EnterWorktree modifies tracked files during worktree creation

Resolved 💬 1 comment Opened Apr 14, 2026 by corvansteijn Closed Apr 14, 2026

Bug

When Claude Code creates a git worktree, tracked files under .claude/rules/ get modified during the initialization process. These show up as unstaged changes in the newly created worktree, even though no user action or tool call triggered them.

It appears Claude Code reads the rules files as part of context loading and writes back a modified version — removing sections it considers no longer relevant based on codebase state.

Reproduction

  1. Create a repo with .claude/rules/ files that contain entries referencing code or features that were previously removed and later restored
  2. Have Claude Code create a worktree (via Agent tool with isolation: "worktree", or EnterWorktree)
  3. Run git status in the new worktree immediately — before any user interaction
  4. Observe unstaged modifications to .claude/rules/ files

Key observations

  • The modified file's timestamp matches the worktree creation timestamp to the second
  • No git hooks are active, no Claude Code hooks write to files
  • Git reflog shows only the worktree creation — no commits
  • The modification removes content from rules files, suggesting an automated "cleanup" pass

Expected behavior

Worktree creation should not modify any tracked files. The working tree should be clean immediately after creation.

Environment

  • Claude Code Desktop, macOS Darwin 25.4.0
  • claude-opus-4-6

View original on GitHub ↗

This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗