Symptom
bun ~/.claude/LIFEOS/TOOLS/AlgoPhase.ts <phase> (without --slug) can write the Algorithm phase to a different session's row in work.json than the active one — corrupting the Pulse dashboard's phase / mode-history for an unrelated session.
Root cause
Slug resolution priority (in AlgoPhase.ts):
--slug
- row whose
sessionUUID === process.env.CLAUDE_SESSION_ID
--uuid
- most-recent algorithm-mode row across all sessions
Priority 2 reads CLAUDE_SESSION_ID. Per the official env-vars doc, Claude Code exposes neither CLAUDE_SESSION_ID nor CLAUDE_CODE_SESSION_ID as a general Bash env var — the documented session id is CLAUDE_CODE_BRIDGE_SESSION_ID (Remote Control) / CLAUDE_CODE_REMOTE_SESSION_ID (cloud). So priority 2 never matches, and every bare invocation falls through to priority 4, which guesses the most-recently-active algorithm row. With more than one live session, that guess can be wrong — a silent write to the wrong session.
Docs discrepancy worth surfacing
The changelog (v2.1.163) says stdio MCP servers "receive the same CLAUDE_CODE_SESSION_ID as hooks/Bash on --resume" — naming a variable that env-vars.md says isn't exposed (it documents CLAUDE_CODE_BRIDGE_SESSION_ID). The correct session var for a Bash subprocess to read is ambiguous across the official docs.
Suggested fix (two parts; the second needs no env var)
- Read the documented session var(s) —
CLAUDE_CODE_BRIDGE_SESSION_ID / CLAUDE_CODE_REMOTE_SESSION_ID — with fallbacks, instead of the non-exposed CLAUDE_SESSION_ID.
- Fail closed when resolution is ambiguous (no
--slug/--uuid/env match and >1 live algorithm-mode row) instead of guessing the most-recent row. The silent wrong-write is the real harm; refusing + printing an error is strictly safer for a tool that writes state.
I have a tested patch (env-var fallback + fail-closed layering + unit tests) if it's useful.
Environment: reproduced on Linux. The exact session env var differs by surface (CLI vs Agent SDK), so part 2 (surface-independent) is the durable half.
Symptom
bun ~/.claude/LIFEOS/TOOLS/AlgoPhase.ts <phase>(without--slug) can write the Algorithm phase to a different session's row inwork.jsonthan the active one — corrupting the Pulse dashboard's phase / mode-history for an unrelated session.Root cause
Slug resolution priority (in
AlgoPhase.ts):--slugsessionUUID === process.env.CLAUDE_SESSION_ID--uuidPriority 2 reads
CLAUDE_SESSION_ID. Per the official env-vars doc, Claude Code exposes neitherCLAUDE_SESSION_IDnorCLAUDE_CODE_SESSION_IDas a general Bash env var — the documented session id isCLAUDE_CODE_BRIDGE_SESSION_ID(Remote Control) /CLAUDE_CODE_REMOTE_SESSION_ID(cloud). So priority 2 never matches, and every bare invocation falls through to priority 4, which guesses the most-recently-active algorithm row. With more than one live session, that guess can be wrong — a silent write to the wrong session.Docs discrepancy worth surfacing
The changelog (v2.1.163) says stdio MCP servers "receive the same
CLAUDE_CODE_SESSION_IDas hooks/Bash on--resume" — naming a variable that env-vars.md says isn't exposed (it documentsCLAUDE_CODE_BRIDGE_SESSION_ID). The correct session var for a Bash subprocess to read is ambiguous across the official docs.Suggested fix (two parts; the second needs no env var)
CLAUDE_CODE_BRIDGE_SESSION_ID/CLAUDE_CODE_REMOTE_SESSION_ID— with fallbacks, instead of the non-exposedCLAUDE_SESSION_ID.--slug/--uuid/env match and >1 live algorithm-mode row) instead of guessing the most-recent row. The silent wrong-write is the real harm; refusing + printing an error is strictly safer for a tool that writes state.I have a tested patch (env-var fallback + fail-closed layering + unit tests) if it's useful.
Environment: reproduced on Linux. The exact session env var differs by surface (CLI vs Agent SDK), so part 2 (surface-independent) is the durable half.