/worktree command integrates with the git worktrees system to allow isolated work on multiple branches simultaneously. Instead of git stash and git checkout, you create separate worktrees and switch between them with a single command.
Git worktrees allow you to have multiple working copies of the same repository, each on a different branch, sharing the same
.git. ChatCLI automates the creation, listing, and removal of these worktrees.Concept
A worktree is a separate directory linked to the same Git repository but on a different branch. This allows:.git, commits, and history. You can work on each branch without interfering with the others.
Commands
| Command | Description |
|---|---|
/worktree create <branch> | Creates a new worktree for the specified branch |
/worktree list | Lists all active worktrees for the repository |
/worktree remove <branch> | Removes an existing worktree |
/worktree status | Shows the current worktree status (branch, modified files) |
Creating a Worktree
Automatic branch detection
If the branch already exists in the repository (local or remote), ChatCLI uses it directly. If it doesn’t exist, it creates a new branch from the current HEAD.
Directory creation
The worktree directory is created alongside the repository root, with a name based on the branch (slashes replaced with hyphens).
Listing Worktrees
Removing a Worktree
Worktree Status
Typical Workflows
- Parallel feature
- Urgent hotfix
- PR review
Work on a feature without affecting the main branch:
Technical Details
Directory Location
Worktrees are created alongside the repository root:<repo-name>-<branch>, where slashes (/) in the branch are replaced with hyphens (-).
Automatic CWD Change
When creating or selecting a worktree, ChatCLI automatically changes the CWD. This ensures that:- Agent/coder commands operate on the correct files
- File search (
search,tree) reflects the correct branch - Bootstrap files (SOUL.md, RULES.md) are detected correctly
Compatibility
| Requirement | Details |
|---|---|
| Git | >= 2.15.0 (worktree support) |
| Repository | Must be a Git repository (non-bare) |
| Permissions | Write access to the parent directory of the repository |
Next Steps
Sessions
Combine worktrees with sessions for persistent context per branch.
Coder Mode
Use coder mode with worktrees for isolated engineering per branch.