On this repository Bonsai reduced ~76,911 raw tokens to 13,450 shrunk tokens (~82.5% savings) using AST skeletonization — keep your LLM contexts small, accurate, and cheap.
Naming note: the GitHub repository, CLI binary, Codex plugin, and Claude plugin are bonsai; the VS Code package is bonsai-vscode.
Command:
Output:
Run inside a repo:
bonsai .This writes:
bonsai.xml
Copy it into your LLM and ask:
Use this Bonsai XML as repo context. Summarize the architecture and tell me where to start reading.
Need the binary? Download a release. No Rust needed.
macOS Apple Silicon:
curl -L -o bonsai https://github.com/MickyBalladelli/bonsai/releases/latest/download/bonsai-macos-arm64
chmod +x bonsai
sudo mv bonsai /usr/local/bin/bonsaiLinux x64:
curl -L -o bonsai https://github.com/MickyBalladelli/bonsai/releases/latest/download/bonsai-linux-x64
chmod +x bonsai
sudo mv bonsai /usr/local/bin/bonsaiOr install from source:
cargo install --path .Install straight from GitHub:
cargo install --git https://github.com/MickyBalladelli/bonsai.gitUse Bonsai when you want broad repo context that is visible and repeatable:
Summarize this project.
Explain the architecture.
Find likely entry points.
Prepare context before asking another LLM.
Compare token savings before sending repo context.
It is less useful when the agent already has the exact file or function you want edited.
Release binaries:
bonsai-macos-arm64
bonsai-linux-x64
Download from:
https://github.com/MickyBalladelli/bonsai/releases/latest
From this repo:
cargo install --path .From git:
cargo install --git https://github.com/MickyBalladelli/bonsai.gitOr build a local binary:
cargo build --release
target/release/bonsai .Tagged releases publish:
bonsai-linux-x64
bonsai-macos-arm64
bonsai-linux-x64.sha256
bonsai-macos-arm64.sha256
bonsai-vscode-*.vsix
The Codex plugin, Claude Code plugin, and VS Code extension find the binary in this order:
BONSAI_BIN
bonsai on PATH
repo-local target/release/bonsai
Paste-ready clipboard prompt:
bonsai . --prompt --output clipboardCustom paste-ready prompt:
bonsai . --ask-template "Use this repo context to find likely bugs." --output clipboardArchitecture map:
bonsai . --level 3Detailed repo context:
bonsai . --max-tokens 12000 --level 2Only scan src:
bonsai srcWrite somewhere else:
bonsai . --output-file /tmp/bonsai.xmlWrite JSON:
bonsai . --format json --output-file /tmp/bonsai.jsonWrite a paste-ready prompt file:
bonsai . --prompt --output-file /tmp/bonsai-prompt.txtShow selected files:
bonsai . --print-filesOnly write the project map:
bonsai . --project-map-onlyWrite metadata and project map without file bodies:
bonsai . --no-contentSort output:
bonsai . --sort priority
bonsai . --sort tokens
bonsai . --sort pathAdd per-directory token summaries:
bonsai . --directory-summariesFail when output is still over budget after maximum compression:
bonsai . --max-tokens 12000 --fail-over-budgetWrite starter agent instructions:
bonsai init-agent
bonsai init-agent . --forceMeasure token savings:
bonsai . --max-tokens 12000 --statsFilter files:
bonsai . --include 'src/**' --exclude '**/generated.rs'Skip files larger than the default 1 MiB limit:
bonsai . --max-file-bytes 2097152Use --max-file-bytes 0 to disable the size cap.
Generate context:
bonsai . --max-tokens 12000 --level 2 --prompt --output-file /tmp/bonsai-prompt.txtPaste /tmp/bonsai-prompt.txt into an LLM. It starts with:
Use this repo context to explain the architecture, identify the main entry points, and tell me where to start reading.
This repo includes a Codex plugin:
plugins/bonsai
Add the local marketplace:
codex plugin marketplace add "$HOME/dev/bonsai/.agents/plugins"Then install or enable bonsai in Codex.
Ask:
Use $bonsai to compress this repo before answering.
The helper command is:
plugins/bonsai/skills/bonsai/scripts/run_bonsai.sh . 12000 2 /tmp/bonsai.xmlThis repo includes a Claude Code plugin:
claude/bonsai
Run Claude Code with the plugin:
claude --plugin-dir ./claude/bonsaiUse the skill:
/bonsai:bonsai
The helper command is:
claude/bonsai/bin/bonsai-claude . 12000 2 /tmp/bonsai.xmlFor local marketplace testing:
claude plugin marketplace add .Then inside Claude Code:
/plugin install bonsai@bonsai
The VS Code extension lives here:
copilot/bonsai-vscode
Install the packaged VSIX:
code --install-extension copilot/bonsai-vscode/bonsai-vscode-0.3.1.vsixRun Command Palette:
Bonsai: Generate and Ask
If chat does not open automatically, paste the copied prompt into Copilot Chat, ChatGPT, or Codex in VS Code.
Other commands:
Bonsai: Generate Context
Bonsai: Copy Context Prompt
Bonsai: Copy Project Map
Bonsai: Preview Project Map
Bonsai: Open Last Context
--level 1 keeps full code first, then shrinks files if the token budget is too small.
--level 2 keeps imports, signatures, types, classes, and function shapes. Function bodies become ....
--level 3 keeps a compact tree map only.
Full source:
fn greet(name: &str) -> String {
let message = format!("hello {name}");
println!("{message}");
message
}Skeleton:
fn greet(name: &str) -> String { ... }Tree map:
fn greet(name: &str) -> String
Markdown and config files are treated differently from source code. Bonsai keeps compact headings, important lines, and top-level config shape.
XML is the default. Use --format json for JSON.
Both formats include:
metadata: generated time, repo root, token budget, compression level, file count
project map: file paths, selected levels, per-file token counts
files: compressed file contents with per-file token counts
Schema notes live in:
docs/output-schema.md
Bonsai scans:
.js .jsx .ts .tsx .py .rs .go .java .cs .swift .kt .md .json .yaml .yml .toml
It parses JavaScript, TypeScript, Python, Rust, Go, Java, C#, Swift, and Kotlin with tree-sitter. Docs and config files use compact line-based context.
It respects .gitignore and .cursorignore.
Binary not found:
Install with `cargo install --path .`, set `BONSAI_BIN`, or run `cargo build --release`.
Clipboard failure:
Use `--output file --output-file /tmp/bonsai.xml`.
Clipboard access can fail in headless shells, remote sessions, or sandboxes.
No files selected:
Run with `--print-files`.
Check `--include`, `--exclude`, `.gitignore`, and `.cursorignore`.
Use `--no-respect-gitignore` when ignored files should be included.
Output over budget:
Use a smaller target path, add `--exclude`, increase `--max-tokens`, or use `--level 3`.
Check:
cargo checkTest:
cargo testBuild release binary:
cargo build --releaseBuild VS Code extension:
cd copilot/bonsai-vscode
npm install
npm run compile
npm run packageCI and releases are configured in:
.github/workflows/ci.yml
.github/workflows/release.yml
Create a release:
git tag v0.3.1
git push origin v0.3.1Version bump checklist:
Cargo.toml
copilot/bonsai-vscode/package.json
copilot/bonsai-vscode/package-lock.json
plugins/bonsai/.codex-plugin/plugin.json
claude/bonsai/.claude-plugin/plugin.json
.claude-plugin/marketplace.json, if pinning marketplace version
README install/package examples


