Skip to content

Worktree UX: session keying, multi-repo isolation, and gitignored files #52113

@JefStat

Description

@JefStat

Summary

/worktree is great when a task fits cleanly inside a single git repo, but several rough edges make it painful in common real-world workflows. Filing as a bundle since they share a theme.

The pain points

  1. Sessions are keyed by cwd, so worktrees fragment session history.
    Starting a session in the repo root and then spawning a worktree means claude --resume from either location sees only half the history. There's no obvious way to follow a session across the cwd change.

  2. No way to change a running session's cwd.
    Once you realize mid-session you wanted to be in a worktree, you can't move the session into it. You either abandon context or abandon the worktree.

  3. /worktree requires a git repo.
    Useful when you're working in ~/scratch/, a docs-only dir, or any non-repo workspace and want the same isolation guarantee. Today you have to git init just to get a worktree.

  4. Worktrees don't extend to sibling repos touched during the task.
    My tasks routinely edit repo A while consulting/modifying repo B next to it. The worktree isolates A but the agent still reads/writes the real checkout of B, which defeats the "safe sandbox" promise of worktrees.

  5. Gitignored local config (.env, decrypted secrets, local symlinks) isn't copied into the worktree.
    First run of pnpm dev / tests inside the worktree fails because every gitignored dev-time file is missing. An opt-in copy list (or a documented convention) would unblock this.

Why this matters

Worktrees are the main mechanism for parallel agent work and safe experimentation. The current shape biases users toward single-repo, git-repo-only, dev-server-free tasks — a narrow slice of what people actually do.

Suggestions (not prescriptive)

  • Session metadata could be keyed by session ID with cwd tracked as a mutable property.
  • Allow /worktree in non-repo dirs via a plain directory copy (opt-in).
  • Let /worktree accept additional repo paths to also worktree.
  • A settings key for "files to copy into each worktree" (.env*, *.local, etc.) with sensible defaults.

Environment

  • Claude Code on macOS (darwin 24.6.0)
  • Worktrees created via /worktree into .claude/worktrees/<name>

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions