Skip to content

hokuts/wtzsh

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

wt.zsh

Zsh functions for managing git worktrees with git-wt and Claude Code.

Requirements

Installation

Add the following to your .zshrc after compinit:

autoload -Uz compinit && compinit
source /path/to/wt.zsh

Then reload your shell:

source ~/.zshrc

Functions

cdwt — navigate to a worktree

cdwt [<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 — launch Claude Code in a worktree

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 — remove a worktree

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)

Unifying worktree paths created by Claude Code

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.

Worktree cleanup on Claude Code exit

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.

About

Zsh helper functions for git worktree

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages