TL;DR — Key Takeaways
- RAG: great for large codebases needing semantic search; needs infrastructure
- Context files: zero infrastructure, portable, sufficient for most projects
- Choose RAG when: 1000+ files, semantic search needed, dedicated infra OK
- For most devs: CLAUDE.md + explicit file paths beats RAG
Two Approaches to Agent Knowledge
When an AI coding agent needs to know something about your project, how does it get that information? Two approaches have emerged:
- Context files (CLAUDE.md, AGENTS.md) — you write down the key decisions and conventions in Markdown; the agent reads the whole file at session start
- RAG (Retrieval Augmented Generation) — a vector database stores your codebase and documentation; the agent queries it to retrieve semantically relevant snippets
Both solve the agent knowledge problem. They differ fundamentally in complexity, scalability, and what kinds of knowledge they handle best.
What Is RAG for AI Coding Agents?
RAG (Retrieval Augmented Generation) is a technique where the AI agent queries a vector database before generating a response, retrieving the most semantically relevant pieces of information to augment its context.
In a RAG setup for coding:
- Your codebase, documentation, and decision logs are indexed as vector embeddings
- When the agent needs to answer a question or complete a task, it queries the vector store with a semantic search
- The most relevant code snippets, docs, or decisions are retrieved
- These are injected into the agent's context window alongside the task instruction
The key advantage: retrieval is semantic and selective. Instead of loading your entire codebase (which would overflow the context window), RAG loads only what's relevant to the current query.
A typical RAG stack for coding: LlamaIndex or LangChain for orchestration, Qdrant or Pinecone for vector storage, OpenAI Embeddings or Sentence Transformers for embedding generation.
What Are Context Files?
Context files are Markdown documents (CLAUDE.md, AGENTS.md, .cursorrules) that you write and maintain to give AI agents structured project context. The entire file is loaded into the context window at session start.
The key advantage: simplicity and portability. No vector database. No embedding pipeline. No API calls for retrieval. A text file in your repository.
Context files excel at the specific type of knowledge AI agents need most: structured architectural decisions with the reasoning behind them.
## Architecture Decisions
- Auth: Auth0 (not Passport) — compliance requirements, managed sessions
- Database: Prisma (not Drizzle) — type-safe client, migration tooling
- Error handling: return { data, error } — do not throw from handlers
This isn't the kind of knowledge that benefits from semantic retrieval — it's always relevant and always needs to be present. Selective retrieval is an overhead cost, not a benefit.
Direct Comparison
| RAG | Context files | |
|---|---|---|
| Setup complexity | High (vector DB, embedding pipeline) | None (edit a text file) |
| Infrastructure | Vector database + embedding API | None |
| Context loading | Selective (semantic retrieval) | Full file (everything always present) |
| Scales to | Millions of tokens | ~600 words effectively |
| Best knowledge type | Large codebases, documentation | Architectural decisions, conventions |
| Version controlled | Usually not | Yes (committed to repo) |
| Portable across tools | No (requires integration per tool) | Yes |
| Maintenance | Index updates needed | Manual file edits |
When Context Files Win
For the vast majority of AI coding workflows, context files are superior. Here's why:
Most project context is always relevant. Your auth strategy, error handling pattern, and naming conventions should be present on every task. Selective retrieval of "relevant" decisions isn't an advantage — you want all of them present.
Decisions need reasoning, not just code. RAG indexes code and text. It can retrieve the fact that you use Auth0, but not the reasoning ("compliance requirements, managed sessions, we rejected Passport for these reasons"). Context files capture the reasoning explicitly.
Zero infrastructure overhead. A CLAUDE.md file requires no setup, no maintenance of indexes, no API calls at session start. A RAG system requires a vector database, an embedding model, an indexing pipeline, and ongoing index maintenance.
Portability. CLAUDE.md and AGENTS.md work with Claude Code, Cursor, Cline, and Windsurf out of the box. A RAG system requires custom integration per tool.
For a typical project with 50 architectural decisions and a few dozen conventions: the entire context fits in a well-written CLAUDE.md under 600 words. No retrieval infrastructure needed.
When RAG Wins
RAG's advantages emerge at scale and for specific use cases:
Very large codebases. A monorepo with 2,000 files and 10 years of history cannot be meaningfully summarized in a 600-word CLAUDE.md. RAG can index all of it and retrieve relevant code on demand.
Documentation-heavy development. If your project has extensive API documentation, architectural documents, and decision logs that you want the AI to consult, RAG can index all of it for semantic retrieval.
Question-answering over code history. "What was the previous implementation of the billing system?" is a question RAG can answer by retrieving relevant git history or documentation. Context files don't capture history.
Building AI products with user-specific context. If you're building a product where each user needs personalized AI memory, RAG provides the scalable infrastructure that context files can't.
Cross-project knowledge sharing. An agency with 50 client projects can use RAG to index all of them and retrieve relevant solutions from past projects when working on a new one.
The Hybrid Approach
The most effective approach for large codebases uses both:
Context files (CLAUDE.md/AGENTS.md) for:
- Architectural decisions and reasoning
- Conventions and patterns
- What to do and what not to do
- Always-present constraints
RAG for:
- Large codebase search (beyond what context files can represent)
- Historical documentation and past decisions
- Code examples from across the codebase
At session start, the agent reads CLAUDE.md (structured, always-relevant context) plus a RAG query based on the current task (specific code or documentation relevant to this task).
Practical RAG Setup for Coding Agents
For teams who need RAG, here's a minimal setup with LlamaIndex:
pip install llama-index llama-index-vector-stores-qdrant
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader
from llama_index.vector_stores.qdrant import QdrantVectorStore
import qdrant_client
# Index your codebase
documents = SimpleDirectoryReader("./src").load_data()
client = qdrant_client.QdrantClient(host="localhost", port=6333)
vector_store = QdrantVectorStore(client=client, collection_name="codebase")
index = VectorStoreIndex.from_documents(documents, vector_store=vector_store)
# Query
query_engine = index.as_query_engine()
response = query_engine.query("How does authentication work in this codebase?")
print(response)
This indexes your source files and enables semantic queries. You'd integrate this with your AI agent's context-building step.
Key Takeaways
- RAG = vector database for semantic retrieval of relevant context; best at scale
- Context files = Markdown documents with structured decisions; best for typical project workflows
- For most developers and teams: context files (CLAUDE.md/AGENTS.md) are the right choice — zero infrastructure, portable, sufficient for project-scale context
- RAG wins when: 1,000+ file codebases, extensive documentation, historical search needs, or building AI products with personalized memory
- Hybrid approach: context files for always-relevant structured decisions + RAG for large codebase search
- The infrastructure cost of RAG is significant — only introduce it when the benefits clearly outweigh the complexity
Related: AI Agent Memory: Short-Term vs Long-Term Explained · Mem0 vs File-Based Context · How to Persist Architectural Decisions Across AI Sessions