Skip to content

[FEATURE] Warn user immediately when session opens inside a worktree before allowing any file edits #72467

Description

@claudealbo

Preflight Checklist

  • I have searched existing requests and this feature hasn't been requested yet
  • 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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions