Inspiration
Got tired of watching Claude Code and Cursor choke on big repos. You ask it something simple and it either burns through half your context window reading files that have nothing to do with your prompt, or it just misses the one function that actually matters because it's buried three folders deep. Felt dumb that the AI has to figure this out fresh every single session when a repo's structure barely changes between prompts. So I built something that does the "figure out what's relevant" step before the AI even starts, instead of making the model do it live and pay for it in tokens.
What it does
Forge sits in front of your AI coding tool. Before you run claude, cursor, or codex, it scans your repo, pulls out symbols and dependencies, figures out which files actually matter for your prompt, and trims them down to just the relevant functions/classes using AST parsing (tree-sitter). Then it hands that pruned context to the AI tool through env vars or MCP. On top of that it injects some behavior rules (basically forces YAGNI-style implementations and shorter responses so it's not writing 10 files when you asked for 1) and there's a commit message generator that reads your staged diff and writes a proper conventional commit for you.
How I built it
Whole thing runs through one pipeline no matter which tool you're launching:
- scan the repo (regex-based parsers, works across Python/JS/TS/JSX/TSX)
- rank files using TF-IDF against your prompt + how central they are in the dependency graph
- prune with tree-sitter down to just the symbols that matter
- prepend the behavior rules
- compress (strip whitespace/boilerplate)
- cache it against a repo fingerprint so re-runs are instant
- set FORGE_CONTEXT and launch your actual tool
There's also an optional layer I added later — a classifier that looks at your prompt and tags it simple/edit/multi-feature/complex, then routes to a lighter or heavier model depending on that, splits multi-part requests into separate chunks, and re-runs just the broken piece if something fails validation instead of redoing the whole thing. That's all opt-in, off by default, sits on top of the core stuff.
Also exposed 6 tools over MCP (get_optimized_context, get_summary, get_dependency_graph, file_lookup, symbol_lookup, semantic_search) so it's not locked to my wrappers, any MCP client can hit it directly.
Challenges I ran into
AST pruning across 5 different languages without spinning up a full language server per file was the annoying part, tree-sitter helped but tuning it to not accidentally strip something relevant took a while. Also had to be really careful the efficiency layer stayed additive only, it can't touch billing/quota/model pricing or mess with how the AI client picks its own tools, that boundary was non-negotiable for me. Early on I also had a bug where if you ran forge from your home directory instead of inside a project it would just try to scan everything on your machine, that was a fun one to catch.
Building an actual benchmark that measures real token savings instead of just claiming a number was harder than I expected too, had to wire up tiktoken and Anthropic's count API and do live runs to get numbers I could actually stand behind.
Accomplishments I'm proud of
One pipeline powering Claude Code, Cursor, Codex, and Antigravity instead of four separate half-baked integrations. Published it to PyPI so it's a one-liner install (uv tool install forgeoptimizer). And forge benchmark actually spits out real measured numbers with CSV/JSON/markdown reports, not marketing fluff.
What I learned
Most of the "AI isn't smart enough" complaints are actually "the AI got handed too much garbage context" problems. Also learned that staying disciplined about scope (never touch billing, never touch model internals) made the whole thing way easier to reason about and trust, versus trying to be some all-in-one wrapper that does everything.
What's next for Forge
Want to add Go/Rust/Java support since right now it's Python/JS/TS only. Also want an actual visual dependency graph in the CLI instead of the text dump it gives right now, and smarter thresholds for when to do selective context vs full context depending on repo size instead of a fixed cutoff.
Open in a workspace folder through wrapper commands
Built With
- cli
- mcp
- pypi
- python
- react
- typescript
Log in or sign up for Devpost to join the conversation.