Composto
A fast structural map of your codebase, for AI agents. Your file's full structure in a fraction of the tokens.
Send your agent the structure, not the noise.
Composto compresses any source file into a structural IR that keeps exactly what your agent needs, signatures, types, control flow, dependencies, at 60-95% fewer tokens than raw code. Spread across a repo and kept fresh, that IR becomes a navigation map your agent reads instead of blindly opening files. Local-first, MIT. Works with Claude Code, Cursor, and Gemini CLI.
$ composto ir src/memory/confidence.ts L1
USE:./types.js
OUT INTERFACE:ConfidenceContext
OUT INTERFACE:ScoreAndConfidence
FN:calibrationFactor(signals: Signal[])
GUARD:[firing.length === 0 → 1.0, avg < 20 → 0.3, avg < 100 → 0.6]
FN:historyFactor(totalCommits: number)
GUARD:[totalCommits < 50 → 0.2, totalCommits < 200 → 0.5, totalCommits < 1000 → 0.8]
OUT FN:computeScoreAndConfidence(signals: Signal[], ctx: ConfidenceContext)
# 541 tokens of raw code → 230 tokens of IR (57% fewer). Structure intact:
# every signature, dependency, and decision threshold survives.
Use it in 3 steps
# 1. See what your repo costs an AI, zero install, no API key, ~2s
cd your-project
npx composto-ai score # scorecard: tokens, $/load, a README badge
# 2. Install
npm install -g composto-ai
# 3. Wire it into your AI agent so it gets compact context automatically
composto init --client=claude-code # or cursor, or gemini-cli
# Restart your client. Existing settings are merged, never overwritten.
That's it. On Claude Code, large code Reads are auto-replaced with structure-preserving IR before they hit the agent's context, saving tokens on every turn (see composto stats).
More commands
composto score . # shareable scorecard + README badge (add --json to pipe)
composto ir src/app.ts # compress one file to IR (L0/L1/L2/L3)
composto context src/ --budget 4000 # pack a directory's map into a token budget
composto context . --target <symbol> # target file raw, surroundings as IR
composto context . --json # machine-readable context for piping into agents
composto reindex . # write the navigation map to .composto/context.md
composto start . # keep the map live: file watcher auto-refreshes it
composto proxy --port 8787 # compression proxy, point your LLM base URL at it
composto stats # cumulative tokens saved by the compress hook
The core: a token-efficient structural map
Composto's spine is a tree-sitter based AST compressor and a smart context packer. Compress any file to IR, or pack a whole directory into a token budget:
composto ir src/app.ts # compress a file to IR (L0/L1/L2/L3)
composto context src/ --budget 2000 # smart context within a token budget
composto benchmark . # see compression stats
See the IR Layers, Health-Aware IR, and Context Budget sections below for details.
MCP plugin (Claude Code, Cursor, Claude Desktop)
The MCP server is bundled inside composto-ai. Install the package globally first, then register the server with your client:
npm install -g composto-ai
Claude Code:
claude mcp add composto -- composto-mcp
Cursor , add to ~/.cursor/mcp.json (or project-local .cursor/mcp.json):
{
"mcpServers": {
"composto": {
"command": "composto-mcp"
}
}
}
Then restart Cursor and verify under Settings → MCP that composto is green.
Claude Desktop , add the same block to ~/Library/Application Support/Claude/claude_desktop_config.json.
Composto adds 3 tools to your AI assistant: composto_ir, composto_context, and composto_benchmark.
Cursor: one-command setup
Registering the MCP server only exposes the tools, Cursor's agent often defaults to its built-in read_file / codebase_search. To configure both the MCP server and a project rule that tells the agent when to call Composto, run:
cd your-project
composto init --client=cursor --with-rules
This writes .cursor/mcp.json (project-local MCP registration) and .cursor/rules/composto.mdc (an alwaysApply: true rule injected into every conversation). Existing files are merged, never overwritten. Restart Cursor and check Settings → MCP that composto is green.
Without the rule, hit rate is ~30-50%; with it, ~85-95%. The rule template lives in src/cli/init.ts (CURSOR_RULES_MDC).
Hook-enforced compression (Claude Code)