Forge
Forge is a pre-launch context preparation tool for AI coding assistants. Before you run claude, codex, or cursor, Forge scans your repository, extracts symbols and dependencies, builds a structured summary, injects configurable behavior instructions, and passes the optimized context to the AI tool through environment variables and MCP tools.
Core Philosophy
[!IMPORTANT] Forge optimizes what it controls.
Forge focuses on three areas:
- Repository Intelligence — Symbol extraction, dependency analysis, file scanning, and semantic ranking.
- Behavior Optimization — Configurable implementation guidance (PromptForge YAGNI rules) and response style optimization (ResponseForge conciseness rules).
- Runtime Infrastructure — Zero-configuration wrappers, context caching, background daemon, and MCP server.
Forge prepares context before the AI session begins. It does not modify provider billing, quota accounting, model pricing, model inference, or the AI client's internal tool selection logic.
Architecture
Forge has a single unified context preparation path used by all wrappers:
- Repository scan — Extracts files, symbols (classes/functions), and dependencies (imports/requires) using parallel regex-based parsers for Python, JS, TS, JSX, and TSX.
- Semantic ranking — Ranks files by TF-IDF query relevance with dependency centrality scoring.
- AST pruning — Uses tree-sitter to prune files to only relevant symbols, keeping context lean.
- Behavior injection — Prepends intensity-gated PromptForge (YAGNI) and ResponseForge (conciseness) instructions.
- Compression — Collapses whitespace, strips boilerplate, and removes redundant content.
- Caching — Fingerprints repositories and caches context between launches.
- Launch — Sets
FORGE_CONTEXTenv var and starts the AI CLI.
Already built-in (unchanged)
These core layers are the default Forge path and stay on unless you turn them off via profile/config:
| Layer | What it does |
|---|---|
| PromptForge (Minimal Build Mode) | Implementation-style / YAGNI rules that prune speculative work |
| ResponseForge (Concise Mode) | Concise response-style rules |
| Semantic ranking + AST prune | Query-aware file ranking and symbol-level pruning |
| Compression + cache | Token compression and fingerprint-based reuse |
Optional efficiency layers (new, disabled by default)
Additive cost-reduction modules live under forgecli/efficiency/ and activate only when you set [efficiency] enabled = true. They do not replace Minimal Build Mode / Concise Mode — they sit on top.
| Module | Purpose |
|---|---|
| Prompt classifier | Labels requests as simple / edit / multi_feature / complex before LLM work |
| Tiered model routing | Maps classifier output to configurable light/standard/heavy models |
| System-prompt-first assembly | Keeps shared system instructions first so prefix KV cache can hit |
| Feature decomposition | Splits multi-feature asks into independently validated units |
| Validate–regenerate loop | Re-runs a failing unit instead of forwarding broken output |
| Selective context preload | Full context on small repos; request-referenced + key files on large ones |
Example config (forgecli.toml / Forge.toml):
[efficiency]
enabled = true
classifier = true
tiered_routing = true
system_prompt_first = true
feature_decomposition = true
validate_regenerate = true
selective_context = true
selective_file_threshold = 400
max_features = 8
max_regenerate_attempts = 3
[efficiency.tiers]
light_model = "claude-haiku-4.5"
standard_model = "claude-sonnet-4.5"
heavy_model = "claude-opus-4.6"
simple_max_score = 0.35
edit_max_score = 0.65
Tier values may be bare model ids (claude-haiku-4.5) or provider:model (anthropic:claude-haiku-4.5).
Installation
uv tool install forgeoptimizer
The CLI entrypoint is forge.
To upgrade an existing installation to get the latest optimization fixes:
uv tool upgrade forgeoptimizer
Important Usage Guidelines
[!IMPORTANT] Always run commands inside your specific project directories.
Forge scans the files in your current working directory to build context.
- Do not run
forgecommands inside your home directory (~) or root (/), as this will cause Forge to scan all unrelated system/home directories and files, leading to long scans or freezes.- Always
cdinto your specific project folder or Git repository before running commands likeforge claude,forge cursor, orforge antigravity.
Interfaces
Forge provides two ways to connect with your AI coding tools:
- Convenience Wrappers (
forge claude,forge cursor,forge codex,forge antigravity) — Automatically prepare context, configure MCP, and launch the target AI CLI. - MCP Server (
forge mcp) — Standard stdio JSON-RPC interface exposing 6 tools that AI clients can call during sessions.
Command Reference
| Command | Description |
|---|---|
forge claude |
Launch Claude Code with optimized context |
forge codex |
Launch Codex CLI with optimized context |
forge cursor |
Launch Cursor CLI with optimized context |
forge antigravity |
Launch Antigravity CLI with optimized context |
forge commit |
Generate a Conventional Commit message from staged changes |
forge mcp |
Start the stdio MCP server |
forge start |
Start the background daemon |
forge config |
Configure optimization profiles |
forge status |
Show repository, daemon, and optimization status |
forge doctor |
Verify installation and dependencies |
forge inspect |
Display active pipeline and optimization stages |
forge stats |
Show cache metrics and pipeline performance |
forge profile |
View or set optimization profiles |
forge explain |
Explain pipeline stages, concepts, or topics |
forge --version |
Show version |
Use --refresh to bypass the cache on any wrapper command:
forge claude --refresh
MCP Tools
Forge exposes 6 tools over MCP:
get_optimized_context— Full optimized repository context with optional query filteringget_summary— Repository layout, file count, and size summaryget_dependency_graph— Module/file import relationships (from repo scan)file_lookup— File contents by relative pathsymbol_lookup— Class/function definitions and locationssemantic_search— Keyword search across codebase chunks
[!IMPORTANT] Forge exposes these tools, but whether they are called depends on the AI client's internal orchestration. Forge does not control tool selection.
Environment Variables
| Variable | Purpose |
|---|---|
FORGE_CONTEXT |
Optimized pre-launch context text |
FORGE_CONTEXT_FILE |
Path to the cached context file |
FORGE_REPO_ROOT |
Detected repository root |
Token-reduction benchmark
Measure real input-token counts (tiktoken / Anthropic count API) for baseline vs Forge across Claude, Codex, Cursor, and Antigravity model mappings:
# Default: Forge small/medium/large scopes, all tasks + ablations
forge benchmark -o benchmark_results
# Faster smoke run
forge benchmark --quick -o /tmp/forge-bench
# Optional: measure completion tokens via provider APIs
ANTHROPIC_API_KEY=… OPENAI_API_KEY=… forge benchmark --live -o benchmark_results
Reports: token_benchmark.md (docs-ready), .json, and .csv. Negative reductions (Forge increased tokens) are listed explicitly.
Token-reduction fixes (measured)
- Session instruction cache — PromptForge/ResponseForge rules sent once per MCP/session (
get_session_instructions+ cachedget_optimized_context). - Hard
max_tokenscaps by classifier tier ([efficiency.tiers] max_tokens_simple|edit|…). - Adaptive selective context — activates on file count or estimated token budget (default threshold 150 files / 6k tokens), not only at 400+.
- MCP primary context — initialize
instructions+forge://contextresource tell the agent Forge context replaces full-repo dump.
Live completion tokens (where Concise Mode / Minimal Build Mode should show wins):
export FEATHERLESS_API_KEY=…
forge benchmark --live --live-provider featherless --quick -o docs/benchmark_results
# optional model override:
forge benchmark --live --live-provider featherless --live-model meta-llama/Meta-Llama-3.1-8B-Instruct
Default Featherless model is mistralai/Mistral-7B-Instruct-v0.2 (override with --live-model / FEATHERLESS_MODEL). Anthropic / OpenAI remain supported via --live-provider anthropic|openai when those keys are funded.
Development
git clone https://github.com/mdshzb04/Forge
cd Forge
python -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"
pytest
ruff check forgecli tests
License
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file forgeoptimizer-1.3.1.tar.gz.
File metadata
- Download URL: forgeoptimizer-1.3.1.tar.gz
- Upload date:
- Size: 437.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7941b310a168e3311d6fc8ea1755b72d4c6fc786941d3ab18de790e274ec3fee
|
|
| MD5 |
fc8ab5b3e47ae97ab84a6ce8635ed7d1
|
|
| BLAKE2b-256 |
4924ea369045d9205e09af73c3445953b68027a45d8acfefee8d5a264d818424
|
Provenance
The following attestation bundles were made for forgeoptimizer-1.3.1.tar.gz:
Publisher:
ci.yml on mdshzb04/Forge
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
forgeoptimizer-1.3.1.tar.gz -
Subject digest:
7941b310a168e3311d6fc8ea1755b72d4c6fc786941d3ab18de790e274ec3fee - Sigstore transparency entry: 2360242284
- Sigstore integration time:
-
Permalink:
mdshzb04/Forge@4560ce2af26896832399fb10b5e770659c8f5a1a -
Branch / Tag:
refs/tags/v1.3.1 - Owner: https://github.com/mdshzb04
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@4560ce2af26896832399fb10b5e770659c8f5a1a -
Trigger Event:
push
-
Statement type:
File details
Details for the file forgeoptimizer-1.3.1-py3-none-any.whl.
File metadata
- Download URL: forgeoptimizer-1.3.1-py3-none-any.whl
- Upload date:
- Size: 363.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
79655959690db074388936a182897f5496aa6d06ef901409926aed52ef92fa05
|
|
| MD5 |
ae46f1aeb58d77b8b040846a55a25bf7
|
|
| BLAKE2b-256 |
1c60bc944f4c844f37f51dcc4834e576c199800dcd507be1a9fa7403b640c504
|
Provenance
The following attestation bundles were made for forgeoptimizer-1.3.1-py3-none-any.whl:
Publisher:
ci.yml on mdshzb04/Forge
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
forgeoptimizer-1.3.1-py3-none-any.whl -
Subject digest:
79655959690db074388936a182897f5496aa6d06ef901409926aed52ef92fa05 - Sigstore transparency entry: 2360242414
- Sigstore integration time:
-
Permalink:
mdshzb04/Forge@4560ce2af26896832399fb10b5e770659c8f5a1a -
Branch / Tag:
refs/tags/v1.3.1 - Owner: https://github.com/mdshzb04
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@4560ce2af26896832399fb10b5e770659c8f5a1a -
Trigger Event:
push
-
Statement type: