bonsai

command module
v0.2.28 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 19, 2026 License: MIT Imports: 24 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

          .&&&&&&&&&&.
       .&&&&&&&&&&&&&&&&.        .&&&&&.
        '&&&&&&&&&&&&&&'     .&&&&&&&&&&&.
             '-.\ /.-'        '&&&&&&&&&'
   .&&&&&.       ) (       _.-'                 _                           _
 .&&&&&&&&&.    /  /   _.-'                    | |__   ___  _ __  ___  __ _(_)
  '&&&&&&&'-._ (  (_.-'                        | '_ \ / _ \| '_ \/ __|/ _` | |
              '-\  \                           | |_) | (_) | | | \__ \ (_| | |
                 )  )                          |_.__/ \___/|_| |_|___/\__,_|_|
          _______/____\_______
          \__________________/
             \_/        \_/

bonsai

Grow and prune git worktrees, run AI agents across them. In a local web workspace, a TUI or a plain CLI.

CI Latest release Go version

Install

# macOS / Linux
curl -fsSL https://raw.githubusercontent.com/Tiago-0liveira/bonsai/main/install/install.sh | bash
# Windows (PowerShell 5.1+)
irm https://raw.githubusercontent.com/Tiago-0liveira/bonsai/main/install/install.ps1 | iex

Both download the latest GitHub Release, verify its SHA256 checksum and need no Go. Release binaries embed the full web UI. Prefer Go? go install github.com/Tiago-0liveira/bonsai@latest gives you the TUI and CLI, but /app serves only a placeholder (no embedded web UI; see Building).

What you can do

🌳 Manage git worktrees
  • Create a worktree from a new branch, an existing branch or a GitHub PR, and copy untracked files (.env and friends) into it via a fuzzy finder.
  • Lifecycle hooks (on_worktree_create / on_worktree_delete) and aliases: run project commands (Node, Python, Go, Rust, Make) or your own as background processes, many per worktree, with live dev-server URLs next to each.
  • See PR and CI status, ahead/behind, dirty counts and a diff against base for every worktree at a glance.
  • Prune with a clear preview of exactly what will happen, optionally merging the PR first.
🖥️ Three interfaces, one core
  • Web workspace: bonsai web serves a local app at http://127.0.0.1:7001/app, embedded in release binaries. No hosted service.
  • TUI: bonsai inside a repo, with a searchable keymap (?) and an Agents tab (g, see docs/agents.md).
  • CLI: every feature is also a plain, scriptable command.
⚙️ Background supervisor

bonsai web starts a background daemon and returns. Watch it with bonsai web --attach (or bonsai web attach) for live logs; detaching leaves it running. Manage it with status, logs, restart, stop and doctor.

🤖 AI agents
  • Integrates Claude Code, Codex and Antigravity.
  • Several profiles (accounts) per provider, each with an isolated config directory, so accounts never leak into each other.
  • Run many agent sessions at once across worktrees, in the web terminal dock or with bonsai agent run.
  • Start, watch, control and stop sessions from the TUI's Agents tab, with provider-grouped profiles and usage, clear input-focus hints, color-coded capacity bars, and model/effort overrides for each new agent. Provider icons are ✹ for Claude and ❃ for Codex. Compact provider counts sit beside worktree badges, and a usage pane under the worktree list (30+ rows) shows remaining capacity with provider-colored rails and adaptive meters (usage pane).
  • The TUI's Usage page shows compact account strips with aligned default and model usage rows, remaining-capacity meters, colored balances and reset times.
  • Per-profile launch defaults (model, effort, permissions) and an Agents tab in the web app to manage profiles, sign-ins and sessions.
  • bonsai agent usage shows plan limits (5-hour and weekly windows, credits, resets) for every profile of every provider at once, with live progress.
  • bonsai agents attach <id> keeps detach, kill and control shortcuts visible; killing requires confirmation (session controls).

Details: docs/agents.md.

🔄 Also
  • Live GitHub updates, optional: a webhook through a Cloudflare, ngrok or Tailscale tunnel replaces polling. Only the webhook receiver is ever exposed (docs/web.md).
  • Self-update: bonsai update verifies and installs the latest release.

Quick start

bonsai web                      # first run: pick project folders, then opens the UI

cd your-repo
bonsai                          # TUI: n new worktree, enter shell, ? keymap, q quit
bonsai create --pr 42           # CLI: worktree from a GitHub PR, prints its path
bonsai agent account add claude work   # then start an agent from any worktree

For scripts: bonsai web --no-open --no-setup.

CLI cheat sheet

# worktrees
bonsai list                         # worktrees (branch, path)
bonsai create <branch>              # new branch (--existing <br> | --pr <n>)
bonsai copy <file> <worktree>       # copy a main-repo file into a worktree
bonsai path <branch|main>           # print a path (pair with `bcd`, see docs)
bonsai x <alias> [worktree]         # run an alias (x --list to see them)

# web app
bonsai web [--attach]               # start in the background / follow live logs
bonsai web status|logs|restart|stop|doctor|setup

# agents
bonsai agent account add <provider> <name>    # claude | codex | antigravity
bonsai agent account list
bonsai agent run <account> [-- <args…>]
bonsai agent usage [--refresh]

# maintenance
bonsai update [--check]             # self-update
bonsai help                         # full usage

Full reference, keybindings and the bcd shell helper: docs/tui-cli.md.

Configuration

Drop an optional .bonsai.yaml in your repo root:

upstream: origin/main          # base ref for ahead/behind and prune's merge target

hooks:
  on_worktree_create:
    - "cp {main}/.env {new_worktree}/.env"
    - "npm install"

aliases:
  - name: dev
    command: "npm run dev"

Every field is documented in the annotated .bonsai.yaml; hook variables are listed in docs/tui-cli.md.

Documentation

Doc What is in it
docs/web.md Running the web app: setup, project folders, settings, updates and tunnels, Agents tab, recovery
docs/agents.md Claude Code, Codex and Antigravity profiles, seeding, isolation, usage, defaults
docs/tui-cli.md TUI keybindings, CLI reference, configuration, hooks, prune, updates
docs/architecture.md How the local web stack fits together
docs/git-backend.md Local API security model, webhook receiver, Git backend
docs/development.md Contributor stack, ports, provider contract, validation
docs/releasing.md CI, release builds and validation
CONTRIBUTING.md Contributing checklist

Requirements

  • git 2.35+ on your PATH.
  • gh (optional): PR badges, worktrees from PRs, merge-on-prune and GitHub data in the web app. Everything else works without it.
  • Agents (optional): Claude Code 2.1.295+ (claude), Codex CLI 0.162.1+ (codex) and/or Antigravity (agy). Interactive agent terminals in the web app are not available on Windows yet.
  • Go 1.26+ only if you build from source.

Building from source

go build -o bonsai .            # TUI + CLI; /app shows a placeholder

To embed the web app, build the frontend first (Node 22.12.0, pnpm 12.9.1):

pnpm --dir web install --frozen-lockfile && pnpm --dir web build
go build -tags embedui -o bonsai .

See CONTRIBUTING.md for the full test and lint workflow.

License

MIT

Documentation

Overview

Command bonsai is a git worktree manager TUI. main wires the core layer (config, state, git discovery) into the Bubble Tea presentation layer.

Directories

Path Synopsis
internal
agentsbackend
Package agentsbackend implements the TUI's agentsapi contract on the real agent runtime and holder records, shared with the web UI and the CLI.
Package agentsbackend implements the TUI's agentsapi contract on the real agent runtime and holder records, shared with the web UI and the CLI.
cli
Package cli implements bonsai's non-interactive subcommands.
Package cli implements bonsai's non-interactive subcommands.
core/agenthost
Package agenthost runs each agent session in its own detached holder process (`bonsai __agent-host`), so a session outlives the API that started it.
Package agenthost runs each agent session in its own detached holder process (`bonsai __agent-host`), so a session outlives the API that started it.
core/agents/usagefmt
Package usagefmt formats agent usage as plain text.
Package usagefmt formats agent usage as plain text.
core/agentsetup
Package agentsetup runs profile setup and sign-in for the web: each job owns a terminal stream for the provider's login commands and a secret prompt the browser answers.
Package agentsetup runs profile setup and sign-in for the web: each job owns a terminal stream for the provider's login commands and a secret prompt the browser answers.
core/agentterminal
Package agentterminal runs provider processes in PTYs with bounded terminal streams; package agenthost holds each agent session in its own process.
Package agentterminal runs provider processes in PTYs with bounded terminal streams; package agenthost holds each agent session in its own process.
core/browser
Package browser opens a URL in the user's default web browser.
Package browser opens a URL in the user's default web browser.
core/clipboard
Package clipboard copies text to the system clipboard via the first available external tool.
Package clipboard copies text to the system clipboard via the first available external tool.
core/config
Package config loads the .bonsai.yaml project config via viper and persists mutable state (file-copy frequency, aliases) to the user config directory.
Package config loads the .bonsai.yaml project config via viper and persists mutable state (file-copy frequency, aliases) to the user config directory.
core/editors
Package editors discovers GUI editors for the environment running Bonsai: commands on PATH and a few well-known user directories on Linux, PATH plus standard application bundles on macOS, and PATH plus the standard install folders on Windows.
Package editors discovers GUI editors for the environment running Bonsai: commands on PATH and a few well-known user directories on Linux, PATH plus standard application bundles on macOS, and PATH plus the standard install folders on Windows.
core/exec
Package exec manages independent background subprocesses.
Package exec manages independent background subprocesses.
core/fs
Package fs handles fuzzy file search over the main repo tree and copying files from the main repo into a worktree.
Package fs handles fuzzy file search over the main repo tree and copying files from the main repo into a worktree.
core/gh
Package gh wraps the GitHub CLI (`gh`) for the operations bonsai needs.
Package gh wraps the GitHub CLI (`gh`) for the operations bonsai needs.
core/git
Package git wraps the Git CLI.
Package git wraps the Git CLI.
core/notify
Package notify sends best-effort desktop notifications.
Package notify sends best-effort desktop notifications.
core/pkgmgr
Package pkgmgr discovers project/build commands from package managers and build tools.
Package pkgmgr discovers project/build commands from package managers and build tools.
core/portowner
Package portowner names the process listening on a loopback TCP port, so a port conflict can say "pid 4242, node" instead of only "in use".
Package portowner names the process listening on a loopback TCP port, so a port conflict can say "pid 4242, node" instead of only "in use".
core/procstore
Package procstore owns bonsai's on-disk process state.
Package procstore owns bonsai's on-disk process state.
core/termscreen
Package termscreen renders a terminal program's output onto a grid of characters, so text a TUI paints by moving the cursor can be read back as it appears on screen.
Package termscreen renders a terminal program's output onto a grid of characters, so text a TUI paints by moving the cursor can be read back as it appears on screen.
core/trace
Package trace provides opt-in timing spans and process-spawn counters for the sync pipeline.
Package trace provides opt-in timing spans and process-spawn counters for the sync pipeline.
core/updater
Package updater downloads and verifies official Bonsai releases.
Package updater downloads and verifies official Bonsai releases.
daemon/client
Package client talks to a repo's bonsai daemon over its Unix socket.
Package client talks to a repo's bonsai daemon over its Unix socket.
daemon/gitbridge
Package gitbridge is the allowlisted, outbound-only Git bridge.
Package gitbridge is the allowlisted, outbound-only Git bridge.
daemon/protocol
Package protocol defines the wire format between bonsai clients (TUI, CLI) and the per-repo daemon.
Package protocol defines the wire format between bonsai clients (TUI, CLI) and the per-repo daemon.
daemon/server
Package server implements the per-repo bonsai daemon.
Package server implements the per-repo bonsai daemon.
daemon/watcher
Package watcher accelerates reconciliation with filesystem notifications.
Package watcher accelerates reconciliation with filesystem notifications.
git
Package git defines Bonsai's transport-independent Git domain.
Package git defines Bonsai's transport-independent Git domain.
git/github/app
Package app implements GitHub's domain API without a gh executable.
Package app implements GitHub's domain API without a gh executable.
git/github/ghcli
Compatibility names preserve CLI/TUI behavior while the daemon and web use the context-aware domain interfaces.
Compatibility names preserve CLI/TUI behavior while the daemon and web use the context-aware domain interfaces.
git/local
Compatibility names preserve CLI/TUI behavior while the daemon and web use the context-aware domain interfaces.
Compatibility names preserve CLI/TUI behavior while the daemon and web use the context-aware domain interfaces.
livehooks
Package livehooks keeps one Bonsai repository webhook per live-updates repository pointed at the current tunnel: find it (stored ID, else the ?bonsai=<install-id> marker), create it when missing, re-point it when the public URL or secret changes, and read its health from GitHub's last delivery.
Package livehooks keeps one Bonsai repository webhook per live-updates repository pointed at the current tunnel: find it (stored ID, else the ?bonsai=<install-id> marker), create it when missing, re-point it when the public URL or secret changes, and read its health from GitHub's last delivery.
providers/codex
Package codex runs the OpenAI Codex CLI.
Package codex runs the OpenAI Codex CLI.
server/runtime
Package runtime keeps a narrow compatibility wrapper for callers that used the original local API entrypoint.
Package runtime keeps a narrow compatibility wrapper for callers that used the original local API entrypoint.
server/webhooks
Package webhooks verifies and durably queues GitHub deliveries before replying.
Package webhooks verifies and durably queues GitHub deliveries before replying.
server/webui
Package webui serves the web UI bundle from the local API, on the API's own origin.
Package webui serves the web UI bundle from the local API, on the API's own origin.
storage/git
Package git provides a durable metadata store.
Package git provides a durable metadata store.
ui
Package ui is the Bubble Tea presentation layer.
Package ui is the Bubble Tea presentation layer.
ui/agentsapi
Package agentsapi is the contract between the TUI and the agent backend.
Package agentsapi is the contract between the TUI and the agent backend.
ui/agentsapi/fake
Package fake is an in-memory agentsapi backend for TUI tests.
Package fake is an in-memory agentsapi backend for TUI tests.
ui/components/accounts
Package accounts renders profile, launch and usage views inside the Agents tab.
Package accounts renders profile, launch and usage views inside the Agents tab.
ui/components/launchform
Package launchform is the generic editor for provider-declared fields (agents.LaunchField): the Defaults tab of the accounts modal edits profile fields with it and the new-agent dialog edits launch fields.
Package launchform is the generic editor for provider-declared fields (agents.LaunchField): the Defaults tab of the accounts modal edits profile fields with it and the new-agent dialog edits launch fields.
ui/components/modals
Package modals provides a single reusable centered overlay that operates in one of several modes: free text input, static selection, live fuzzy search, or yes/no confirmation.
Package modals provides a single reusable centered overlay that operates in one of several modes: free text input, static selection, live fuzzy search, or yes/no confirmation.
ui/components/prefs
Package prefs is the in-app preferences overlay: theme preset picker with live apply, a full keybinding editor, and behavioral defaults.
Package prefs is the in-app preferences overlay: theme preset picker with live apply, a full keybinding editor, and behavioral defaults.
ui/components/terminal
Package terminal is the right-pane viewport showing process output or git log.
Package terminal is the right-pane viewport showing process output or git log.
ui/components/usagepane
Package usagepane renders meter strips below the worktree list.
Package usagepane renders meter strips below the worktree list.
ui/components/vterm
Package vterm renders a raw agent PTY byte stream into a fixed rectangle using the charmbracelet/x/vt emulator.
Package vterm renders a raw agent PTY byte stream into a fixed rectangle using the charmbracelet/x/vt emulator.
ui/components/worktreelist
Package worktreelist is the left-pane list of git worktrees.
Package worktreelist is the left-pane list of git worktrees.
ui/theme
Package theme centralizes the UI color palette so the whole TUI can be restyled from one place, driven by config (a preset plus per-role overrides).
Package theme centralizes the UI color palette so the whole TUI can be restyled from one place, driven by config (a preset plus per-role overrides).
ui/usagestore
Package usagestore is the one place the TUI fetches and holds account usage.
Package usagestore is the one place the TUI fetches and holds account usage.
ui/websetup
Package websetup is the `bonsai web setup` terminal UI: the first-run wizard and the edit-mode dashboard.
Package websetup is the `bonsai web setup` terminal UI: the first-run wizard and the edit-mode dashboard.
version
Package version holds metadata injected by GoReleaser.
Package version holds metadata injected by GoReleaser.
websetup
Package websetup is the model behind `bonsai web setup`: what the user is choosing (a Draft), what applying it changes (a Plan) and the words used to explain each choice.
Package websetup is the model behind `bonsai web setup`: what the user is choosing (a Draft), what applying it changes (a Plan) and the words used to explain each choice.
websetup/checks
Package checks inspects what `bonsai web` needs on this computer: git, the GitHub CLI and its login, project folders, the API port and the tunnel tools that live updates will use.
Package checks inspects what `bonsai web` needs on this computer: git, the GitHub CLI and its login, project folders, the API port and the tunnel tools that live updates will use.
webtunnel
Package webtunnel describes the tunnels `bonsai web` can run for live updates: the argv for each preset, how its public URL is learned, and the argv validation that keeps the tunnel pointed at the webhook receiver and nothing else.
Package webtunnel describes the tunnels `bonsai web` can run for live updates: the argv for each preset, how its public URL is learned, and the argv validation that keeps the tunnel pointed at the webhook receiver and nothing else.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL