Worktrees and code review
Local and worktree threads, review mode, comments, sync and merge back.
A Git worktree is a second checkout of the same repository. A thread placed in a worktree edits files there, so parallel threads do not touch each other's files. Its Files, Terminal and Changes panels use that directory.
Choose where a thread runs#
Before the first message, pick a mode in the row above the composer:
| Mode | Directory | Options |
|---|---|---|
| Local | The project checkout. | Branch: the current one, another one, or New branch from …. |
| Worktree | A new checkout for this thread. | Branch name or detached, base branch, carry uncommitted changes, setup script. |
The worktree is created when you send.
/worktree new creates one at once; /new worktree starts a new thread in one. Remember saves the choice as the project's default.Local refuses a branch switch when the checkout has uncommitted changes, another thread is running there, or another worktree holds the branch. Turn off Local: switching branches per project to prevent switches entirely.
Configure worktrees per project#
Settings → Projects → (project) sets:
- the worktree folder and branch naming;
- the setup script, which can install dependencies or copy files such as
.env.local. Without one, pi-kit suggests one from the lockfile; - Remove the folder after merge back, hand-off or archiving: Ask, Right away, After 7 days or Never.
Open worktrees lists each worktree with its thread and offers Hand off, Merge back and Remove folder. With After 7 days, a worktree you handed off is removed a week later if it is still clean and no thread uses it.
Review changes#
Open Changes and pick a source:
| Source | Compares |
|---|---|
| This thread | Each file with its state before the run that first changed it. |
| Working tree | All uncommitted changes in the checkout. |
| Outcome | The recorded diff of a commit, merge or pull request. |
pi-kit takes Git snapshots before and after each run and each background-agent turn, and refreshes when HEAD moves. A folder without Git offers Initialise git.
The thread header shows a pill with added and removed lines. Click it to open review mode.
| Control | Does |
|---|---|
| Source | Switch between This thread, Working tree and Outcome. |
| Changed files, ‹ › | Jump to a file or step through them. N of M viewed tracks progress. |
| Unified / Split | One column, or Before and After side by side with synchronized scrolling. Narrow windows use Unified. |
| Find in diff (⌘F) | Search the file. Aa matches case. |
| Open in editor | Open the file. Files above the size limit open only there. |
| Revert file, Stage all | Act on current changes, not on an Outcome. |
Comment and send
Hover a line, click +, write a comment and choose Add to batch. Comments collect until you choose Send comments to pi; they go as one message.
Video walkthrough · English captions
Review file changes
Select code in a prepared fictional change, queue comments across two files, and send one feedback batch to pi. File references and selected code stay attached to the conversation.
Snapshots record folder state, not who made each edit. Another thread in the same checkout shows up in the comparison; use a worktree to keep them apart.
Sync with the base branch#
Thread menu → Sync with ‹base›…, or
/worktree sync. Choose Merge or Rebase (rebase needs a clean worktree). Conflicts open in review mode with Review conflicts; resolve them and run your checks before merging back.Merge back or open a pull request#
Thread menu → Merge back…, or
/worktree merge. Choose Merge into ‹branch› or Open a pull request. A pull request needs the GitHub CLI (gh), signed in, and a remote. The result appears as an outcome badge on the thread.Removing the worktree is a separate step. Uncommitted files or another thread using the folder block removal.
Move a thread#
The thread menu offers, where they apply:
| Item | Does |
|---|---|
| Hand off to local… | Move the work from the worktree into the project checkout. This can switch the checkout's branch. |
| Move into a worktree… | Move a Local thread into a new worktree, with all uncommitted changes in that checkout. |
| Create branch here… | Give a detached worktree a branch. |
A disabled item explains what blocks it.
Several threads in one repository#
Threads see which files other agents in the repository changed recently. This is advisory: files are not locked. A worktree separates checkouts, not permissions: commands can still reach other folders. Use Sandboxed protection to restrict tools.
See Troubleshooting for branch, placement and cleanup errors.