Feature Request: /add-git and /clean-git — Multi-repo worktree-aware collaboration

Resolved 💬 2 comments Opened Feb 22, 2026 by kevinaimonster Closed Mar 22, 2026

Preflight Checklist

  • [x] I have searched existing requests and this feature hasn't been requested yet
  • [x] This is a single feature request (not multiple features)

Problem Statement

Problem

When working with multiple repositories (e.g., frontend + backend, SDK + main app, microservices), /add-dir works well for adding another project to the session. However, when the primary project uses git worktree for branch isolation, the added repository is still on its main working tree. This means changes to the secondary repo during a feature branch session can pollute its working directory and affect other worktrees or developers.

There is currently no way to automatically create a matching worktree in a secondary repository and add it to the session — users must manually manage this outside of Claude Code.

Proposed Solution

Proposed Solution

/add-git <repo-path> [--branch <base-branch>]

A new slash command that intelligently adds another git repository to the current session, with automatic worktree isolation when appropriate.

If the current working directory is NOT a worktree, simply delegate to /add-dir <repo-path>. No isolation needed.

If the current working directory IS a worktree, create a corresponding worktree in the target repo:

  1. Snapshot & protect the target repo's current state (record current branch; git stash if dirty).
  2. Prompt for base branch if --branch is not provided. Show candidates: main, master, develop, or custom input.
  3. Create worktree:
  • Branch: claude/<current-worktree-branch> (e.g., claude/feat-avatar)
  • Directory: <repo>/../<repo-name>--claude-<branch> (e.g., sdk--claude-feat-avatar)
  • Command: git -C <repo> worktree add <path> -b claude/<branch> <base-branch>
  1. Write metadata .claude-worktree-meta in the new worktree root for tracking.
  2. Restore target repo's original state (checkout original branch, pop stash). Zero side effects on the original working tree.
  3. Add the new worktree to the session via /add-dir.

/clean-git [--all] [--repo <path>]

A companion command to clean up worktrees created by /add-git.

  1. Scan all repositories for worktrees with claude/* branch prefix.
  2. Display status: ✅ merged & clean (safe to remove) vs ⚠️ unmerged or has uncommitted changes (needs confirmation).
  3. User selects which to remove (multi-select, merged ones pre-selected).
  4. Execute: clean removal for merged; explicit confirmation required for unmerged or dirty worktrees.
  5. Output summary: e.g., "Removed 3 worktrees, skipped 1"

Session Exit Hint (optional)

When a session exits after creating claude/* worktrees, show a non-blocking reminder suggesting /clean-git. No automatic cleanup — the user may still need these worktrees.

Alternative Solutions

_No response_

Priority

Critical - Blocking my work

Feature Category

CLI commands and flags

Use Case Example

Use Case

# Working on a feature in my main app using a worktree
cd ~/myapp--feat-avatar
claude

# Need to make corresponding changes in the SDK repo
> /add-git ~/sdk

# Claude Code detects I'm in a worktree, prompts for base branch,
# creates ~/sdk--claude-feat-avatar from sdk's main branch,
# adds it to the session.
# Original ~/sdk working tree is completely untouched.

# When done:
> /clean-git
# Shows all claude/* worktrees with merge status, select which to remove.

---

Edge Cases

  • Branch name conflict: claude/feat-avatar already exists → append suffix or prompt for custom name
  • Worktree path exists: prompt user to reuse / recreate / custom path
  • Submodules: run git submodule update --init after creation
  • Stash pop conflict on restore: keep stash, warn user with reference
  • Disk/permission errors: clean up partial state, restore target repo, report error

Additional Context

Naming Conventions

| Item | Pattern | Example |
|---|---|---|
| Branch | claude/<current-worktree-branch> | claude/feat-avatar |
| Directory | <repo-name>--claude-<branch> | sdk--claude-feat-avatar |
| Auto stash | claude-add-git-auto-<timestamp> | claude-add-git-auto-1708600200 |
| Metadata | .claude-worktree-meta | JSON in worktree root |

---

Motivation

Multi-repo development is extremely common. The git worktree workflow is a clean way to isolate feature work, but this isolation breaks down the moment you need to touch a second repository — today you either pollute the other repo's working tree or manually manage worktrees outside of Claude Code.

/add-git bridges this gap by making multi-repo worktree isolation a first-class workflow in Claude Code.

View original on GitHub ↗

This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗