[BUG] CLAUDE.md and .claude/rules/ loaded twice in git worktrees

Resolved 💬 3 comments Opened Feb 20, 2026 by gboston Closed Mar 20, 2026

Description

When running Claude Code inside a git worktree, project instructions (CLAUDE.md, AGENTS.md, .claude/rules/*.md) are loaded twice — once from the worktree path and once from the main repository path. Both copies appear in the system context, doubling the context usage for project instructions.

Reproduction steps

  1. Have a repo with CLAUDE.md and/or .claude/rules/ containing project instructions
  2. Create a git worktree:

``bash
git worktree add .worktrees/my-feature -b my-feature
``

  1. Open Claude Code in the worktree directory:

``bash
cd .worktrees/my-feature
claude
``

  1. Observe the loaded context — every project instruction file appears twice:
  • Contents of /path/to/main-repo/CLAUDE.md
  • Contents of /path/to/main-repo/.worktrees/my-feature/CLAUDE.md
  • Contents of /path/to/main-repo/.claude/rules/frontend.md
  • Contents of /path/to/main-repo/.worktrees/my-feature/.claude/rules/frontend.md

Expected behavior

Each project instruction file should be loaded exactly once, regardless of whether running in a worktree or the main repo.

Actual behavior

Every file from CLAUDE.md, AGENTS.md, and .claude/rules/ is loaded twice. Both copies contain identical content since they are the same files in the same git repository.

Root cause

Same as #26992. In a git worktree, .git is a file pointing back to the main repo:

gitdir: /path/to/main-repo/.git/worktrees/<name>

Claude Code discovers project instructions from both:

  1. The worktree's CWD (e.g., .worktrees/my-feature/CLAUDE.md)
  2. The main repository root (by following .git back to the main repo, e.g., main-repo/CLAUDE.md)

Since both paths resolve to the same git content, every instruction file appears twice.

Suggested fix

  • Deduplicate discovered files by inode or content hash
  • Or resolve both paths to the same canonical git root and only load once
  • Or detect worktree context and only load from the CWD path

Environment

  • Claude Code version: 2.1.47
  • OS: macOS (Darwin 25.0.0)
  • Shell: zsh

Related issues

  • #26992 — Same root cause, but for duplicate slash commands in worktrees
  • #27069 — Duplicate skills/commands in worktrees

View original on GitHub ↗

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