claude-code - 💡(How to fix) Fix EnterWorktree modifies tracked files during worktree creation [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#47890Fetched 2026-04-15 06:39:24
View on GitHub
Comments
0
Participants
1
Timeline
5
Reactions
0
Participants
Timeline (top)
labeled ×4closed ×1
RAW_BUFFERClick to expand / collapse

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

extent analysis

TL;DR

Modify the Claude Code configuration to prevent automatic cleanup of rules files during worktree initialization.

Guidance

  • Investigate the Claude Code documentation for options to disable automatic cleanup of rules files, potentially through a configuration flag or setting.
  • Verify that the isolation: "worktree" parameter in the Agent tool or EnterWorktree command does not implicitly trigger the cleanup process.
  • Check if there are any environment variables or startup options for Claude Code that can be used to suppress the modification of rules files during worktree creation.
  • Consider creating a custom hook or script to restore the original rules files after worktree creation, as a temporary workaround.

Example

No code snippet is provided due to the lack of specific API or function references in the issue.

Notes

The solution may depend on the specific version of Claude Code and its configuration options. The provided guidance is based on the information given and may need to be adapted to the actual implementation.

Recommendation

Apply workaround: Modify the Claude Code configuration or use a custom script to prevent or revert the automatic cleanup of rules files, as the root cause seems to be related to the tool's behavior rather than a version-specific bug that could be fixed by upgrading.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

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

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING