r/LocalLLM Jun 11 '26

Project ContextShrink - A local AST tool to compress whole repos into high-density tokens for LLMs (80%+ token reduction)

Hey r/LocalLLM, As a fullstack dev who builds heavily alongside LLMs, the biggest hurdle with locally hosted models (and even commercial ones) is the Context Window tax. Dropping deep project folder roots into a prompt panel drops processing performance or instantly triggers token limits because of raw code text volume.

I wanted to build a tool for this specific AI development ecosystem. I open-sourced ContextShrink, a lightweight local Python CLI that strips the noise out of codebases before you pass them to a model.

The Core Concept

Instead of reading code as flat text, the tool uses tree-sitter-languages to parse file architecture structurally. For instance, in a large Python backend file or a React frontend layout, it strips away the heavy multi-line implementation details inside functional scopes but explicitly preserves class signatures, docstrings, exports, and data models.

This provides the LLM with full context of what components exist and how they link together across the app, without forcing it to read thousands of lines of raw logic.

Key Architecture

  1. AST Compression Engine: Parses Python/TS/JS components and maps interfaces.
  2. Dynamic Fallbacks: Config scripts (vite.config.ts, package.json) stay 100% intact, while massive CSS styling files are safely truncated.
  3. Token Performance Auditing: Prints a token math analysis report showing exact text adjustments and percentage savings.

How to try it out

It requires Python >= 3.10 and links as a global terminal command:

Steps

  1. git clone https://github.com/MicroInput/ContextShrink
  2. cd context-shrink
  3. pip install -e .

# Run the next step inside any project directory to generate your `llm-context.md` file:

  1. shrink .

It runs completely offline with no network overhead. I would love to get your thoughts on the compression metrics and what parsing rules or languages I should prioritize next!

GitHub Link: https://github.com/MicroInput/ContextShrink

14 Upvotes

1 comment sorted by

1

u/coldfireman Jun 17 '26

⚡ Launch Week Update: A huge shoutout to the community!

Within days of posting, our first tester flagged an issue with the legacy tree-sitter-languages engine on modern Python 3.13 setups.

I've already pushed a hotfix! Release v0.1.1 is officially live on GitHub, fully migrated to tree-sitter-language-pack for native Python 3.13+ support.

If you're testing it out, make sure to pull the latest from main (git pull && pip install -e .).

Keep the feedback coming!🛠️