cached-context
File cache with diff tracking for AI coding agents. Drop-in MCP server that cuts token usage by 26%.
Built with Rust for maximum reliability and performance. Uses rusqlite (bundled SQLite) and rmcp for production-grade stability.
What is cached-context?
cached-context is an MCP server that caches file reads for AI coding agents. Instead of re-reading entire files, cachebro returns diffs or "unchanged" confirmations, saving ~26% of token usage.
How it works
First read: agent reads src/auth.rs → cached-context caches content + hash → returns full file
Second read: agent reads src/auth.rs → hash unchanged → returns "[unchanged, 245 lines, 1,837 tokens saved]"
After edit: agent reads src/auth.ts → hash changed → returns unified diff (only changed lines)
Installation
Option 1: Homebrew (macOS/Linux)
Option 2: Cargo (Rust toolchain required)
Option 3: Pre-built Binary
Download the latest release from GitHub Releases.
# macOS (Apple Silicon) - code signed
|
# macOS (Intel) - code signed
|
# Linux
macOS Security Note
If macOS blocks the binary after installation, you may need to remove the quarantine attribute:
Or allow it in System Settings > Privacy & Security.
Option 4: Build from Source
Quick Start
1. Verify Installation
2. Configure MCP
Claude Code
Add to your .claude.json:
Cursor
Add to .cursor/mcp.json:
OpenCode
Add to .opencode/mcp.json:
3. Restart Your Agent
After configuring, restart Claude Code, Cursor, or OpenCode. The agent will automatically discover and use cachebro's read_file tool instead of the built-in Read tool.
Usage
Manual Testing
# Check cache status
# Clear the cache
# Start MCP server (for manual testing)
Available Tools
When used as an MCP server, cached-context exposes:
| Tool | Description |
|---|---|
read_file |
Read a file with caching. Returns full content, "unchanged", or diff. |
read_files |
Batch read multiple files with caching. |
cache_status |
Show cache statistics. |
cache_clear |
Clear all cached data. |
Configuration
Environment Variables
| Variable | Default | Description |
|---|---|---|
CACHED_CONTEXT_DIR |
.cached-context |
Directory for cache database |
RUST_LOG |
info |
Logging level (error, warn, info, debug, trace) |
Cache Location
By default, cached-context stores its database at ./.cached-context/cache.db (relative to working directory). You can change this:
CACHED_CONTEXT_DIR=/path/to/cache
Architecture
- Rust implementation for reliability and performance
- SQLite backend via rusqlite (bundled SQLite)
- MCP protocol via rmcp
- Diff algorithm using similar
Performance
- File read: < 10ms for typical files
- Diff computation: < 5ms for typical changes
- MCP round-trip: < 50ms
Testing
# Run all tests
# Run tests quietly
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
License
MIT License - see LICENSE file for details.
Acknowledgments
- Original TypeScript implementation by glommer/cachebro
- Built with terraphim infrastructure
Support
For issues and questions:
- GitHub Issues: https://github.com/terraphim/cached-context/issues
- Discussions: https://github.com/terraphim/cached-context/discussions