bonsai

command module
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2026 License: MIT Imports: 10 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

A terminal UI for growing and pruning git worktrees.

Manage worktrees, sync files, run scripts, and drive git β€” without leaving your keyboard.


Why

Juggling git worktrees by hand is tedious: creating them, copying over untracked files like .env, running dev servers per branch, tracking which one has an open PR, and cleaning them up. bonsai puts all of that in one fast TUI β€” and every feature is also a plain CLI command you can script.

Features

  • 🌳 Worktree list with ahead/behind arrows (↑N ↓M), #PR badges auto-detected via gh, dirty change counts (●N ?M), CI dots, and 6 sort modes.
  • πŸ” Inspector tab per worktree: working-tree status, last commit, diff-vs-base summary, disk usage, and stash count.
  • 🚦 Checks tab with the branch's GitHub Actions runs, and a full PR tab (detail, reviews, merge/approve/close).
  • πŸ“„ Diff tab: files changed vs base with per-file diffs.
  • 🌐 Live dev-server URLs detected in process output (http://localhost:… shown next to each process).
  • πŸ“‹ Yank menu (y): copy the worktree path, branch name, or PR URL to your clipboard.
  • ✨ Create worktrees from a new branch, an existing branch, or a GitHub PR.
  • πŸ“‹ Copy files from main into a worktree via fuzzy finder β€” ranked by how often you copy them.
  • πŸ”§ Run package scripts and custom aliases as background processes β€” many per worktree, switchable.
  • πŸͺ Lifecycle hooks (on_worktree_create / on_worktree_delete) with {variable} and $BONSAI_* substitution.
  • πŸ”€ Git ops inline: pull, push, commit, rebase (drops to a real shell for conflict resolution).
  • πŸ—‘οΈ Prune with an optional merge-PR-first step and a clear preview of exactly what will happen.
  • βš™οΈ Edit .bonsai.yaml from the command palette β€” every setting, with descriptions and examples, applied live.
  • πŸ–₯️ Everything works from the CLI too β€” bonsai create, bonsai copy, bonsai x <alias>, and more.

Install

./install.sh

Downloads the latest GitHub Release, verifies its SHA256 checksum, and installs it to /usr/local/bin (or ~/.local/bin if that isn't writable). Override the location with PREFIX:

PREFIX="$HOME/.local" ./install.sh

On Windows, run install.bat (which calls install.ps1), or run ./install.ps1 from PowerShell. It installs to %USERPROFILE%\go\bin by default, honoring PREFIX, GOBIN, or GOPATH when set, and installs the bcd.bat helper. Neither installer requires Go. Linux/macOS need curl, tar, and either sha256sum or shasum; Windows uses PowerShell 5.1 or later.

With Go
go install github.com/Tiago-0liveira/bonsai@latest
From source
go build -o bonsai .

Versions and updates

bonsai -v                  # also --version or version
bonsai -u                  # also --update or update
bonsai update --check      # check the latest stable GitHub Release
bonsai update              # prompt to verify and install it

These commands work outside a Git repository. Updates support Linux, macOS, and Windows on amd64 and arm64. The executable's directory must be writable; symlinked installations update the resolved executable. Restart Bonsai after updating. On Windows the old executable remains as bonsai.exe.old until the next update. A crashed updater may leave a .update-lock beside the executable; remove it only after confirming no updater is running.

Release builds include their version, commit, and build date. Source builds report dev and do not replace themselves or display automatic update prompts. Periodic update checks run in the background (once every 24 hours) with a short timeout and cache the result in the OS user cache under bonsai/update_state.json. Interactive sessions prompt before installing, while non-interactive environments (like CI or piped commands) log a single-line notice. Network failures never prevent startup; explicit bonsai --update bypasses the cache.

CI and releases

Pull requests targeting main run formatting, module checks, vet, builds and tests on Linux/macOS/Windows, Linux race tests, and a GoReleaser snapshot build. The CI passes aggregate must pass before merging into protected main.

A merged PR triggers a queued release, defaulting to the next patch version. Use at most one label: release:patch, release:minor, release:major, or release:none. With no existing stable tags, the first patch is v0.0.1. Release jobs check out the exact merge commit, create a tag, build all six platform archives and checksums.txt, then publish the completed draft. They run only for merged PRs, including fork PRs; direct pushes and manual tags do not trigger releases. A failed run can be rerun: it reuses that merge's tag and rebuilds an incomplete draft. Published releases are left intact.

goreleaser release --snapshot --clean  # local release dry-run

Requirements

  • Go 1.26+ (to build)
  • git on your PATH
  • gh (optional) β€” only needed for PR badges, creating worktrees from PRs, and merge-on-prune. Everything else works without it.

Quick start

cd your-repo
bonsai

Press n to create a worktree, enter to drop into a shell in the selected one, ? for the full keymap, q to quit.

Keybindings

Key Action
tab Cycle focus between panes
shift+tab Cycle the right-pane tabs
enter Open a shell in the selected worktree
e Open your editor ($VISUAL/$EDITOR) in the selected worktree
n New worktree (new branch / existing branch / PR)
ctrl+n Create a PR from the selected worktree
v / l / d / P Processes / Git Log / Diff / PR tab
i Inspector tab (status, last commit, diff, disk, stashes)
b Checks tab (GitHub Actions runs for the branch)
o Cycle list sort (name / ahead / behind / PR / activity / dirty)
/ Filter the worktree list
c Copy a file from main into the worktree (fuzzy)
y Yank: copy path / branch / PR URL to the clipboard
s Run a package script (npm / pnpm / yarn / bun / cargo / make)
p Aliases menu (run one, or οΌ‹ new alias)
ctrl+p Git pull
ctrl+u Git push
f Git fetch (all remotes)
C Git commit (stages all)
r Git rebase onto a chosen branch
u Update branch from base (rebase or merge)
x Prune the worktree (with optional PR merge)
X Prune all merged worktrees
R Refresh worktrees, metrics, and PRs
, Preferences (theme, keybindings, defaults)
? Keybindings reference (searchable)
q / ctrl+c Quit

CLI

Any argument runs a subcommand instead of the TUI:

bonsai list                     # list worktrees (branch, path)
bonsai create <branch>          # new worktree on a new branch β†’ prints its path
bonsai create --existing <br>   # new worktree on an existing branch
bonsai create --pr <number>     # new worktree checked out from a GitHub PR
bonsai copy <file> <worktree>   # copy a main-repo file into a worktree
bonsai path <branch|main>       # print a worktree's path (for cd)
bonsai x <alias> [worktree]     # run an alias (default: current directory)
bonsai x --list                 # list available aliases
bonsai alias add <name> <cmd…>  # add a user alias
bonsai alias list               # list aliases
bonsai alias rm <name>          # remove a user alias
bonsai shell-init               # print a shell 'bcd' cd helper
bonsai version (-v)             # print version and build info
bonsai update (-u)              # check or install latest release
bonsai help                     # full usage
Jump into a worktree from your shell

A binary can't change its parent shell's directory, so bonsai ships a helper:

eval "$(bonsai shell-init)"     # add to ~/.zshrc or ~/.bashrc
bcd feat/login                  # cd into that worktree
bcd                             # cd back to main

Configuration

bonsai reads .bonsai.yaml from your repo root. See the annotated example β€” it documents every field. In short:

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"
  on_worktree_delete:
    - "echo 'removing {worktree_name}'"

aliases:
  - name: dev
    command: "npm run dev"
Hook & alias variables

Use {name} inside hook commands and alias commands. Each is also exported to hooks as $BONSAI_<NAME> (uppercased).

Variable Value
{new_worktree} / {worktree} Absolute path of the worktree
{worktree_name} Worktree directory name (e.g. repo-feat-login)
{main} / {main_branch_path} Absolute path of the main worktree
{branch} Branch name
{base_branch} Base branch from upstream (origin/main β†’ main)
{repo} Repository directory name
{pr_number} Connected PR number, or empty

User aliases you add in-app or via bonsai alias add persist to ~/.config/bonsai/state.json (which also tracks file-copy frequency for fuzzy ranking). Aliases in .bonsai.yaml are read-only project defaults.

How prune works

x (prune) is local teardown and is destructive. The confirmation modal previews the exact pipeline, e.g.:

merge PR #20 to main β†’ run on_worktree_delete β†’ delete worktree β†’ delete branch
  • The merge step is off by default β€” toggle it with space. It only appears for branches with a connected PR and runs gh pr merge.
  • delete worktree uses --force; delete branch uses -D. Unpushed commits and uncommitted changes are lost.
  • It never touches the remote unless you explicitly enable merge.

Architecture

Strict split between presentation and core:

  • internal/ui β€” all Bubble Tea (model / update / view / components). No os/exec, file I/O, or raw git.
  • internal/core β€” git, gh, config, exec, fs, pkgmgr, notify, clipboard. Plain Go types and errors, independently testable.
  • internal/cli β€” the non-interactive subcommands, sharing the same core.

Built with Bubble Tea, Lip Gloss, Viper, and sahilm/fuzzy.

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
cli
Package cli implements bonsai's non-interactive subcommands.
Package cli implements bonsai's non-interactive subcommands.
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/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 detects a project's package manager / build tool and exposes its runnable scripts or targets.
Package pkgmgr detects a project's package manager / build tool and exposes its runnable scripts or targets.
core/procstore
Package procstore owns bonsai's on-disk process state.
Package procstore owns bonsai's on-disk process state.
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/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.
ui
Package ui is the Bubble Tea presentation layer.
Package ui is the Bubble Tea presentation layer.
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/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).
version
Package version holds metadata injected by GoReleaser.
Package version holds metadata injected by GoReleaser.

Jump to

Keyboard shortcuts

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