ByteCosts
agent-memory-claude-md-vs-vector.mdx

AI Coding Agents

Coding Agent Memory: CLAUDE.md vs. Memory Tools vs. Vector Indexes

A rules file such as CLAUDE.md provides startup context when selected by the client, while a vector database retrieves relevant chunks through a search. A tool-mediated store lets the agent retrieve notes, with token costs for tool definitions, lookup requests, and retrieved text carried into the conversation. Start with rules for standing guidance, try memory for recurring rediscovery, and evaluate an index when repeated search is expensive enough to justify keeping it current.

How the three mechanisms compare

Markdown rules filesTool-mediated memoryVector / RAG index
What loadsSelected startup instructions enter the prompt prefix. With auto memory enabled, Claude Code loads the first 200 lines or 25KB of MEMORY.md, whichever comes firstA tool definition and the notes returned by lookupsRetrieved chunks for the query
Token costInput tokens on requests that carry the file, with cache-read rates on eligible hitsTool definitions, lookup requests, retrieved text, and later requests that retain itEmbedding costs and input tokens for retrieved chunks
Staleness riskStanding guidance needs review when repo conventions changeNotes can outlive the code they describeResults can lag code changes until the next update
Setup and maintenanceWrite Markdown and scope instructions by path where supportedImplement a client-side handler or adopt a memory storeMaintain an embedding pipeline, a vector store, and an update process
Where data livesUsually in the repo. Project-level external imports require approval in Claude CodeThe application chooses where notes liveThe index stores a secondary representation of the codebase
Cache interactionA matching warm prefix can be reused at cache-read ratesReturned text can become part of a cached prefix on later requestsA query’s chunks add input and may be carried forward

How rules files enter the prompt

Rules add input tokens to requests that carry them. Cached portions can be billed at the cache-read rate while the prefix stays warm. Claude Code’s memory documentation advises targeting under 200 lines per CLAUDE.md file because longer files consume more context and can reduce adherence. Keep instructions specific enough to test, such as which command to run for a package or where to put a migration.

Claude Code supports @path imports up to four hops deep. Imported content loads with its parent file, so splitting a long file into imports can help readers navigate it while leaving the same text in the prompt. Use path-scoped rules to reduce what loads for unrelated work. A shared instruction for all tests goes in the root file. A convention that applies to one package can load only when Claude works with matching files.

AGENTS.md is a shared Markdown format with no required structure. Its format guidance gives precedence to the closest file to the edited file. Check how each client loads instructions before relying on that rule across tools. As of November 30, 2026, Claude Code v2.1.277 and later can read AGENTS.md directly in supported sessions. By default, AGENTS.md is the fallback when the working directory and its ancestors contain no CLAUDE.md, .claude/CLAUDE.md, or CLAUDE.local.md. Claude Code loads eligible ancestor files at startup and can read eligible nested files on demand. Use Project instructions in /config to choose the fallback, both formats, CLAUDE.md alone, or managed-only for startup.

An external import from a project CLAUDE.md can trigger an approval dialog. Claude Code loads an external import in a directly loaded AGENTS.md only after prior project approval. Give approval through the project’s external-import flow before relying on that import.

With auto memory enabled, Claude Code loads the first 200 lines or 25KB of MEMORY.md, whichever comes first, at startup. Claude reads separate topic files on demand. Subagents can have their own auto memory. Keep recurring facts in topic files and use the startup index to tell the agent where to look.

Tool-mediated memory costs

Anthropic’s memory tool ({"type": "memory_20250818", "name": "memory"}) runs through a client-side handler. When enabled, Claude checks its memory directory before starting the task. Your application handles the file operations, decides where the store lives, and returns results. The documented commands are view, create, str_replace, insert, delete, and rename. The handler must reject paths outside /memories. The tool description specifies a 16,000-character text view limit. If implementing the documented view behavior, apply that limit in the handler and support view_range for follow-up reads.

Tool-mediated memory adds tool definition and lookup costs. Retrieved text first enters as fresh input and may be billed again while it remains in later requests, at cache-read rates when eligible. A store is a good candidate when only some tasks need a particular note. If most tasks need the same fact, count the lookup request and the carried text before moving that fact out of the rules file.

Treat project instructions as standing guidance. Enforce hard constraints with permissions or a PreToolUse hook. For example, a project instruction can tell the agent which directory contains fixtures. If an operation must be blocked in a directory, enforce that restriction at tool execution.

Maintaining a vector index requires an embedding pipeline, storage, and an update process. Retrieval can help when the query describes a concept without using the exact names in the repository. For queries with known symbols or filenames, test how far direct search gets before adding an index.

On the Latent Space podcast in May 2025, Claude Code lead engineer Boris Cherny said early versions tried RAG with off-the-shelf embeddings before settling on agentic search using tools such as glob and grep. He cited indexing complexity, drift as code changes, and the risks of storing an index. He also described token and latency costs for direct exploration. His account describes Claude Code’s design choice and draws mostly on internal impressions.

Cline gives its own reasons for avoiding a vector index. Its engineering post argues that chunks can split a function from its callers or relevant context, an index can fall behind the checkout, and embeddings create a secondary representation of the code that needs protection. For a local comparison, use tasks where the agent must identify the right definition and inspect its callers. Score the resulting explanation against the code in the same checkout.

The Codebase-Memory paper (arXiv, March 2026) builds a persistent tree-sitter knowledge graph over a repo. Across 31 repositories, the authors report 83% answer quality for their system versus 92% for a file-exploration agent, with about one-tenth the tokens and 2.1 times fewer tool calls. For graph-native queries such as hub detection and caller ranking, it matched or exceeded the explorer on 19 of 31 languages. The authors’ result gives a reason to test a structural index on relationship queries and to check answer quality on general questions before using it as the default.

Design the retrieval comparison around the questions you actually ask. Include an exact lookup such as where an exported function is defined, a semantic query such as where failed jobs are rescheduled, and a relationship query such as which callers are affected by a change. Write down the evidence an accepted answer needs. Use the same revision and budget for each run. A plausible explanation that cites the old implementation after a rename should fail, even if the index found the right concept.

Also measure how the store behaves after a change. Make a representative edit in a test checkout and repeat the affected query before and after the index refresh. Record how long stale results remain visible and whether the agent verifies retrieved passages against the checkout. A structural or vector index earns its maintenance cost if it helps answer enough of your recurring questions within the quality and freshness limits you set. Keep direct search available for cases where the current file is the authoritative evidence.

What a rules file costs over a long session

Assume a 3,000-token CLAUDE.md in the stable prefix of 200 API requests. Multiply the file’s token count by the number of requests at each rate, then divide by one million. Claude Sonnet 5.5 costs $2 per million fresh input tokens, $2.50 per million five-minute cache write tokens, and $0.10 per million cache-read tokens as of November 30, 2026. See the pricing index for current rates.

ScenarioMathEstimated cost
No caching, 200 requests200 x 3,000 x $2/1M~$1.20
Warm cache (one write, 199 reads)3,000 x $2.50/1M + 597,000 x $0.10/1M~$0.07
Every request misses and rewrites the prefix200 x 3,000 x $2.50/1M~$1.50

A warm cache reduces the file’s estimated input cost to the cache-read rate after the first write. The last row assumes a new five-minute cache write on every request. That costs more than sending the file without caching. Count API requests because a single user turn can include a tool call and another request to continue with its result. See what is prompt caching and manage context in long coding agent sessions.

For a tool store serving the same knowledge, measure tool-definition tokens, extra requests per lookup, and retrieved tokens carried into later requests. Compare those costs with the warm and cold rules-file estimates at your actual lookup frequency. Keep a separate tally of tasks that needed the note but failed to retrieve it. A lower bill can come from doing less retrieval, so check whether the work still meets the acceptance criteria.

Make the comparison at the level of a fact the agent needs. A package’s required test command is standing guidance and belongs in an instruction file that loads for that package. A troubleshooting note about a transient failure is a candidate for a topic file because many tasks will never need it. An inventory of call sites is a query against the current code, so it should be verified against the current checkout. Put a fact in the store whose update process can keep it accurate. If a note starts duplicating a rule or a current symbol, refer back to the file that owns the fact so the next change has one place to update.

Choosing by repo and team

  • Solo developer with a small or medium repo. Start with a CLAUDE.md under 200 lines and add path-scoped rules as needed.
  • Team sharing instructions across tools. Use a root AGENTS.md for shared guidance. Check how each client loads nested files and resolves conflicts before relying on per-package overrides.
  • Recurring rediscovery across sessions. Try Claude Code auto memory first if its startup index and on-demand topic files fit your workflow. Use a client-handled store when your application needs to control where notes live and how the agent retrieves them.
  • Large or fast-moving codebase. Use direct file search as a baseline. Test a vector index for semantic retrieval or a structural index for questions such as caller ranking. Compare accepted answers, latency, and cost. Check when the index refreshes and what data it stores.

What to do next

Audit your rules file first. Keep guidance that applies across the repo and move directory-specific instructions into path-scoped rules. During regular work, keep a short list of facts that agents have to rediscover, such as the fixture naming convention or which package owns an API. For each entry, record how the agent found it and whether the fact stayed valid after a code change. That gives you real queries to test against direct search or a store.

Try any change in a fresh session. Ask the agent to work on a file that should trigger the scoped instruction and then a file outside that scope. Check which instructions appeared and whether the agent followed them. For a memory store, run a task that needs a saved note and confirm the evidence includes the retrieved note and the current code.

Check access from a second workspace if multiple users or projects share the same store. Verify that the agent can retrieve the notes intended for that workspace and that its search is scoped to those notes. If you discover an outdated note, correct it at the source and confirm the next relevant lookup reflects the change.

Compare claude-mem and memU if the same knowledge keeps getting rediscovered across sessions. If the missing information is the current task state, preserve it in a structured compaction checkpoint and test whether a fresh session can resume the work.

Sources

How this note was produced

Drafted with AI assistance from committed ByteCosts pricing snapshots and deterministic cost formulas. Figures are grounded in the linked sources (last updated 2026-11-30). Read our editorial & automation policy, inspect the methodology, or report a discrepancy.

Coding Agent Memory: CLAUDE.md vs. Memory Tools vs. Vector Indexes. ByteCosts. Updated 2026-11-30. https://bytecosts.com/blog/agent-memory-claude-md-vs-vector/

Sources