Repository navigation
Conversation
Any shell command starts the daemon when none is running, and startDetachedDaemon gave it os.Environ(). Run from inside Claude Code, that carried CLAUDE_CODE_CHILD_SESSION and CLAUDE_CODE_SESSION_ID into the daemon, and from there into every session the browser asked for. prepareCommandLaunch saw a bare `claude` inside a Claude conversation and rewrote it to `claude --resume <id> --fork-session`, so starting Claude from the app reopened the conversation the daemon happened to be born in, every time, until the daemon restarted. OpenCode had the same path, including its "continue the latest session" fallback. Three independent guards, so one regression cannot bring it back: - The daemon starts without any agent harness's identity variables. - Sessions the daemon launches for the browser start without them too, which also covers a daemon an older release already started with them. - A session the browser asked for (SHELL_ONLINE_SESSION_ORIGIN set) never hands off. Typing `shell claude` inside Claude Code still does. harnessIdentityVariables is the one list; a test checks it covers every adapter's detection and strip variables. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ScihqCEjAhjFfkvfSR3ZXN
2 tasks done
Contributor
Author
|
Combined into #285, with the other open fixes and the two flaky CI checks fixed. |
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.
What changes for the user?
Bug: on a machine where
shellwas first run from inside Claude Code, startingclaudefrom the app reopens that old Claude conversation, as a fork, instead of starting a new one. It happens every time, until the daemon restarts. We hit this on a real account: two app-started "new sessions" in a row both opened a fork of the Claude Code conversation that had runshell listearlier.Cause:
shellcommand starts the daemon when none is running (ensureDaemon), andstartDetachedDaemongives itos.Environ().CLAUDECODE,CLAUDE_CODE_CHILD_SESSION=1andCLAUDE_CODE_SESSION_ID.agent_loop.go,launch.Env = os.Environ()).prepareCommandLaunchsees a bareclaude"inside" a Claude conversation and rewrites it toclaude --resume <id> --fork-session.OpenCode has the same path, including its "continue the latest session" fallback.
Fix: three independent guards, so one regression can't bring it back.
startDetachedDaemon(Unix and Windows)agent_loop.go, browser-started sessionsmain.go, handoff decisionhandoffAllowed(): a session the browser asked for (SHELL_ONLINE_SESSION_ORIGINset) never hands off.Typing
shell claudeinside Claude Code still forks the conversation, as the handoff feature intends. The installed service was never affected, because it passes only its allowlist of variables through.harnessIdentityVariablesis the single list. A test checks it covers every adapter's detection and strip variables, so a new harness adapter can't silently reopen this.Verification
handoff_test.go:TestBrowserStartedSessionNeverForksAnAgentConversationis the regression test. The pre-fix call site (prepareCommandLaunch(..., !foreground)) turns a browser-startedclaudeintoclaude --resume 123e4567-… --fork-session, and it no longer does. A typedshell claudestill hands off, and a foreground launch doesn't.TestDetachedEnvironmentDropsAgentConversationIdentityTestHarnessIdentityVariablesCoverEveryAdapterremote_start: true) and runtime directory:shell liststarted a daemon.go vet ./...andgofmtare clean.go test -race ./...passes: all 9 packages.Access and privacy
This narrows what the daemon and browser-started sessions inherit. No change to authorization, remote-start consent, encryption or stored content.
Rollout
Needs a CLI release. On an affected machine, the fix takes effect once the new release's daemon replaces the running one, via
shell service install, a reboot, or signing in again (restartDaemon). The second guard also protects sessions launched by a new daemon even if its own environment were somehow contaminated.Until then, the workaround is to stop the daemon and start it again from a normal terminal, not from inside an agent.
🤖 Generated with Claude Code
https://claude.ai/code/session_01ScihqCEjAhjFfkvfSR3ZXN