Skip to main content
ChatCLI’s /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:
They all share the same .git, commits, and history. You can work on each branch without interfering with the others.

Commands


Creating a Worktree

1

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.
2

Directory creation

The worktree directory is created alongside the repository root, with a name based on the branch (slashes replaced with hyphens).
3

CWD change

ChatCLI automatically changes the working directory to the new worktree, allowing subsequent commands to operate in the correct context.
The branch can be an existing branch (local or remote) or a new branch. ChatCLI automatically detects which and acts accordingly.

Listing Worktrees


Removing a Worktree

Removing a worktree deletes the directory but does not delete the branch. Uncommitted changes will be lost. Always commit or stash before removing.

Worktree Status


Typical Workflows

Work on a feature without affecting the main branch:

Technical Details

Directory Location

Worktrees are created alongside the repository root:
The directory name is composed as <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


Next Steps

Sessions

Combine worktrees with sessions for persistent context per branch.

Coder Mode

Use coder mode with worktrees for isolated engineering per branch.