Our coding agent was burning $50/month in GitHub API tokens. Here's the cache that fixed it.
Our coding agent was burning through GitHub API tokens faster than a junior dev copy-pasting Stack Overflow. Rate limits every few hours. $50/month in API overages. The culprit? It was treating every file operation like a fresh exploration.
Here's what was happening: Agent starts a task, immediately calls GET /repos/owner/repo/contents/ to "understand the codebase structure." Then GET /repos/owner/repo/contents/src to "explore the source directory." Then individual file requests. Every. Single. Session.
For a 200-file repository, that's 50+ API calls before it writes a single line of code.
The fix was embarrassingly simple: we gave it a filesystem cache that survives sessions.
mkdir -p ~/.agent_cache/repos cd ~/.agent_cache/repos git clone [your-repo] --depth 1 # In your agent config: export AGENT_REPO_CACHE="$HOME/.agent_cache/repos/[repo-name]" export GITHUB_CACHE_TTL="3600" # 1 hour
Now when the agent needs to understand project structure, it reads from the local clone first. Only hits the API for recent changes or when the cache expires.
The results were immediate:
- API calls dropped 85% — from 50+ per session to 3-8
- Session startup time went from 2 minutes to 15 seconds
- Monthly GitHub API costs dropped from $50 to $8
But the real win was behavioral. The agent stopped treating every session like its first day on the job. It remembered where tests live, how the build system works, what the main entry points are.
Pro tip: Set up a cron job to refresh the cache daily during off-hours. Your agent gets fresh code context without burning API tokens during active sessions.
The cache strategy works for any API your agent hits repeatedly. We use the same pattern for npm registry lookups, documentation sites, and dependency graphs. The agent gets the speed of local access with the freshness of periodic syncing.
One caveat: if you're working on a fast-moving codebase with multiple contributors, tune your cache TTL down to 15-30 minutes. Better to take a few extra API hits than have your agent working from stale context.
The broader lesson: agents are expensive because they're wasteful, not because they're intelligent. Most optimization happens at the infrastructure level, not the prompt level.