[Feature Request] EnterWorktree lacks environment variable injection for new worktree context

Resolved 💬 1 comment Opened May 23, 2026 by mascah Closed Jun 23, 2026

Bug Description
Gap: no built-in way to inject env vars into the session after the EnterWorktree tool

EnterWorktree switches the session into a new worktree but leaves no path to update the session's environment for that worktree. The two relevant hooks each cover only half the need, and they don't overlap:

  • WorktreeCreate fires on EnterWorktree but cannot write $CLAUDE_ENV_FILE (its stdout is consumed as the worktree path).
  • CwdChanged can write $CLAUDE_ENV_FILE but does not fire when EnterWorktree changes the cwd.

Net result: after EnterWorktree, Bash-tool commands run in the new worktree but still see the main checkout's environment (wrong ports, DATABASE_URL, VIRTUAL_ENV, PATH). Verified on Claude Code 2.1.149.

The only workaround is a PreToolUse:Bash hook that rewrites every command via updatedInput.command to self-load env from its cwd — which works, but is a per-command band-aid for what should be a lifecycle event.

Requested fix (either would resolve it):

  1. Make EnterWorktree fire CwdChanged, or
  2. Let WorktreeCreate append to $CLAUDE_ENV_FILE.

Environment Info

  • Platform: darwin
  • Terminal: xterm-256color
  • Version: 2.1.150
  • Feedback ID: 00b5eb87-79f2-46e0-b124-5e887d9cb5b7

Errors

[]

View original on GitHub ↗

This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗