Skip to content

fix: strip inherited agent session env vars when spawning new panes - #68

Merged
110y merged 1 commit into
mainfrom
fix/strip-inherited-agent-session-env
Jun 9, 2026
Merged

fix: strip inherited agent session env vars when spawning new panes#68
110y merged 1 commit into
mainfrom
fix/strip-inherited-agent-session-env

Conversation

@110y

@110y 110y commented Jun 9, 2026

Copy link
Copy Markdown
Owner

When the muxac tmux server is started from inside a Claude Code session, it captures Claude's session-identity environment variables (CLAUDE_CODE_SESSION_ID, CLAUDECODE, CLAUDE_PROJECT_DIR) and injects them into every pane it later spawns. A freshly launched Claude Code then treats itself as an already-identified nested session and stops persisting its transcript, so the session cannot be resumed. A stale CLAUDE_PROJECT_DIR can also cause muxac to misdetect Codex/Gemini sessions as Claude.

This wraps the spawned command with env -u to unset those inherited variables before exec, so each pane starts as a fresh top-level session. Each agent repopulates the correct values for its own run.

Copilot AI review requested due to automatic review settings June 9, 2026 13:37

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR prevents muxac-spawned tmux sessions from inheriting Claude Code session-identity environment variables by wrapping the spawned command with env -u ..., ensuring each pane starts as a fresh top-level agent session and transcript persistence/resume behavior remains correct.

Changes:

  • Wrap new session commands with an env -u prefix to unset CLAUDE_CODE_SESSION_ID, CLAUDECODE, and CLAUDE_PROJECT_DIR before launching the agent.
  • Add/adjust tests to validate the new command wrapping behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
internal/newcmd/newcmd.go Wraps the spawned command with env -u to strip inherited Claude session env vars.
internal/newcmd/newcmd_test.go Updates expectations and adds a dedicated test for the command wrapping.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +88 to 91
wantCommand := "env -u CLAUDE_CODE_SESSION_ID -u CLAUDECODE -u CLAUDE_PROJECT_DIR claude"
if ns.Command != wantCommand {
t.Errorf("command = %q, want %q", ns.Command, wantCommand)
}
@110y
110y merged commit ed3de69 into main Jun 9, 2026
5 checks passed
@110y
110y deleted the fix/strip-inherited-agent-session-env branch June 9, 2026 13:45
@muxac-cd muxac-cd Bot mentioned this pull request Jun 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants