Behavior earns room.
Executable product contracts define the external surface. Distinct action–observation pairs determine one global allowance.
See the contract ↗Complexity budgets for coding agents
Your coding agent can build almost anything.
Bonsai gives it a reason to build less.
A small tool. An explicit stack.
A contract. A ceiling. A reason to prune.
export function validQuantity(quantity: number) { return Number.isInteger(quantity) && quantity > 0} export function placeOrder(input: { quantity: number }) { return { status: validQuantity(input.quantity) ? 'accepted' : 'rejected' }} export function unusedHelper() {}Change this file.Watch the verdict respond.
bonsai checkThe verdictRequired behavior. Justified code. Within budget.
Follow the contract into the handler, then through its dependencies. A helper doesn’t need its own top-level scenario.
Contract ancestry makes code eligible to remain. It still pays its full retained cost.
bonsai explain src/checkout.tsShared code counts once at its full cost. Simplification creates room after the changed candidate demonstrates real savings.
Passing tests are one condition. Staying lean is another.
A closer look at the checkout example. Explore the complete project
Deliberate growth. Continuous pruning.
Why Bonsai exists
AI agents add code in seconds. The extra layers slow every next feature.
Bonsai keeps your agent pruning before the codebase gets out of hand.
Principles behind Bonsai
Keep each level coherent enough to understand as a whole.
Make code easy to replace. Let useful parts stabilize; retire the rest early.
Keep the product’s promises while simplifying the implementation beneath them.
Passing tests are only the beginning
Bonsai checks required behavior, contract ancestry,
and retained size together.
Executable product contracts define the external surface. Distinct action–observation pairs determine one global allowance.
See the contract ↗Retained components need a path to a product contract. Lower-level tests inherit that ancestry; they cannot invent it.
Understand ancestry ↗When the next feature exceeds the ceiling, reclaim room. Inline the wrapper. Remove the duplication. Keep the required behavior.
Explore the budget ↗Describe behavior once
Accepted orders. Invalid quantities. Boundary cases. Each example must pass, but repeating an action and result never buys more code.
The specification stays in .feature files. A small executable registry connects it to your real handlers.
Feature: Checkout
Scenario Outline: Place an order
When I invoke "place-order" with {"quantity": <quantity>}
Then response "status" equals "<status>"
Examples:
| quantity | status |
| 1 | accepted |
| 0 | rejected |
| -1 | rejected |Diminishing room. Increasing discipline.
Start with room to bootstrap. After that, each doubling of external contract surface adds a fixed amount of capacity. Choose the bootstrap allowance, growth rate, and absolute ceiling.
More capability has to fit an increasingly economical implementation.
See the policyA shared wrapper still pays its full cost.
Reuse earns room when it removes real duplication.
Where the code meets the ceiling.
Contract surface · pairs
4,000 tokens to prune.
Beyond a green test suite
BDD checks what must work. Bonsai also limits what gets to stay.
| Behavior contracts, with compaction. | BonsaiCOMPACTION | BDD runnerCucumber alone | Lintersalone |
|---|---|---|---|
| Executable .feature scenarios | ✓ | ✓ | − |
| Checks expected scenario outcomes | ✓ | ✓ | − |
| Requires contract ancestry | ✓ | − | − |
| Caps total maintained source | ✓ | − | − |
| Reports required budget reduction | ✓ | − | − |
| Enforces lint rules | − | − | ✓ |
Bonsai builds on executable behavior contracts. It adds retention rules and a code budget.
Comparison reflects standalone use; custom integrations can add capabilities.
Your agent. A tighter loop.
Bonsai supplies the facts and the limit.
Your coding agent does the reasoning and the pruning.
Start with the retained size, required checks, and available headroom.
bonsai checkSee why a component belongs and which relationships keep it connected.
bonsai explain src/checkout.tsInline the wrapper. Remove the duplication. Keep the required behavior.
Run a fresh check. Preserve the behavior and prove the candidate fits.
bonsai checkGet started
Choose one route: ask your coding agent to set it up, or configure the project yourself.
Agent-assisted setup
Paste the prompt into the coding agent you already use. It guides the skill installation, policy, and first real contracts.
Get the agent skill1. Install the complete Bonsai skill from https://github.com/jiggy/bonsai/tree/main/skills/bonsai in this project's skills directory, including `references/`. Read `SKILL.md`. 2. Follow `references/adoption.md`: initialize Bonsai, review the inventory and policy in `bonsai.json`, and connect real handlers to `.feature` contracts. Preserve required behavior and existing tests. 3. Verify a passing baseline, then demonstrate unused-code rejection and recovery. Add the project gate command and agent instructions.
Install the CLI, then initialize your project. Bonsai preserves existing files and creates the configuration and starters you need.
Read the setup guidebun add --global @jigging/bonsai
bonsai initbonsai checkNo. A helper can inherit contract ancestry through the production component that needs it. Lower-level tests then inherit from retained subjects. A unit test cannot justify otherwise unsupported production code.
Extra examples, duplicate scenarios, and split files earn no additional allowance. Each required check still has to pass. Only distinct external action–observation pairs affect the surface count.
Bonsai measures retained source tokens within an explicit maintained inventory, including contracts, bindings, tests, fixtures, and configuration. Formatting outside TypeScript literals creates no headroom. The metric creates consistent pressure; it does not claim to measure comprehension or predict effort.
Bonsai reports the constraint and blocks acceptance. Your existing coding agent proposes and verifies the change. Unsupported code must be removed, connected to required behavior, or recovered through a legitimate contract correction.
Bonsai supports TypeScript and named in-process handlers, a small executable Gherkin grammar, static symbol ancestry, retained-size budgets, and candidate-bound contract results. Use it for a supported pilot and review the maintained inventory.
HTTP and queue adapters, coverage and mutation evidence, and hardened merge enforcement are on the roadmap. Contract handlers execute with your privileges; use an external sandbox for untrusted candidates. Read the full limits ↗
Deliberate growth. Continuous pruning.