DEV Community

ZeroRanker
ZeroRanker

Posted on

How I Saved $1.50 Per API Call By Building a Smart Repo Compressor for AI Assistants

What It Does

ContextForge is a Python CLI tool that solves the "my repo is too big for AI context window" problem.

The Python requests library = 154,061 tokens ($2.31 per GPT-4 call). 50% of that is test files, docs, changelogs.

ContextForge compresses it to 50,406 tokens ($0.77) by:

  • Analyzing Git history to find important files
  • Auto-excluding tests/binaries/node_modules
  • Extracting function signatures (not implementations)
  • Exporting optimized packages for GPT-4, Claude XML, Gemini, Aider

Results

Metric Before After
Tokens 154,061 50,406 (67% ↓)
Cost/Call $2.31 $0.77
Files 112 54

One command: contextforge forge ./repo --budget 50000 --model gpt4

Tech Stack

Python 3.10+ (tiktoken, gitpython, rich, typer, matplotlib)
48 tests passing | MIT License | Fully open source

Links

GitHub: https://github.com/zeroranker/contextforge

Built in ~2 hours as a side project. Would love feedback!

Top comments (0)