[BUG] Editing files in Main folder of the repo, instead of Worktree

Resolved 💬 3 comments Opened Apr 11, 2026 by kosovans Closed Apr 14, 2026

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

When Claude Code is operating inside a git worktree (spawned via the Agent tool with isolation: "worktree"), the Write and Edit tools resolve file paths against the main repository instead of the worktree's working directory.

In my case, the worktree was at:
/Users/.../.../.claude/worktrees/angry-sammet

Claude's Write tool wrote to:
/Users/.../.../.../Views/Settings/iOSSettingsView.swift
(the main repo)

Instead of:
/Users/.../.../.claude/worktrees/angry-sammet/.../Views/Settings/iOSSettingsView.swift
(the worktree)

The Bash tool correctly used the worktree as its cwd, but Write/Edit did not. The build command (xcodebuild) also ran from the main repo path. The user had to manually revert the main repo and re-apply changes in the worktree.

What Should Happen?

When Claude Code is running in a worktree, all file operations (Write, Edit, Read, Glob, Grep) should resolve paths relative to the worktree root, not the main repository. The worktree path should be the canonical base for all file I/O.

Error Messages/Logs

Steps to Reproduce

Open a git repository in Claude Code
Ask Claude to perform a task (e.g., "edit file X")
Claude spawns a subagent with isolation: "worktree", creating a worktree at .claude/worktrees/<name>
Inside the worktree agent, Claude uses the Write or Edit tool with an absolute path pointing to the main repo (e.g., /Users/.../MyProject/src/file.swift) instead of the worktree (e.g., /Users/.../MyProject/.claude/worktrees/<name>/src/file.swift)
The main repo gets modified unexpectedly; the worktree remains unchanged
The Bash tool correctly uses the worktree cwd, but Write/Edit/Read do not

Claude Model

Opus

Is this a regression?

Yes, this worked in a previous version

Last Working Version

_No response_

Claude Code Version

2.1.87

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Other

Additional Information

I was running desktop APP

View original on GitHub ↗

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