Duplicate slash commands in git worktrees
Description
When running Claude Code inside a git worktree, every slash command in .claude/commands/ appears twice in the / menu. Both copies show as (project). This does not happen in the main repository — only in worktrees.
Reproduction steps
- Have a repo with
.claude/commands/containing slash commands - Create a git worktree:
``bash``
git worktree add ../my-worktree -b test-branch
- Open Claude Code in the worktree directory:
``bash``
cd ../my-worktree
claude
- Type
/to open the command menu - Every command appears twice (e.g.,
/code-reviewlisted twice, both marked(project))
No custom configuration or file copying is needed — a plain git worktree add is sufficient to reproduce.
Expected behavior
Each command should appear exactly once, same as in the main repository.
Actual behavior
Every command from .claude/commands/ is listed twice in the menu. Both entries are tagged (project).
Root cause hypothesis
In a git worktree, the .git entry is a file (not a directory) pointing back to the main repo:
gitdir: /path/to/main-repo/.git/worktrees/<name>
Claude Code likely discovers .claude/commands/ from both:
- The worktree's own
.claude/commands/(the current working directory) - The main repository's
.claude/commands/(by following the.gitfile back to the main repo root)
Since both paths contain the same commands (same git repo), every command appears twice.
Environment
- Claude Code version: 2.1.47
- OS: macOS (Darwin 25.2.0)
- Shell: zsh
Related issues
- #3939 — Duplicate custom commands (fixed in v1.0.61, but not for worktrees)
- #2316 — Commands duplicated from home directory (fixed in v1.0.61)
- #10105 — Claude confuses worktree directories with main repository
- #13019 — Tool permissions not recognized in git worktrees
This issue has 8 comments on GitHub. Read the full discussion on GitHub ↗