Lesson 0002
Inspect a Git worktree before you touch it
A worktree is another checkout attached to the same repository. In Agents View, that matters because useful background work may live in an isolated worktree path until you intentionally keep it, merge it, or remove it.
The one idea
Do not think of a worktree as a second clone. Think of it as a second working directory connected to the same repository storage. The official Git manual says one repository can have one main worktree and zero or more linked worktrees, letting you check out more than one branch at a time.
.claude/worktrees/.
What is isolated
| Thing | Worktree behavior | Why you care |
|---|---|---|
| Files on disk | Separate per worktree path. | An agent can edit files without touching your main checkout. |
HEAD and index |
Separate per worktree. | Each worktree can have its own checked-out commit and staged changes. |
| Commits and branch refs | Shared by the repository. | A commit made in one worktree is visible from the others. |
| Same branch twice | Git refuses by default. | This prevents two directories from both pretending to own one branch. |
| Dirty removal | git worktree remove refuses by default. |
Git tries to stop you from deleting uncommitted work by accident. |
The inspection loop
git worktree list
Entercd <path>
Statusgit status --short
Branchgit branch --show-current
Diffgit diff
Decidekeep, merge, or remove
Use this loop whenever a session, tool, or teammate points you at a worktree path. The first decision is not "delete or merge"; it is "what branch, what files, what changes?"
git worktree list
cd <worktree-path>
git status --short
git branch --show-current
git diff
git diff --cached
git log --oneline --decorate -5
Create one safely
The most common manual pattern is a sibling directory plus a fresh branch. From the main checkout:
git worktree add ../task-name -b task-name
For throwaway testing with no branch, use a detached worktree:
git worktree add -d ../scratch-test
Remove one safely
Remove a linked worktree through Git, not by deleting its folder first. Git tracks administrative metadata for linked worktrees, so the command can check whether the directory is clean.
git worktree remove ../task-name
If someone already deleted a worktree directory by hand, inspect stale entries before cleanup:
git worktree prune --dry-run
git worktree prune
Agents View checklist
-
Find the path
Peek or attach to the session and find the worktree path. Agents View reference material notes that Claude-created background work may be isolated under
.claude/worktrees/. -
Inspect before cleanup
Run the inspection loop in that path. Confirm whether changes are untracked, unstaged, staged, or committed.
-
Keep useful work intentionally
Commit it on its branch, push it, cherry-pick it elsewhere, or copy a patch. Choose one before deleting the session or removing the worktree.
-
Remove only when boring
A boring worktree has no useful uncommitted changes. Then
git worktree remove <path>should succeed without force.
Practice: retrieve the safety loop
Type the command from memory, then check. The point is to make the inspection loop automatic before you need it under pressure.
Primary source
- Read the official Git manual next: git-worktree documentation. Focus on Description, Commands, Details, List Output Format, and Examples.