Skip to content

agladky/cwt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cwt

A small shell tool for managing git worktrees. Built for running multiple Claude Code sessions on the same repo without them stepping on each other, but useful for any parallel-branch workflow.

Git worktrees let you have multiple working copies of a repo, each on its own branch, sharing the same .git history. cwt wraps that with short names, auto-branching, and an fzf picker so you don't have to think about paths.

What it looks like

~/code/myrepo              ← your repo
~/code/myrepo.wt-feature   ← cwt add feature
~/code/myrepo.wt-hotfix    ← cwt add hotfix
~/code/myrepo.wt-1         ← cwt add (auto-named)

Each worktree gets its own branch (wt/feature, wt/hotfix, wt/1), a symlink to .claude/ from the main repo (so all sessions share config), and copies of .env* files.

Install

Fish

git clone https://github.com/agladky/cwt.git
cp cwt/functions/cwt.fish ~/.config/fish/functions/
cp cwt/completions/cwt.fish ~/.config/fish/completions/

Bash

Add to your ~/.bashrc:

source /path/to/cwt/cwt.sh
source /path/to/cwt/completions/cwt.bash

Zsh

Add to your ~/.zshrc:

source /path/to/cwt/cwt.sh
fpath=(/path/to/cwt/completions $fpath)
autoload -Uz compinit && compinit

Or source completions directly:

source /path/to/cwt/cwt.sh
source /path/to/cwt/completions/cwt.zsh

No dependencies beyond git. fzf is optional but recommended for the worktree picker.

Usage

cwt add feature          # create worktree, cd into it
cwt add                  # auto-named (1, 2, 3...)
cwt add -b my-branch     # custom branch name instead of wt/feature
cwt add -s develop       # branch off a specific commit/branch
cwt add hotfix -p        # print path only, don't cd (for scripting)

cwt ls                   # list worktrees, * marks current
cwt go feature           # cd into a worktree
cwt go                   # fzf picker
cwt                      # same as cwt go

cwt merge feature        # merge wt/feature into current branch
cwt merge feature --squash  # squash merge

cwt rm feature           # remove worktree + branch (checks for dirty state)
cwt rm feature -f        # force remove

Composability

stdout only ever gets machine-readable data (paths from add -p, lines from ls). Everything else goes to stderr. So you can do things like:

# fish
set p (cwt add hotfix -p)
cd (cwt add experiment -p)
# bash / zsh
p=$(cwt add hotfix -p)
cd "$(cwt add experiment -p)"

Typical workflow

cd ~/code/myproject
cwt add billing-fix        # creates worktree, switches to it
# ... work, commit ...
cwt go main                # back to main branch
cwt merge billing-fix --squash
git commit -m "fix billing calculation"
cwt rm billing-fix         # clean up

How it works

  • Worktrees are siblings of your repo dir with a .wt-NAME suffix
  • Branches are auto-created under wt/ namespace
  • .claude/ gets symlinked so Claude Code config is shared across worktrees
  • .env* files are copied (not linked, since they're gitignored)
  • cwt rm checks for uncommitted changes and unmerged commits before deleting
  • Stale worktree entries are auto-pruned on add, ls, and rm
  • Works from inside any worktree (resolves the main repo via git rev-parse --git-common-dir)
  • Tab completions for all subcommands, flags, and worktree names

License

MIT

About

Fish shell tool for managing git worktrees — built for parallel Claude Code sessions

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages