Skip to main content

Convert Repomix/repominify output into compact AI-friendly codebase summaries using free LLMs.

Project description

savetoken ๐Ÿช™

Transform your Repomix codebase dump into a high-fidelity AI context brief โ€” ~83% fewer tokens than sending the raw zip, ~88% fidelity to the original.

Instead of pasting hundreds of thousands of tokens of source code into an AI, savetoken produces a structured codebrief.md that the AI can reason about just as effectively, at a fraction of the cost.


How it fits in your workflow

Your project
    โ†“
npx repomix                          # pack codebase โ†’ repomix-output.xml
    โ†“
savetoken summarize repomix-output.xml   # analyse โ†’ codebrief.md
    โ†“
Paste codebrief.md into your AI prompt   # 17% of tokens, ~88% fidelity

Install

pip install savetoken

Requires Python 3.10+. Zero runtime dependencies โ€” stdlib only (ast, urllib, json, hashlib, re).


Quick start

# 1. Pack your codebase with Repomix
npx repomix

# 2. Generate context brief (Gemini Flash is free and recommended)
export GEMINI_API_KEY=your_key_here
savetoken summarize repomix-output.xml

# Output: codebrief.md โ€” paste into any AI prompt

Python API

from savetoken import SaveToken

st = SaveToken(provider="gemini", api_key="...")
summary = st.summarize("repomix-output.xml")
st.save(summary, "codebrief.md")

What's in the output

savetoken extracts seven categories of information, each via the most accurate method available:

Section Source Fidelity
Strategic files (schemas, configs, entry points, tests) verbatim 100%
Hot functions (most-called by PageRank) verbatim 100%
File docs (module/class/fn docstrings, signatures, constants) AST ~95%
Execution flows (entry โ†’ service โ†’ repo โ†’ db) call graph trace ~90%
Call graph (cross-file function calls, prod/test split) AST ~90%
Environment contract (all env vars, defaults, required) AST 100%
SQL schema (tables, columns, FKs, indexes) AST ~95%
Critical blocks (HACK/FIXME with ยฑ10 lines context) verbatim 100%

No LLM is called for Python files. Docstrings and signatures are extracted directly from source โ€” zero hallucination, instant, cacheable. LLM calls are only used for: project overview, flow descriptions, and non-Python file summaries.


Providers

Provider Model Free tier Env var
gemini โญ Gemini 2.0 Flash โœ… Generous, 1M ctx GEMINI_API_KEY
groq Llama 3.3 70B โœ… Fast GROQ_API_KEY
mistral Mistral Small Latest โœ… Available MISTRAL_API_KEY
openai gpt-4o-mini Paid OPENAI_API_KEY
deepseek deepseek-chat Very cheap DEEPSEEK_API_KEY

Gemini is recommended โ€” 1M token context handles any codebase size.


CLI reference

savetoken summarize repomix-output.xml
savetoken summarize repomix-output.xml \
  --provider groq \
  --output codebrief.md \
  --format markdown \
  --lang pt \
  --target-ratio 0.50 \
  --flow-depth 5 \
  --force        # ignore cache, regenerate everything
savetoken cache-stats
savetoken clear-cache
Flag Default Description
--provider gemini LLM provider
--output codebrief.md Output path
--format markdown markdown or json
--lang en Language for generated descriptions
--target-ratio 0.50 Max output/input token ratio
--flow-depth 5 Max hops in execution flow traces
--force off Bypass cache
--cache-dir .savetoken_cache Cache directory
--quiet off Suppress per-file progress

Caching

Every file is hashed by content. On re-runs, only changed files are re-processed. The cache lives in .savetoken_cache/ โ€” commit it to share across your team. Cache keys are schema-versioned: any model change automatically invalidates stale entries.

savetoken cache-stats   # entries, size, schema version
savetoken clear-cache

Real-world numbers (datalock โ€” 59 files, 271k tokens)

Raw codebase (zip):  271,252 tokens   100%   fidelity 100%
savetoken output:     47,204 tokens    17%   fidelity  ~88%
Savings:                              83%

Token breakdown:

  • Strategic verbatim (11 files): 26%
  • File Docs / AST (48 files): 44%
  • Call graph (1,139 edges): 25%
  • Flows, env, overhead: 5%

VS Code extension

Located in vscode-extension/. Commands:

  • SaveToken: Summarize Codebase โ€” runs on repomix-output.xml
  • SaveToken: Open Summary
  • SaveToken: Clear Cache

Settings: savetoken.provider, savetoken.apiKey, savetoken.language, savetoken.outputFile, savetoken.autoSummarizeOnRepomix.


Project structure

savetoken/
โ”œโ”€โ”€ savetoken/
โ”‚   โ”œโ”€โ”€ core.py                 Orchestrator โ€” full pipeline
โ”‚   โ”œโ”€โ”€ models.py               All dataclasses (FileSummary, Flow, etc.)
โ”‚   โ”œโ”€โ”€ classifier.py           STRATEGIC / AST / REGULAR / SKIP per file
โ”‚   โ”œโ”€โ”€ budget.py               Token budget allocation (post-classification)
โ”‚   โ”œโ”€โ”€ analyzer.py             AST call graph + inheritance (prod/test split)
โ”‚   โ”œโ”€โ”€ ast_types.py            Function signature extraction via AST
โ”‚   โ”œโ”€โ”€ docstring_extractor.py  Module/class/fn docstrings + constants (NEW)
โ”‚   โ”œโ”€โ”€ ranker.py               PageRank centrality โ†’ hot functions
โ”‚   โ”œโ”€โ”€ flows.py                Execution flow tracer (BFS on call graph)
โ”‚   โ”œโ”€โ”€ env_extractor.py        Environment variable extractor
โ”‚   โ”œโ”€โ”€ schema_sql.py           SQL schema (Django/SQLAlchemy/Alembic/raw SQL)
โ”‚   โ”œโ”€โ”€ critical_context.py     HACK/FIXME blocks with ยฑ10 line context
โ”‚   โ”œโ”€โ”€ deduplicator.py         Remove cross-section redundancy
โ”‚   โ”œโ”€โ”€ output.py               Markdown + JSON renderers
โ”‚   โ”œโ”€โ”€ cache.py                File-based cache with schema versioning
โ”‚   โ”œโ”€โ”€ cli.py                  CLI entry point
โ”‚   โ”œโ”€โ”€ exceptions.py           SaveTokenError hierarchy
โ”‚   โ””โ”€โ”€ providers/
โ”‚       โ”œโ”€โ”€ base.py             Abstract provider + prompts
โ”‚       โ”œโ”€โ”€ gemini.py           Gemini 2.0 Flash
โ”‚       โ”œโ”€โ”€ groq.py             Groq / Llama 3.3 70B
โ”‚       โ”œโ”€โ”€ mistral.py          Mistral Small
โ”‚       โ””โ”€โ”€ openai.py           OpenAI-compatible (OpenAI, DeepSeek, Ollama)
โ”œโ”€โ”€ vscode-extension/           VS Code extension
โ”œโ”€โ”€ tests/                      117 unit + integration tests
โ”œโ”€โ”€ examples/                   Usage examples
โ””โ”€โ”€ pyproject.toml

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

savetoken-0.1.1.tar.gz (48.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

savetoken-0.1.1-py3-none-any.whl (47.5 kB view details)

Uploaded Python 3

File details

Details for the file savetoken-0.1.1.tar.gz.

File metadata

  • Download URL: savetoken-0.1.1.tar.gz
  • Upload date:
  • Size: 48.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for savetoken-0.1.1.tar.gz
Algorithm Hash digest
SHA256 27cafd0c9f0c730e1a0678eaae8c63acdaad1147a38254d21c8a00adc9f41157
MD5 08a05c517405c5197a8d1ac729bb5897
BLAKE2b-256 e4c1573098ff486a468de8012f1ce7d6ae10ccfd3a2fd04692f2c31a3f541d7f

See more details on using hashes here.

File details

Details for the file savetoken-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: savetoken-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 47.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for savetoken-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fce2c332d6ad482b3dc38ee3ef04f1150a7800db2c93e220429dc5b68a49bb2c
MD5 52989d66da54afb339a7b8bdb3a57229
BLAKE2b-256 b9eee8bcb1f640041bdcba5952b4ba5baed19b8999381a97d822ba996f751b93

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page