CLI tool that enhances git worktree and jj workspace with automated setup and utilities.
Supported VCS:
- Git -
git worktreeoperations - jj (Jujutsu) -
jj workspaceoperations (including colocated repositories)
Note: This tool is under active development. Commands and configuration format may change in future versions.
Every time you create a git worktree or jj workspace, you end up doing the same manual setup:
- Creating symlinks to config files like
.env.local - Copying
.env.exampleto.env - Creating cache directories
kabu reads .kabu/config.yaml (or .kabu/config.toml) from your repository and runs these tasks automatically when creating a worktree or workspace. It automatically detects whether you're in a git repository or jj repository and uses the appropriate commands.
cargo install kabuSee INSTALL.md for other installation methods (mise, Nix, GitHub Releases).
- Create
.kabu/config.yaml(or.kabu/config.toml): In your repository root, create a configuration file to define your worktree setup. Both YAML and TOML formats are supported (YAML takes priority if both exist).# .kabu/config.yaml example mkdir: - path: build description: Build output directory link: - source: .env.local description: Local environment variables
- Add a worktree: Use
kabu addto create a new worktree with the defined setup.This will create a new worktree atkabu add ../my-feature-worktree
../my-feature-worktreeand apply themkdirandlinkoperations defined in.kabu/config.yaml.
For comprehensive details on all commands, options, and configuration, please refer to the CLI's built-in help (kabu --help and kabu <subcommand> --help) and man pages (kabu man).
kabu automatically detects the version control system in use:
| VCS | Detection | Commands Used |
|---|---|---|
| Git | .git directory |
git worktree add/remove/list |
| jj (Jujutsu) | .jj directory |
jj workspace add/forget/list |
| jj colocated | Both .git and .jj |
jj workspace commands |
All kabu commands work the same regardless of the underlying VCS. The tool transparently translates operations to the appropriate VCS commands.
jj-specific notes:
- jj "workspaces" serve a similar purpose to git "worktrees" (multiple working directories for the same repository)
- The "default" workspace in jj is treated as the main workspace
- Colocated repositories (jj on top of git) are fully supported
# Create a worktree/workspace with setup
kabu add ../feature-branch
# Create a new branch and worktree (git)
# or new workspace with bookmark (jj)
kabu add -b new-feature ../new-feature
# Interactive mode - select branch and path
kabu add --interactive
# Preview without executing
kabu add --dry-run ../test# List all worktrees/workspaces with detailed information
kabu list
kabu ls # Short alias
# Show header row with column names
kabu list --header
# List only paths (useful for scripting)
kabu list --path-only
kabu ls -pStatus Symbols:
*= Uncommitted changes (modified, deleted, or untracked files)
jj-specific columns:
- Shows workspace name and change ID instead of branch name when applicable
- Displays bookmark name if associated with the workspace
# Remove a worktree/workspace with safety checks
kabu remove ../feature-branch
# Shorthand alias
kabu rm ../feature-branch
# Remove current worktree/workspace (the one you're in)
kabu remove --current
# Interactive mode - select worktrees/workspaces to remove
# Shows [current] marker for the one you're in
kabu remove --interactive
# Preview what would be removed
kabu remove --dry-run ../feature-branch
# Force removal (skip safety checks and confirmation)
kabu remove --force ../feature-branchSafety Checks:
By default, kabu remove warns about:
- Modified files
- Deleted files
- Untracked files
- Unpushed commits (git) / commits not on remote bookmarks (jj)
Use --force to bypass all checks and confirmation prompts.
# Interactively select and cd to a worktree
kabu cd
# Or get worktree path for scripting (works without shell integration)
cd "$(kabu path)"kabu cd: Requires shell integration (kabu init - see Shell Integration section). Displays an interactive fuzzy finder (on Unix) or selection menu (on Windows) and automatically changes to the selected worktree. If shell integration is not enabled, the command will display a helpful error message with setup instructions.
kabu path: Prints the selected worktree path to stdout. Works without shell integration. Useful for scripting or as a fallback.
# Show config format help
kabu config
# Create a new repo config
kabu config new
# Create a new global config
kabu config new --global
# Validate configuration
kabu config validateHooks allow you to run custom commands before/after worktree operations:
# Review and trust hooks in .kabu/config.yaml
kabu trust
# Show hooks without trusting
kabu trust --show
# Check trust status (exit 0 if trusted, 1 if untrusted)
kabu trust --check
# Revoke trust
kabu untrust
# List all trusted repositories
kabu untrust --listSecurity: For security, hooks require explicit trust via kabu trust before execution. See Hooks Configuration below.
Optional feature. Shell integration is not required for basic kabu functionality (add, remove, list, path, etc.). It only adds quality-of-life improvements.
To enable shell completions and automatic hook trust warnings, add the following to your shell configuration:
Bash (~/.bashrc):
eval "$(kabu init bash)"Zsh (~/.zshrc):
eval "$(kabu init zsh)"Fish (~/.config/fish/config.fish):
kabu init fish | sourcePowerShell (profile):
Invoke-Expression (& kabu init powershell | Out-String)Elvish (~/.config/elvish/rc.elv):
eval (kabu init elvish | slurp)Shell integration provides:
- Shell completions for commands and options
kabu cdcommand to interactively change directory to selected worktree (only available with shell integration)- Auto cd after add - Automatically
cdto newly created worktree (configurable viaauto_cd.after_add) - Auto cd after remove - Automatically
cdwhen current worktree is removed (configurable viaauto_cd.after_remove) - Automatic trust warnings when entering directories with untrusted hooks
Create .kabu/config.yaml or .kabu/config.toml in your repository root. Both YAML and TOML formats are supported. If both files exist, YAML takes priority. See examples/ for various use cases.
JSON Schema: The configuration format is validated against a JSON Schema located at schema/kabu.schema.json. This schema can be used with editors that support YAML schema validation for autocomplete and validation.
Editor Integration: To enable schema validation in VS Code or other editors using yaml-language-server, add this comment at the top of your .kabu/config.yaml:
# yaml-language-server: $schema=https://raw.githubusercontent.com/h-michael/kabu/main/schema/kabu.schema.json
on_conflict: backupon_conflict: backup # abort, skip, overwrite, backup
mkdir:
- path: build
description: Build output directory
link:
- source: .env.local
description: Local environment
copy:
- source: .env.example
target: .env
description: Environment templateOperations:
mkdir- Create directorieslink- Create symbolic linkscopy- Copy files or directories
Examples: examples/basic.yaml
Configure default worktree path with template variables:
worktree:
path_template: ../worktrees/{branch}Template variables:
{{branch}}or{{ branch }}- Branch name (e.g.,feature/foo){{repository}}or{{ repository }}- Repository name (e.g.,myrepo)
Examples: examples/worktree-path.yaml
Use glob patterns in link operations to match multiple files:
link:
- source: fixtures/*
ignore_tracked: true
description: Link untracked test fixturesSupported patterns:
*- matches any characters?- matches a single character[...]- matches character ranges**- matches directories recursively
Options:
ignore_tracked: true- Skip git-tracked files (useful for linking only untracked files like local configs or test data)
Examples: examples/glob-patterns.yaml
Execute custom commands before/after worktree operations. Requires explicit trust via kabu trust.
hooks:
post_add:
- command: npm install
description: Install dependencies
- command: mise install
description: Install mise toolsHook types:
pre_add- Before worktree creationpost_add- After worktree setuppre_remove- Before worktree removalpost_remove- After worktree removal
Template variables:
{{worktree_path}}- Full path to worktree{{worktree_name}}- Worktree directory name{{branch}}- Branch name{{repo_root}}- Repository root
Environment variables:
Hooks also receive the following environment variables, which contain raw (unescaped) values:
KABU_WORKTREE_PATH- Full path to worktreeKABU_WORKTREE_NAME- Worktree directory nameKABU_BRANCH- Branch name (empty if detached)KABU_REPO_ROOT- Repository rootKABU_VCS_TYPE- VCS type ("git" or "jj")KABU_CHANGE_ID- jj change ID (empty for git)KABU_COMMIT_ID- jj commit ID (empty for git)
Use environment variables when you need raw values without shell escaping (e.g., for tmux session management):
hooks:
post_add:
- command: tmux new-session -d -s "kabu-$KABU_WORKTREE_NAME" -c "$KABU_WORKTREE_PATH"
description: Create tmux session
post_remove:
- command: tmux kill-session -t "kabu-$KABU_WORKTREE_NAME" 2>/dev/null || true
description: Remove tmux sessionSecurity:
- Template variables are shell-escaped automatically (POSIX sh on Unix, PowerShell on Windows)
- Environment variables contain raw values and follow standard shell expansion rules
- Always quote environment variable expansions in hook commands (
"$KABU_*","$env:KABU_*","%KABU_*%") to avoid shell injection from untrusted values - Must trust hooks via
kabu trustbefore execution - Changes require re-trusting
Windows shells:
- Default shell auto-detect order:
pwsh→powershell→bash(Git Bash) →cmd - Override with
--hook-shellorKABUHOOK_SHELL(pwsh,powershell,bash,cmd,wsl) --hook-shelltakes precedence overKABUHOOK_SHELLwslis only used when explicitly set, because Windows paths may not map to WSL- Environment variable syntax differs by shell:
$env:KABU_WORKTREE_NAME(PowerShell),%KABU_WORKTREE_NAME%(cmd),$KABU_WORKTREE_NAME(bash/wsl)
Examples: examples/hooks-basic.yaml, examples/nodejs-project.yaml
| Operation | Description |
|---|---|
mkdir |
Create directories |
link |
Create symbolic links |
copy |
Copy files or directories |
hooks.* |
Run custom commands (requires trust) |
When a target file already exists, kabu can:
abort- Stop immediately (default in non-interactive mode)skip- Skip the file and continueoverwrite- Replace the existing filebackup- Rename existing file to.bakand proceed
Set globally with on_conflict, per-operation, or via --on-conflict flag.
Automatically change directory after worktree operations. Requires shell integration.
auto_cd:
after_add: true # cd to new worktree after creation (default: true)
after_remove: main # cd after removing current worktree (default: main)after_remove options:
main- cd to main worktreeselect- Show interactive selection
| Option | Description |
|---|---|
--interactive, -i |
Select branch and path interactively |
--dry-run |
Preview actions without executing |
--quiet, -q |
Suppress output |
--no-setup |
Skip setup (run git worktree add only) |
--hook-shell <SHELL> |
Windows only: choose hook shell (pwsh, powershell, bash, cmd, wsl) |
Passes through git worktree options:
kabu add [OPTIONS] [PATH] [COMMITISH]
kabu Options:
-i, --interactive Interactive mode
--on-conflict <MODE> abort, skip, overwrite, backup
--dry-run Preview without executing
--no-setup Skip .kabu/config.yaml setup
--hook-shell <SHELL> Windows only: hook shell
git worktree Options:
-b <name> Create new branch
-B <name> Create or reset branch
-f, --force Force creation
-d, --detach Detach HEAD
--no-checkout Do not checkout after creation
--lock Lock worktree after creation
--track / --no-track Branch tracking
--guess-remote Guess remote for tracking
--no-guess-remote Do not guess remote
Shared:
-q, --quiet Suppress output
Remove worktrees with safety checks (alias: kabu rm):
kabu remove [OPTIONS] [PATHS]...
kabu rm [OPTIONS] [PATHS]...
kabu Options:
-i, --interactive Select worktrees interactively
-c, --current Remove current worktree
--dry-run Preview without executing
--hook-shell <SHELL> Windows only: hook shell
git worktree Options:
-f, --force Force removal (skip all checks and prompts)
Shared:
-q, --quiet Suppress output
Generate completion scripts for your shell:
# Bash
kabu completions bash > ~/.local/share/bash-completion/completions/kabu
# Zsh (add ~/.zfunc to your fpath)
kabu completions zsh > ~/.zfunc/_kabu
# Fish
kabu completions fish > ~/.config/fish/completions/kabu.fish
# PowerShell (add to your profile)
kabu completions powershell >> $PROFILE
# PowerShell (or save to a file and dot-source it)
kabu completions powershell > _kabu.ps1
# Then add to $PROFILE: . /path/to/_kabu.ps1Supported shells: bash, elvish, fish, powershell, zsh
To find your PowerShell profile path, run echo $PROFILE. If the profile file doesn't exist, create it with New-Item -Path $PROFILE -ItemType File -Force.
Generate and install the man page:
# Install to system
sudo kabu man > /usr/local/share/man/man1/kabu.1
# View without installing
kabu man | man -l -Hooks are supported on Unix-like systems (Linux, macOS) and Windows.
On Windows, hooks run via an auto-detected shell (pwsh, powershell, Git Bash,
or cmd). Use KABUHOOK_SHELL to force a specific shell if needed.
On Windows, creating symbolic links requires one of the following:
- Windows 11: No special permissions required
- Windows 10 Creators Update (1703) or later: Enable Developer Mode in Settings > Update & Security > For Developers
- Older Windows versions: Run as administrator
Without these permissions, [[link]] operations will fail with a permission error.
For more information, see:
MIT OR Apache-2.0