
Smart AST driven AI context optimizer. Cuts 50%-85% tokens before feeding LLMs. Built-in MCP server.
Smart AST driven AI context optimizer. Cuts 50%-85% tokens before feeding LLMs. Built-in MCP server.
·
Stop feeding your AI entire codebases. Prune them.
Smart AST-driven context optimizer for LLMs. Cuts 50%–85% of tokens while preserving 100% of architectural interfaces and type contracts.
npx contextprune --task "fix stripe webhook handler"
Tools like Repomix or Gitingest revolutionized feeding code into Claude, ChatGPT, and Cursor. But they have a massive flaw: they dump everything.
When you pack a 60-file repository into a single prompt:
ContextPruneYour AI doesn't need to see the internal implementation of your database connection pool just to fix a payment webhook. It only needs the type signatures, method contracts, and exported interfaces.
ContextPrune analyzes your task, constructs a symbol dependency graph, and applies AST Skeletonization:
┌────────────────────────────────────────────────────────┐
│ YOUR REPOSITORY │
└──────────────────────────┬─────────────────────────────┘
│
┌─────────────┴─────────────┐
▼ ▼
[Target Files] [Dependency Files]
(100% Full Code) (Interface Skeletons Only)
e.g. stripe-webhook.ts e.g. database.ts, logger.ts
│ │
└─────────────┬─────────────┘
▼
[Clean, High-Density AI Prompt]
✨ 50% – 85% Token ReductionRun directly with npx in any project folder:
# 1. Optimize repo for a specific task and auto-copy prompt to clipboard
npx contextprune --task "fix auth refresh token expiry"
# 2. Fit strictly into an 8k local context window (Ollama/Llama 3)
npx contextprune --task "add rate limiting" --max-tokens 7500
# 3. Focus on a specific file with surrounding dependency contracts
npx contextprune --target src/server.ts --output prompt.xml
# 4. Convert all files into pure type and interface skeletons
npx contextprune --skeleton-all
# 5. Output JSON for IDE plugins and autonomous agent pipelines
npx contextprune --task "fix bug" --json⚡ ContextPrune Optimizing repository for AI prompt...
┌─────────────────────────────────────────────────────────────┐
│ ✂️ ContextPrune Optimization Report (8ms) │
├───────────────────────────────┬─────────────────────────────┤
│ Raw Dump Baseline Tokens │ 104,800 │
│ Pruned Context Tokens │ 18,200 │
│ 🚀 Context Reduction Rate │ 82.6% SAVED │
│ Est. Cost Savings (Sonnet/GPT) │ $0.26 / query │
│ AI Response Speedup Factor │ 3.4x │
├───────────────────────────────┼─────────────────────────────┤
│ Full Implementation Files │ 3 │
│ Interface Skeleton Stubs │ 12 │
│ Omitted (In Tree Map Only) │ 45 │
│ Total Files Analyzed │ 60 │
└───────────────────────────────┴─────────────────────────────┘
✔ Copied to clipboard! Ready to paste into Claude, Cursor, or ChatGPT.When ContextPrune marks a file as secondary or architectural context, it strips inner implementation bodies while preserving 100% of what the AI needs to write correct code:
export class DatabaseClient {
private pool: Pool;
constructor(url: string) {
this.pool = new Pool({ connectionString: url, max: 20, idleTimeoutMillis: 30000 });
this.pool.on('error', (err) => console.error('Unexpected pool error', err));
}
async query<T>(sql: string, params: unknown[] = []): Promise<T[]> {
const client = await this.pool.connect();
try {
const res = await client.query(sql, params);
return res.rows;
} finally {
client.release();
}
}
}ContextPrune (Skeleton Stub — 32 tokens, 82% saved!):export class DatabaseClient {
constructor(url: string) {
/* ... omitted 4 lines of implementation ... */
}
async query<T>(sql: string, params: unknown[] = []): Promise<T[]> {
/* ... omitted 7 lines of implementation ... */
}
}The LLM knows the exact methods, argument types, and return signatures, without burning tokens on your connection pool logic!
node_modules.--max-tokens 8000 to guarantee your prompt never overflows local Ollama or small context windows.import / require dependencies are automatically boosted to contract skeletons.TokenBucket, payment_intent) accurately.pbcopy), Linux (xclip/wl-copy), and Windows (clip).<contextprune_repository> XML schema (Anthropic standard) and clean GitHub Markdown..gitignore and default developer ignore rules (node_modules, lockfiles, dist, logs, binaries)..ts, .tsx, .js, .jsx, .mjs).py) — classes, dataclasses, async defs, docstrings.go) — structs, interfaces, func signatures.rs) — structs, traits, enums, impl blocks| Flag | Short | Description | Default |
|---|---|---|---|
--task <string> | -t | Natural language description of your task | "" |
--target <path> | Path to file(s) that must have 100% full content | [] | |
--max-tokens <num> | -b | Hard token budget limit (auto-trims lower-priority files) | null |
--format <type> | -f | Output format: xml (Claude) or markdown | xml |
--output <file> | -o | Save output prompt to file | stdout |
--skeleton-all | Skeletonize all files into interface contracts | false | |
--json | Output JSON stats (for agent & IDE integration) | false | |
--no-copy | Disable auto-copying to system clipboard | false | |
--help | -h | Show CLI help screen |
Use ContextPrune inside your own agent, VS Code extension, or CI pipeline:
import { pruneRepository } from 'contextprune';
const result = await pruneRepository('./my-project', {
task: 'fix stripe webhook',
format: 'xml',
maxTokens: 8000,
copy: true
});
console.log(`Saved ${result.savings.percentSaved}% tokens!`);
console.log(result.output);Contributions, issues, and feature requests are welcome! Check out CONTRIBUTING.md to get started.
MIT © Mani Raja
Paste this prompt into your agent. It reads this page and does the setup for you.
Read https://aiagentslisting.com/mcp/contextprune to learn what the "ContextPrune" MCP server does and how to install it. Add it to my coding agent's MCP configuration as documented on that page, then confirm the server connects and list the tools it exposes.Agents can also browse this directory over MCP at https://aiagentslisting.com/api/mcp
npx contextprune --task "fix stripe webhook handler"
npx contextprune --task "fix auth refresh token expiry"
npx contextprune --task "add rate limiting" --max-tokens 7500
npx contextprune --target src/server.ts --output prompt.xml
npx contextprune --skeleton-all
npx contextprune --task "fix bug" --jsonThis server runs locally, so we can't read its tool list over the web yet.
We could not run this server: its npm package has not answered in our offline sandbox, which usually means it needs an API key or other configuration to start. The four checks that need a live server are left out, and the grade tops out at B until we can read its tools.
Maintain this server? Claiming proves you own the listing and earns the last 4 points.
Claim this listingPaste this line near the top of your repository's README. The badge always renders the current score.
[](https://aiagentslisting.com/mcp/contextprune)Nothing comparable is listed yet.
No tagged releases on record.
Connect to the AI Agents Listing MCP server at https://aiagentslisting.com/api/mcp using the HTTP transport and complete the sign-in when it asks. Then call the submit_review tool for the listing "contextprune" with a rating from 1 to 5 and a short note on what worked and what did not.No reviews yet
Be the first to share your experience with this tool.
One email a week. New agents, MCP servers and skills, and what is actually getting traction.