Our coding agent burned $347 re-learning the same codebase every session
I watched our coding agent burn through $347 in OpenAI credits last month. Not from complex reasoning or massive context windows — from asking Claude to explain the same React component 847 times.
The culprit? Every time it hit an error, it would re-read the entire file, re-analyze the component structure, and re-explain what each prop does. Same file. Same explanation. Different session.
Here's the thing about coding agents: they have perfect recall within a conversation but complete amnesia between sessions. Your agent will spend 20 minutes figuring out your auth flow on Monday, then spend another 20 minutes figuring out the exact same auth flow on Tuesday.
Warning: This gets expensive fast. Complex codebases can burn 50-100 tokens per file just for "understanding" — multiply that by every session and every file touch.
The fix isn't smarter prompts or bigger context windows. It's persistent code understanding.
I built a simple cache that saves the agent's analysis of each file:
// .agent-cache/components/UserProfile.json
{
"file_path": "src/components/UserProfile.jsx",
"last_modified": "2024-03-15T10:30:00Z",
"analysis": {
"purpose": "User profile display with edit capabilities",
"key_props": ["userId", "onSave", "editable"],
"dependencies": ["useAuth", "UserAPI"],
"common_issues": ["Missing userId crashes component"]
},
"file_hash": "abc123..."
}Now when the agent encounters a file, it checks three things:
- Does a cache entry exist?
- Has the file changed since last analysis?
- Is the cached analysis still relevant to the current task?
If all three pass, it skips the expensive "understand this code" step and jumps straight to the actual work.
The results were immediate:
- Token usage down 60% — no more re-analyzing the same files
- Session startup 3x faster — agent gets context immediately
- Better consistency — same understanding across sessions
The cache expires when files change (using file hashes) and gets invalidated if the analysis seems stale. But for stable codebases, this saves thousands of tokens per day.
The pattern works for any repetitive analysis: API schemas, database models, configuration files. If your agent keeps "learning" the same thing, cache the learning.
Your coding agent shouldn't rediscover your codebase every morning. Cache the understanding, focus the intelligence on actual problems.