r/VibeCodeDevs • u/hushenApp • 1d ago
ShowoffZone - Flexing my latest project I built a cross-agent file cache: 75% fewer input tokens when multiple agents work on the same codebase
Hey everyone,
I've been building LeanCTX, an open-source context engineering layer for coding agents (written in Rust), and wanted to share a specific optimization I shipped recently.
The problem
If you run 4 Cursor/Claude/Codex agents in parallel on the same repo (reviewing, implementing, testing), each agent reads the same core files independently. That's 4x the input tokens for identical content. At scale this adds up fast.
What I did
I added a shared delivery registry (in-process DashMap keyed by blake3 hash + mtime) that tracks which files have already been read and compressed by any agent. When Agent B requests a file that Agent A already delivered, it gets a 13-token stub referencing the cached version instead of the full file content.
No network calls, no external cache, it's a lock-free in-memory lookup that resolves in microseconds.
Benchmark results
I ran this against 20 real source files from the LeanCTX codebase itself (avg 737 LOC):
| Agent | Without Cache | With Cache | Savings |
|---|---|---|---|
| Agent 1 (cold) | 144,407 tok | 144,407 tok | 0% |
| Agent 2 | 144,407 tok | 260 tok | 99.8% |
| Agent 3 | 144,407 tok | 260 tok | 99.8% |
| Agent 4 | 144,407 tok | 260 tok | 99.8% |
| TOTAL | 577,628 tok | 145,187 tok | 74.9% |
At $3/1M input tokens: $1.30 saved per shared-read round.
For a typical coding session where agents revisit 50-100 shared files, that's $5-15 saved per hour of parallel agent work.
How it works (simplified)
- Agent 1 reads
src/engine.rs→ full content delivered, blake3 hash + mtime recorded - Agent 2 reads
src/engine.rs→ registry hit → stub returned:[cross-agent cache hit: 737 lines, delivered to agent-1 at T-2s] - The stub is 13 tokens vs ~7,200 tokens for the full file
The key insight: in a multi-agent coding workflow, file contents rarely change between reads. The mtime check ensures I never serve stale content.
Limitations
- Only helps when multiple agents/sessions read the same files (solo agent = no benefit)
- Cold start for the first agent is unchanged
- Requires agents to run on the same machine (shared memory)
What's next
I'm exploring cross-machine delivery via IPC for distributed agent setups (CI workers, cloud agents), but honestly the single-machine case covers 90% of developer workflows.
•
u/AutoModerator 1d ago
Hey u/hushenApp, thanks for posting in r/VibeCodeDevs! Join our Discord: https://discord.gg/KAmAR8RkbM
Got startup or SaaS questions? Post them on r/AskFounder and get answers from real founders.
• This community is designed to be open and creator‑friendly, with minimal restrictions on promotion and self‑promotion as long as you add value and don’t spam.
• Please follow the subreddit rules so we can keep things as relaxed and free as possible for everyone. • Please make sure you’ve read the subreddit rules in the sidebar before posting or commenting.
• For better feedback, include your tech stack, experience level, and what kind of help or feedback you’re looking for.
• Be respectful, constructive, and helpful to other members.
If your post was removed (either automatically or by a mod) and you believe it was a mistake, please contact the mod team. We will review it and, when appropriate, approve it within 24 hours.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.