fix: strip inherited agent session env vars when spawning new panes - #68
Merged
Conversation
There was a problem hiding this comment.
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
newsession commands with anenv -uprefix to unsetCLAUDE_CODE_SESSION_ID,CLAUDECODE, andCLAUDE_PROJECT_DIRbefore 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) | ||
| } |
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 staleCLAUDE_PROJECT_DIRcan also cause muxac to misdetect Codex/Gemini sessions as Claude.This wraps the spawned command with
env -uto 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.