[BUG] Duplicate slash commands when running inside a git worktree
Bug Description
Project-level slash commands (.claude/commands/*.md) appear twice in the command list when Claude Code is running inside a git worktree (non-root). From the root worktree, they appear only once as expected.
Steps to Reproduce
# 1. Create a repo with a project slash command
mkdir root && cd root && git init
mkdir -p .claude/commands
echo 'Print "hello world" to the user.' > .claude/commands/hello-world.md
git add -A && git commit -m "test command"
# 2. Create a worktree
git worktree add ../worktrees/test-01 -b test-01
# 3. Launch Claude Code from the worktree
cd ../worktrees/test-01
claude
# 4. Type "/" to list available slash commands
Expected Behavior
/hello-world should appear once in the command list.
Actual Behavior
/hello-world appears twice:
/hello-world Print "hello world" to the user. (project)
/hello-world Print "hello world" to the user. (project)
Root Cause (suspected)
When inside a worktree, Claude Code resolves two different filesystem paths for project commands:
- The worktree's working directory:
.../worktrees/test-01/.claude/commands/ - The root repository's working directory:
.../root/.claude/commands/
Both paths contain the same .claude/commands/hello-world.md (same git content, different filesystem locations). Claude Code loads commands from both without deduplicating.
Key git paths from the worktree:
git rev-parse --show-toplevel→.../worktrees/test-01(the worktree)git rev-parse --git-common-dir→.../root/.git(points back to root repo)
It seems like Claude Code follows --git-common-dir back to the root repo's .claude/commands/ in addition to the worktree's own copy.
Environment
- OS: Linux (WSL2)
- Claude Code: 2.1.52
- Git worktree setup with separate directories for root and worktrees
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗