Skip to content
Source on GitHub (opens in a new tab)

A Git worktree is a second checkout of the same repository, on its own branch. Working in one, zelk can change files and run builds while your own checkout stays as it is, and you can run several sessions side by side.

zelk -worktree fix-42 # the terminal UI, in .zelk/worktrees/fix-42
zelk exec -mode accept-edits -worktree fix-42 "fix #42"
zelk -worktree= # zelk picks a name

-worktree NAME works in .zelk/worktrees/NAME on the branch worktree-NAME, creating both from the current HEAD if they don’t exist yet, and using them as they are if they do. Give it before the task.

Give -worktree a pull or merge request instead of a name, and zelk fetches that change from origin into a worktree of its own:

zelk -worktree '#1234' # into pr-1234
zelk -worktree https://github.com/OWNER/REPO/pull/1234

Quote #1234: the shell reads an unquoted # as a comment.

A new worktree has only what Git tracks. To copy in ignored files a build needs, such as .env, list them in .worktreeinclude at the repository root, one pattern per line as in .gitignore:

.worktreeinclude
.env
config/local.yaml

Only files that are both ignored and listed are copied.

zelk -worktree fix-42 -c # the terminal UI: that worktree's last session
zelk -worktree fix-42 -r # pick among its sessions
zelk exec -worktree fix-42 resume --last "go on"

A session started anywhere inside a worktree shares the main checkout’s memory, and its skills and agents unless the worktree has its own.

zelk exec removes a worktree only when the agent leaves it with ExitWorktree and asks to remove it, once the session’s new place is recorded. Otherwise it keeps the worktree and its branch. When it exits, after an error or an interrupt too, it prints to standard error the command that takes you back to the main checkout and continues that session:

zelk exec: return with: cd '/home/you/repo' && zelk exec '-mode' 'accept-edits' -state '/home/you/.local/state/zelk' -worktree 'fix-42' resume --last

Run it with the same environment, adding a task to continue.

The terminal UI cleans up when you quit normally. A clean worktree whose name zelk generated is removed, with its branch if zelk created it, unless you launched zelk directly in it; then it is only offered for removal, like any other. Any other worktree gets a cleanup sheet describing what removing it would delete, with Keep worktree selected: Enter or Esc keeps it, and Remove worktree discards that work. zelk refuses to remove a worktree another process holds, or one it can’t account for, and always keeps a branch it can’t show it made. After an error or a signal, the worktree is kept.

Removing a worktree you kept is up to you: git worktree remove .zelk/worktrees/fix-42, then git branch -D worktree-fix-42 once you no longer need the branch.

Worktrees work on Windows with Git for Windows installed: zelk runs its git.exe, as for every other git inspection it makes. A worktree is a directory under .zelk\worktrees, so its name must be one Windows can hold. zelk refuses con, prn, aux, nul, com1 to com9 and lpt1 to lpt9 (with or without an extension, in any case), a trailing ., and the characters Windows reserves. It also refuses a name that differs from an existing worktree’s only in case, since NTFS would put both in one directory: -worktree Feature after -worktree feature says so instead of reopening the first.

A worktree’s holder is recognised by its process and the boot it started in. If zelk can’t tell whether a holder is still running, because Windows won’t let it look at that process, the worktree counts as held, never as free, and zelk doesn’t reclaim or remove it.