Skip to content
Back to skills

Bonsai

ASecurity

Manage git worktrees with the bonsai CLI - create isolated per-branch worktrees outside the repo, jump between them, see which agents work where, and clean up merged ones or their disk usage. Use when working on a branch in isolation, parallelizing tasks across worktrees, or tidying up worktrees, branches, and disk space.

  • 11 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added October 19, 2026
ai-agentsgoshellterraformgitdatabase

Works with

  • terminal
  • cli
  • mcp

Security analysis

A100/100

Scanned November 23, 2026

npx -y skills add aymericbeaumet/bonsai --skill bonsai --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Bonsai?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Bonsai
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/aymericbeaumet-bonsai/badge)](https://www.skillsdirectory.com/skills/aymericbeaumet-bonsai)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: bonsai
description: Manage git worktrees with the bonsai CLI - create isolated per-branch worktrees outside the repo, jump between them, see which agents work where, and clean up merged ones or their disk usage. Use when working on a branch in isolation, parallelizing tasks across worktrees, or tidying up worktrees, branches, and disk space.
---

## Git worktrees (bonsai)

### Scope and authorization

Use bonsai to complete the requested worktree operation. Explicit user
instructions override this skill's defaults; carry existing authorization
forward within its scope. Infer routine choices from context and continue
through verification rather than stopping at a proposed command.

If a skill instruction would block or redirect requested work, first check
whether it applies and whether the user already authorized the action. If
it still blocks progress, link the exact SKILL.md you read, quote the rule,
and explain the remaining blocker separately from your interpretation.

### Mental model

- Worktrees live outside the repository at `<root>/<repo-id>/<branch>`
  (default root `~/.bonsai`). Branch names nest: `feat/x` → `feat/x/`.
- Run bonsai from anywhere inside the repo — the main checkout or any
  worktree — it always operates on the repository as a whole.
- Scope: inside a repo, commands act on that project; `-a`/`--all` widens
  them to every project under the root. Outside a repo every project is in
  scope, including for `clean`, `remove`, and `prune`. `-C <dir>`
  (`--cwd`) runs bonsai as if started in `<dir>`, like `git -C`; prefer it
  to scope a command to one project from elsewhere.
- `add` preserves existing branch names and slugifies new inputs segment-by-segment
  while preserving `/` as a nested branch/path delimiter, creates branches automatically, and fetches
  the remote default branch first. Missing arguments open fuzzy pickers on a
  real terminal only; in non-interactive use, always pass arguments or the
  command exits with an error.

### Core workflow

```sh
path=$(bonsai add <branch>)     # create or reuse; prints absolute path; idempotent
cd "$path"                      # then work inside the worktree
bonsai add <branch> --base HEAD # stack on the checkout you run it from
bonsai list --json              # this repo's worktrees, machine-readable
bonsai ps --json                # coding agents running in this repo's worktrees
bonsai remove <branch> [-d]     # drop the worktree (keep branch unless -d)
bonsai clean --dry-run --json   # inspect merged/squash-merged branches
bonsai clean --yes              # execute when cleanup is authorized
bonsai trim --dry-run --json    # inspect reclaimable ignored files
bonsai trim --yes               # execute when freeing disk is authorized
```

The bulk commands `trim`, `clean`, and `prune` share flags: `--dry-run`
plans, `--json` reports, and `--yes` skips the prompt.

### Invariants

- `--base` resolves against the directory bonsai runs from, not the main
  checkout: `--base HEAD` inside a worktree stacks on that worktree.
- New branches created from a base carry no upstream (`--no-track`) until
  first push; branches checked out from the remote track that remote branch.
- A deleted upstream alone never proves a branch is safe to clean.
- A fresh worktree with zero commits already counts as "merged", so `clean`
  will list it — read the plan before executing.
- Untracked local config (`.env*`, `.envrc`, `.mcp.json`, `CLAUDE.local.md`,
  ...) is copied into new worktrees automatically.
- Dependencies are installed automatically in new worktrees when a lockfile
  is present (pnpm/npm/yarn/bun/cargo/uv, lockfiles preserved). Missing tools
  and failed installs leave the worktree available and print an incomplete-setup
  summary with a retry command. Re-adding does not rerun setup. Check stderr before
  assuming deps are in place. Follow any linked package-manager configuration
  warning to enable its worktree-optimized shared store.
- Shell auto-cd applies only to terminal stdout; substitutions and redirections
  preserve paths. `command bonsai` bypasses the wrapper explicitly.

### Cleanup and removal

Choose by what should remain: `trim` keeps the worktree and branch while
removing ignored files; `remove` deletes the chosen checkout directory but
keeps the branch unless `-d`; `clean` deletes integrated checkout directories
and their branches; `prune` drops missing registrations and deletes orphan
directories under the Bonsai root, keeping branches and live registrations.
`remove` matches `git worktree remove`; `trim` is ignored-only cleanup like
`git clean -X`, with additional keep rules. `clean` selects merged worktrees;
`prune` extends `git worktree prune` with orphan-directory deletion.

- Inspect cleanup candidates with `bonsai clean --dry-run --json`.
  A preview-only request ends with the plan. When the user authorized
  cleanup and the inspected targets fit that scope, execute with `--yes`;
  the user need not name the flag. Preserve the preview's scope flags.
- `clean` removes eligible worktrees and their branches across the projects
  in scope. A fresh worktree with no commits can qualify; exclude active work
  from the intended cleanup. Name branches or exact paths with `bonsai clean <target>…` to narrow its
  plan. For removal regardless of integration, use `bonsai remove <branch>`;
  add `-d` only when branch deletion is intended.
- `trim` deletes git-ignored files (dependencies, build output, caches) from
  all Git-registered linked worktrees, including other tools’ checkouts. It keeps worktrees, branches, tracked and
  non-ignored untracked files and common local state (`.env*`, databases,
  keys, Terraform state). Inside ignored dependency/build directories, only explicit `[trim]
  keep` globs and registered nested worktrees are protected; package fixtures
  and dependency checkouts are regenerable (see `bonsai trim --help`). Other
  ignored files are lost, so read the `--dry-run --json` plan. A request to
  free disk space or trim authorizes `--yes` within the planned scope; name
  branches to narrow it, and ask before deleting plan entries that look like
  irreplaceable local data.
- `prune` removes missing, unlocked registrations (HQ: `directory deleted`)
  without deleting branches. Inspect `prune --dry-run --json` before deleting
  orphaned directories, which may contain uncommitted work. Keep `-a`/`--all`
  and runs outside a repo, which span repositories, within the user's scope.
- Other agents' worktrees are protected: `remove` refuses, and `clean` and
  `trim` skip, a worktree where `bonsai ps` shows another agent working.
  Report the skip; do not stop that agent or force removal unless the user
  asked for it. Your own worktree never blocks your request.
- On `trim`, `clean`, and `prune`, `--force` is an alias of `--yes`: it
  skips the prompt. `clean` still skips dirty worktrees. On `remove`,
  `--force` can discard uncommitted files, remove a worktree another agent
  is working in, and, with `-d`, delete an unmerged branch. Use it only when
  that data loss is authorized; a refusal alone is not authorization to
  force removal.
- If authorization is missing, prepare the candidate list before asking
  about the specific removal or data loss. Do not expand a cleanup request
  to unrelated worktrees or repositories.

### Verify the result

After adding a worktree, use the returned path and confirm its branch before
editing. After cleanup, trimming, or removal, inspect `bonsai list --json`
and the command's report; report removed targets, reclaimed space, skipped
worktrees (dirty, missing, or in use by an agent), and failures accurately.
If an operation partly succeeds, inspect the remaining state before retrying.
Read dependency-install warnings on stderr even when `add` succeeds.

Use `bonsai <cmd> --help` for the installed version's exact interface.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.