Coding agents hit a wall at 50,000 lines of code
Your coding agent hits a wall at 50,000 lines of code. Not because it's not smart enough — because it's drowning in context.
I watched our agent spend 20 minutes re-reading the same React components every session, burning through tokens like a slot machine. The context window fills up with file after file, and suddenly your agent is making decisions based on incomplete information from three directories ago.
The solution isn't a bigger context window. It's tiered memory that matches how developers actually work.
Layer 1: File Embeddings (The Search Layer)
Skip the vector database complexity. Use simple file embeddings with semantic search:
// When agent needs to find relevant files
const relevantFiles = await searchCodebase({
query: "authentication middleware",
maxFiles: 5,
excludePaths: ["node_modules", "dist"]
});
// Only pull these into context
for (const file of relevantFiles) {
context.addFile(file.path, file.content);
}Layer 2: Session Memory (The Working Set)
Track what the agent has already learned this session. Don't re-read files it just analyzed:
const sessionMemory = {
analyzedFiles: new Set(),
discoveries: [],
activeContext: []
};
// Before reading a file
if (sessionMemory.analyzedFiles.has(filePath)) {
return sessionMemory.getFileSummary(filePath);
}Layer 3: Project Memory (The Knowledge Graph)
Build a lightweight knowledge graph of your codebase. Not every function — just the architecture that matters:
// Store architectural knowledge
const projectMemory = {
"auth-flow": {
entryPoint: "src/middleware/auth.js",
dependencies: ["src/utils/jwt.js", "src/models/User.js"],
lastModified: "2024-01-15",
summary: "JWT-based auth with refresh tokens"
}
};The agent queries this first, then pulls specific files into context only when needed.
The Result: Our agent went from burning 40K tokens per session to 8K tokens, while making better decisions because it actually remembers what it learned about our codebase structure.
Most developers try to solve this with RAG or bigger context windows. But coding agents don't need to see everything — they need to remember what they've already figured out and find what they need when they need it.
The three-tier approach mirrors how senior developers work: they remember the architecture, keep recent discoveries in working memory, and search for specifics when needed.