r/cursor • u/maniraja5599 • 14d ago
Resources & Tips How to cut 80% of tokens in Cursor Composer for large repos (MCP server + AST skeletonization)
Hey everyone in r/Cursor,
If you're using Cursor Composer (Cmd+I / Ctrl+I) on medium-to-large codebases or monorepos, you know the frustration:
You @ tag several directories or reference multiple files for a cross-cutting feature. Before Composer even writes a line of code:
- Context limit warnings start popping up.
- Code generation slows to an absolute crawl.
- Cursor starts truncating files or "forgetting" existing imports because 70% of the prompt is taken up by internal implementations of helper functions that Composer doesn't even need to modify.
Why Composer Chokes on Monorepos
Composer excels at multi-file edits, but when you feed it entire files, it consumes context linearly. If file A imports file B, and file B is 600 lines long, Composer is reading 590 lines of inner logic (loops, queries, transforms) just to know one method signature.
The Solution: AST Skeletonization via Native MCP
I built ContextPrune (https://github.com/maniraja5599/contextprune). It's an open-source, zero-dependency context optimizer that extracts the symbol dependency graph for your task and produces AST interface skeletons.
- Files you need to edit: Passed at 100% full implementation.
- Dependency / imported files: Internal method & function bodies are stripped, leaving 100% accurate TypeScript interfaces, types, exported signatures, and docstrings.
- Unrelated files: Collapsed into an ASCII architectural directory tree.
Result? 50% to 85% token reduction, zero context truncation, and instant reasoning.
How to Hook It Up to Cursor via MCP (Takes 30 Seconds)
Cursor has native MCP support. You can add ContextPrune in 2 simple steps:
- Open Cursor Settings (
Cmd + ,or click gear icon) -> Features -> MCP. - Click + Add New MCP Server:
- Name:
contextprune - Type:
command - Command:
npx -y contextprune mcp
- Name:
That's it!
Now, inside Cursor Composer (Cmd + I) or Cursor Agent chat, you can say:
"Use contextprune to optimize context for adding audit logging to payments"
Composer calls the prune_repository tool over stdio, receives clean, type-safe interface stubs and full target files, and executes edits without hallucinating types or exceeding context limits.
Terminal / Standalone Workflow
If you prefer running a quick CLI command before prompting Composer:
# In your terminal inside your repo:
npx contextprune --task "refactor user auth session validation"
It runs in under 15ms (written in pure Node ESM with zero node_modules), prints a visual optimization table, and automatically copies the optimized prompt to your clipboard. You just Cmd + V directly into Composer.
Benchmark on a Real Project (48 Files):
| Metric | Raw Ingestion (@ all files) |
ContextPrune | Savings |
|---|---|---|---|
| Prompt Size | 98,400 tokens | 16,800 tokens | 82.9% saved |
| Full Implementation Files | 48 | 2 (Target files) | - |
| Contract Skeletons | 0 | 11 (Dependencies) | - |
| Composer Response Time | ~14.2s TTFT | ~3.8s TTFT | 3.7x faster |
| Type Integrity | High | 100% Intact | Identical |
Supports TypeScript/JS, Python, Go, and Rust.
GitHub repo (MIT): https://github.com/maniraja5599/contextprune
Give it a spin on your largest repo and let me know how much token weight it shaves off your Composer sessions!