Zsh functions for managing git worktrees with git-wt and Claude Code.
Add the following to your .zshrc after compinit:
autoload -Uz compinit && compinit
source /path/to/wt.zshThen reload your shell:
source ~/.zshrccdwt [<name|branch>]
- With argument: navigate to the worktree matching the given worktree name or branch name (tab-completable)
- Without argument: select from a list via fzf, then navigate
- Press Tab to create a new worktree from the typed name instead of selecting an existing one
clwt [-a] [<name|branch>]
- With argument: launch Claude Code in the specified worktree (tab-completable); creates the worktree if it does not exist
- Without argument: select from a list via fzf, then launch Claude Code
- Press Tab to create a new worktree from the typed name instead of selecting an existing one
-a: enable auto-mode (--enable-auto-mode)
rmwt [-f] [<name|branch>]
- With argument: remove the worktree matching the given worktree name or branch name (tab-completable)
- Without argument: select from a list via fzf, then remove
-f: force delete (git wt -D)
By default, Claude Code creates worktrees under <repo>/.claude/worktrees/, which differs from the path convention used by git-wt. To unify the worktree path, register the included hook script in ~/.claude/settings.json:
{
"hooks": {
"WorktreeCreate": [
{
"hooks": [
{
"type": "command",
"command": "/path/to/wtzsh/claude/hooks/WorktreeCreate.zsh"
}
]
}
]
}
}Replace /path/to/wtzsh with the actual path to this repository. This makes claude -w and clwt create worktrees in the same location as git wt.
Using the WorktreeCreate hook causes Claude Code's built-in worktree cleanup to stop working (anthropics/claude-code#34137). To restore automatic cleanup, also register the WorktreeRemove hook:
{
"hooks": {
"WorktreeCreate": [
{
"hooks": [
{
"type": "command",
"command": "/path/to/wtzsh/claude/hooks/WorktreeCreate.zsh"
}
]
}
],
"WorktreeRemove": [
{
"hooks": [
{
"type": "command",
"command": "/path/to/wtzsh/claude/hooks/WorktreeRemove.zsh"
}
]
}
]
}
}This hook removes worktrees that have no uncommitted changes and no commits ahead of the base branch. Unlike Claude's default behavior which offers a Keep/Remove prompt for dirty worktrees, this hook conservatively preserves any worktree with changes.