[FEATURE] Warn user immediately when session opens inside a worktree before allowing any file edits
Preflight Checklist
- [x] I have searched existing requests and this feature hasn't been requested yet
- [x] This is a single feature request (not multiple features)
Problem Statement
Summary
When Claude Code opens a new session inside a worktree (.claude/worktrees/*),
it begins editing files there without warning the user. Worktrees are branched
from older commits, so edits silently overwrite the user's real working code
with an outdated version — destroying recent uncommitted work.
Proposed Solution
Requested behaviour
When cwd is detected inside .claude/worktrees/*, warn before any file edit:
⚠️ This session opened inside a worktree which may be based on an older
branch. Before I edit anything — should I work here or in your main project
folder?
Then wait for explicit confirmation before touching any file.
Why this matters
Silent data-loss risk. One sentence at session start eliminates it entirely.
Alternative Solutions
_No response_
Priority
Medium - Would be very helpful
Feature Category
CLI commands and flags
Use Case Example
Real incident
A user had months of production code including 2000+ lines of automation that
had never been committed. A new session landed in a worktree based on an old
branch. Claude edited files there and copied them to the main project folder,
wiping out all uncommitted work. The user spent hours re-debugging issues that
had already been solved.
Root cause
- Claude has no awareness it is in a worktree vs the real project
- No session-start warning exists
- CLAUDE.md helps only if the user already knows to create it
Additional Context
Summary
When Claude Code opens a new session inside a worktree (.claude/worktrees/*),
it begins editing files there without warning the user. Worktrees are branched
from older commits, so edits silently overwrite the user's real working code
with an outdated version — destroying recent uncommitted work.
Real incident
A user had months of production code including 2000+ lines of automation that
had never been committed. A new session landed in a worktree based on an old
branch. Claude edited files there and copied them to the main project folder,
wiping out all uncommitted work. The user spent hours re-debugging issues that
had already been solved.
Root cause
- Claude has no awareness it is in a worktree vs the real project
- No session-start warning exists
- CLAUDE.md helps only if the user already knows to create it
Requested behaviour
When cwd is detected inside .claude/worktrees/*, warn before any file edit:
⚠️ This session opened inside a worktree which may be based on an older
branch. Before I edit anything — should I work here or in your main project
folder?
Then wait for explicit confirmation before touching any file.
Why this matters
Silent data-loss risk. One sentence at session start eliminates it entirely.
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗