A zero-overhead AST-based code skeletonizer and token compressor for LLMs and AI coding agents.
Passing whole repositories or massive source files into LLM prompts quickly causes:
- Context Window Exhaustion: Thousands of tokens burned on implementation trivia (loops, math, internal boilerplate).
- Attention Degradation (Lost-in-the-middle): Agents struggle to identify relevant interfaces and function signatures buried inside dense files.
context-trimmer parses your codebase into an AST and strips function and method bodies, replacing them with concise placeholders while strictly preserving:
importstatements and dependenciestype,interface, andenumdefinitions- Function, method, and constructor signatures with parameter and return types
- JSDoc comments and Python docstrings
- Class hierarchy and visibility modifiers (
public,private,readonly)
On typical production TypeScript and Python codebases:
- Token reduction: 55% to 78%
- Speed: Over 10,000 LOC parsed and trimmed in under 120ms (zero native C/node-gyp compilation).
Direct execution with npx:
# Print skeleton of a file or directory
npx context-trimmer ./src
# View token reduction stats
npx context-trimmer ./src --stats
# Export trimmed context to a single file for feeding to LLMs
npx context-trimmer ./src --out context.txtexport function processTransaction(id: string, amount: number): Receipt {
const tax = amount * 0.21;
const total = amount + tax;
const receipt = generateDatabaseRecord(id, total);
notifyAccounting(receipt);
return receipt;
}export function processTransaction(id: string, amount: number): Receipt { /* ... */ }MIT © luckdevx