Skip to content

About

High-performance AST code skeletonizer for LLMs & coding agents — strips bodies while preserving signatures & docstrings

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

context-trimmer

License: MIT

A zero-overhead AST-based code skeletonizer and token compressor for LLMs and AI coding agents.


The Problem

Passing whole repositories or massive source files into LLM prompts quickly causes:

  1. Context Window Exhaustion: Thousands of tokens burned on implementation trivia (loops, math, internal boilerplate).
  2. Attention Degradation (Lost-in-the-middle): Agents struggle to identify relevant interfaces and function signatures buried inside dense files.

The Solution

context-trimmer parses your codebase into an AST and strips function and method bodies, replacing them with concise placeholders while strictly preserving:

  • import statements and dependencies
  • type, interface, and enum definitions
  • Function, method, and constructor signatures with parameter and return types
  • JSDoc comments and Python docstrings
  • Class hierarchy and visibility modifiers (public, private, readonly)

Quick Benchmarks

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).

Installation & Usage

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.txt

Example

Before:

export 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;
}

After:

export function processTransaction(id: string, amount: number): Receipt { /* ... */ }

License

MIT © luckdevx

About

High-performance AST code skeletonizer for LLMs & coding agents — strips bodies while preserving signatures & docstrings

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages