Worktrunk
Git worktree lifecycle automation. Built for running multiple AI coding agents without conflicts.
Git worktrees let multiple agents work on one repo without collidingβeach gets a separate directory sharing history. But creating worktrees, tracking paths, and cleaning up afterward is manual. Worktrunk automates the lifecycle: create, switch, clean upβyour shell stays put.
Running ten agents on different features? wt switch --create feature-a, wt switch --create feature-b, and they're isolated. Agent finishes? wt remove feature-a cleans up automatically. No path juggling, no stale directories.
What It Does
Automates the full lifecycle: create worktree, work, merge back, remove worktree.
# Shell now in ../repo.fix-auth/
# Agent works, makes changes, then:
)
)
|
)
)
&
# Shell back in main
Shell integration means directories change automatically. Merge handles staging, committing, merging, pushing, cleanup. One command.
Installation
Three Commands
Create workspace:
Finish and merge:
See active worktrees:
Automation Features
LLM commits - AI generates merge commits from diff and history:
Project hooks - Auto-run tests, install deps:
# .config/wt.toml
[]
= "npm test"
Shell integration - Bash, Zsh, Fish, Nushell, PowerShell, Elvish, Xonsh, Oil.
Design Philosophy
Worktrunk is opinionated. The choices optimize for AI agent workflows:
- Merge does everything - Staging, committing all changes, merging, pushing, cleanup in one command
- Squash by default - Linear history, configurable
- Automatic shell navigation - No manual
cdcommands - Fail-fast hooks - Tests block bad merges
These trade manual control for automation. For fine-grained control, use git worktree directly.
All Commands
wt switch [branch]- Switch to existing worktreewt switch --create [branch]- Create and switch (supports--base=@to branch from current HEAD)wt remove [branch]- Remove worktree (use@for current)wt merge [target]- Merge, push, cleanupwt list- Show all worktreeswt config- Manage configuration
Shortcut: Use @ to refer to your current HEAD (following git's convention):
See wt --help for details.
The Status column shows git repository state using compact symbols. Symbol order indicates priority: conflicts (blocking) β worktree state β git operations β branch divergence β working tree changes.
Symbol order: = β‘β
β»β ββ β ββ β‘β£ ?!+Β»β
| Symbol | Meaning | Category | Dimmed? |
|---|---|---|---|
Β· |
Branch without worktree | N/A | No |
= |
Conflicts with main | Blocking | No |
β‘ |
Working tree matches main (identical to main branch, regardless of commit history) | Worktree state | Yes |
β
|
No commits (no commits ahead AND no uncommitted changes) | Worktree state | Yes |
β» |
Rebase in progress | Git operation | No |
β |
Merge in progress | Git operation | No |
β |
Bare worktree (no working directory) | Worktree attribute | No |
β |
Locked worktree | Worktree attribute | No |
β |
Prunable worktree | Worktree attribute | No |
β |
Commits ahead of main | Branch divergence | No |
β |
Commits behind main | Branch divergence | No |
β‘ |
Commits ahead of remote | Remote divergence | No |
β£ |
Commits behind remote | Remote divergence | No |
? |
Untracked files | Working tree | No |
! |
Modified files (unstaged) | Working tree | No |
+ |
Staged files | Working tree | No |
Β» |
Renamed files | Working tree | No |
β |
Deleted files | Working tree | No |
Symbols combine to show complete state (e.g., β‘β! means matches main, behind main, and has unstaged changes).
Dimming logic: Dimmed rows indicate worktrees with no marginal information beyond main (no unique work). Lines dim when they have either β‘ (matches main) OR β
(no commits). Both conditions use OR logic: either is sufficient to dim. This focuses attention on worktrees containing work.
Branch-only entries: Branches without worktrees show Β· in the Status column, indicating git status is not applicable (no working directory to check).
Configuration
Global config at ~/.config/worktrunk/config.toml:
= "../{main-worktree}.{branch}"
[]
= "llm"
= ["-m", "claude-haiku-4-5-20251001"]
Project config at .config/wt.toml in the repository root (see Project Automation above).
Worktree path defaults: ../repo.branch/ (siblings to main repo). Variables: {main-worktree}, {branch}, {repo}.
Advanced Features
LLM-Powered Commit Messages
During merge operations, worktrunk can generate commit messages using an LLM. The LLM analyzes the staged diff and recent commit history to write messages matching the project's style.
# Merge with LLM-generated commit message (squashes by default)
# Merge without squashing commits
# Merge to a specific target branch
Set up LLM integration: wt config help shows the setup guide, wt config init creates example config.
Edit ~/.config/worktrunk/config.toml:
[]
= "llm" # or "claude", "gpt", etc.
= ["-m", "claude-haiku-4-5-20251001"]
If the LLM is unavailable or fails, worktrunk falls back to a deterministic message.
Worktrunk uses minijinja templates for commit message prompts, giving you full control over what the LLM sees.
Inline template for normal commits:
[]
= "llm"
= ["-s"]
= """
Generate a commit message for {{ repo | upper }}.
Branch: {{ branch }}
{%- if recent_commits %}
Recent commit style ({{ recent_commits | length }} commits):
{%- for commit in recent_commits %}
{{ loop.index }}. {{ commit }}
{%- endfor %}
{%- endif %}
Changes to commit:
{{ git_diff }}
Requirements:
- Follow the style of recent commits above
- First line under 50 chars
- Focus on WHY, not HOW
"""
Inline template for squash commits:
[]
= "llm"
= """
Squashing {{ commits | length }} commit(s) from {{ branch }} to {{ target_branch }}.
{% if commits | length > 1 -%}
Commits being combined:
{%- for c in commits %}
{{ loop.index }}/{{ loop.length }}: {{ c }}
{%- endfor %}
{%- else -%}
Single commit: {{ commits[0] }}
{%- endif %}
Generate one cohesive commit message that captures the overall change.
Use conventional commit format (feat/fix/docs/refactor).
"""
External template files:
[]
= "claude"
= "~/.config/worktrunk/commit-template.jinja"
= "~/.config/worktrunk/squash-template.jinja"
Available template variables:
Normal commits:
{{ git_diff }}- Staged changes{{ branch }}- Current branch name{{ recent_commits }}- Array of recent commit messages (for style matching){{ repo }}- Repository name
Squash commits:
{{ commits }}- Array of commit messages being squashed{{ target_branch }}- Branch being merged into (e.g., "main"){{ branch }}- Current branch name{{ repo }}- Repository name
See the minijinja template documentation for complete syntax reference (filters, conditionals, loops, whitespace control, etc.).
Project Automation
Automate common tasks by creating .config/wt.toml in your repository root. Run tests before merging, install dependencies when creating worktrees, start dev servers automatically.
# Install deps when creating a worktree
[]
= "npm install --frozen-lockfile"
# Start dev server automatically
[]
= "npm run dev"
# Run tests before merging
[]
= "npm test"
= "npm run lint"
| Hook | When It Runs | Execution | Failure Behavior |
|---|---|---|---|
| post-create-command | After git worktree add completes |
Sequential, blocking | Logs warning, continues with remaining commands |
| post-start-command | After post-create completes | Parallel, non-blocking (background processes) | Logs warning, doesn't affect switch result |
| pre-commit-command | Before committing changes during wt merge (both squash and no-squash modes) |
Sequential, blocking, fail-fast | Terminates merge immediately |
| pre-merge-command | After rebase completes during wt merge (validates rebased state before push) |
Sequential, blocking, fail-fast | Terminates merge immediately |
| post-merge-command | After successful merge and push to target branch, before cleanup | Sequential, blocking | Logs warning, continues with remaining commands |
Template variables: {repo}, {branch}, {worktree}, {repo_root}, {target}
Skipping hooks: wt switch --no-verify or wt merge --no-verify
Security: Commands require approval on first run. Use --force to bypass.
Example output with hooks:
)
)
)
)
)
; ; ; ; ;
)
) )
|
|
|
)
)
&
)
)
Custom Worktree Status
Add emoji status markers to worktrees that appear in wt list. Perfect for tracking work-in-progress states, CI status, or team coordination.
Set status manually:
# Set an emoji status for a branch (works everywhere)
# Clear the status
Status appears in the Status column:
Branch Status Working Β± Main β Path
feature-a β‘β!π§ β2 ./feature-a/
feature-b β!β
+2 -1 β1 ./feature-b/
feature-c π€ ./feature-c/
The custom emoji appears directly after the git status symbols.
Claude Code can automatically set/clear emoji status when coding sessions start and end. This shows which branches have active AI sessions.
Add to ~/.claude/settings.json:
Now when you use Claude:
- Sets status to
π€for the current branch when you submit a prompt - Clears the status when the session stops
Status from other terminal:
How it works:
- Status is stored as
worktrunk.status.<branch>in.git/config - Each branch can have its own status emoji
- The hooks automatically detect the current branch and set/clear its status
- Status is shared across all worktrees on the same branch (by design)
- Works with any git repository, no special configuration needed
For true per-worktree isolation (different status for multiple worktrees on the same branch), use worktree-specific config:
One-time setup (enables per-worktree config for the repo):
Set status from within a worktree:
# From within the worktree
# Clear status
Claude Code hooks for per-worktree:
Priority: Worktree-specific config takes precedence over branch-keyed config when both exist.
Worktree Paths
By default, worktrees live as siblings to the main repo:
myapp/ # primary worktree
myapp.feature-x/ # secondary worktree
myapp.bugfix-y/ # secondary worktree
Customize the pattern in ~/.config/worktrunk/config.toml:
# Inside the repo (keeps everything contained)
= ".worktrees/{branch}"
# Shared directory with multiple repos
= "../worktrees/{main-worktree}/{branch}"
Shell Integration Details
Worktrunk automatically configures your shell:
This adds shell integration to your config files (supports Bash, Zsh, Fish, Nushell, PowerShell, Elvish, Xonsh, Oil). The integration enables wt switch to change directories and wt remove to return to the previous location.
Add one line to your shell config:
Bash (~/.bashrc):
Fish (~/.config/fish/config.fish):
wt init fish | source
Zsh (~/.zshrc):
Nushell (~/.config/nushell/env.nu):
wt init nushell | save -f ~/.cache/wt-init.nu
Then add to ~/.config/nushell/config.nu:
source ~/.cache/wt-init.nu
PowerShell (profile):
wt init powershell | Out-String | Invoke-Expression
Elvish (~/.config/elvish/rc.elv):
eval (wt init elvish | slurp)
Xonsh (~/.xonshrc):
Oil Shell (~/.config/oil/oshrc):
Status
Worktrunk is in active development. The core features are stable and ready for use. While the project is pre-1.0, the CLI interface and major features are unlikely to change significantly.
Releases
Use cargo-release to publish new versions:
# Bump version, update Cargo.lock, commit, tag, and push
This updates Cargo.toml and Cargo.lock, creates a commit and tag, then pushes to GitHub. The tag push triggers GitHub Actions to build binaries, create the release, and publish to crates.io.
Run without --execute to preview changes first.
FAQ
Installation fails with C compilation errors
If you encounter errors related to tree-sitter or C compilation (like "error: 'for' loop initial declarations are only allowed in C99 mode" or "undefined reference to le16toh"), install without syntax highlighting:
This disables bash syntax highlighting in command output but keeps all core functionality. The syntax highlighting feature requires C99 compiler support and can fail on older systems or minimal Docker images.