You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
tower: sanitize inherited CLAUDE_CODE_* env — restarting Tower from a Claude Code session silently disables transcript saving (and resume) for every spawned agent #1219
tower: sanitize inherited CLAUDE_CODE_* env — restarting Tower from a Claude Code session silently disables transcript saving (and resume) for every spawned agent
Mechanism (verified end-to-end on a live install)
Claude Code plants CLAUDE_CODE_CHILD_SESSION (and CLAUDE_CODE_SESSION_ID, _ENTRYPOINT, _EXECPATH) into the environment of every subprocess it spawns, so a nested claude can detect it was launched from inside another session and disable transcript saving.
Tower is a daemon — but it inherits the environment of whoever starts it. When Tower is started/restarted from a shell inside a Claude Code session (an extremely common operation: afx tower start, pnpm -w run local-install, crash recovery driven by an architect), the marker bakes into Tower's env and cascades:
claude session → Bash tool → afx tower start → Tower → shellper → agent claude
Every architect/builder claude session Tower spawns then believes it is a nested child session and shows:
⚠ Transcript saving is off — inherited CLAUDE_CODE_CHILD_SESSION marker · restart with CLAUDE_CODE_FORCE_SESSION_P…
Verified with ps eww: the running Tower daemon carried the marker, and multiple shellper-spawned agent claude processes carried it (inherited at spawn). After restarting Tower via env -u CLAUDE_CODE_CHILD_SESSION -u CLAUDE_CODE_SESSION_ID -u CLAUDE_CODE_ENTRYPOINT -u CLAUDE_CODE_EXECPATH afx tower start, Tower's env is clean and new spawns are unaffected.
Why this is worse than a warning banner
Sessions with transcript saving disabled cannot be resumed. Tower's whole crash-recovery story (#1145, #1149, session_id-based resume) assumes agent sessions persist transcripts. A Tower that was ever restarted from inside a Claude session quietly produces agents that are unrecoverable after the next crash — the failure only manifests at recovery time, when it's too late. The leak also persists across Tower restarts via shellpers: daemonized shellper processes outlive Tower and keep their spawn-time env, so agents they restart keep the marker even after Tower itself is cleaned.
Proposed fix
Tower sanitizes at spawn: strip CLAUDE_CODE_* (or at minimum CLAUDE_CODE_CHILD_SESSION) from the env it passes to shellper/agent processes. This is the robust fix — it protects regardless of how Tower was started, including the shellper-outlives-Tower path for newly restarted claude processes.
afx tower start scrubs its own env before daemonizing, and (optionally) prints a note when it detects it was launched from inside a Claude session.
codev doctor check (cheap): warn if the running Tower's env carries CLAUDE_CODE_CHILD_SESSION — detectable via ps eww on the daemon PID.
Notes
Any agent terminals spawned while a contaminated Tower was up have the marker baked in until their claude process restarts; the fix is forward-looking.
The transcript-off warning banner appears to be recent Claude Code CLI behavior; the leak itself may long predate its visibility — which is exactly why the doctor check (3) is worth having.
Recurred again 2026-09-05 (a pnpm -w run local-install from an architect session whose env scrub silently failed). Spawning a BUGFIX builder. Design prescription so no plan gate is needed:
Sanitize at the spawn seam, not at startup. In the code path where Tower builds the env for a shellper / agent process, strip this exact set before spawn: CLAUDE_CODE_CHILD_SESSION, CLAUDE_CODE_SESSION_ID, CLAUDE_CODE_ENTRYPOINT, CLAUDE_CODE_EXECPATH, CLAUDE_CODE_MESSAGING_SOCKET, CLAUDE_CODE_MESSAGING_TOKEN, CLAUDECODE, CLAUDE_PID, CLAUDE_EFFORT. Denylist, not a CLAUDE* prefix wipe — CLAUDE_CONFIG_DIR and similar user settings must survive. One exported helper (sanitizeInheritedClaudeEnv(env)) used by every spawn path, with a unit test that pins the list.
afx tower start scrubs its own env with the same helper before daemonizing, and prints one line when it detects it was launched from inside a Claude session.
codev doctor check: read the running Tower daemon's env (ps -E -p <pid> on macOS, /proc/<pid>/environ on Linux) and warn if the marker is present, with the exact restart command.
Verification is functional, not by inspection: restart Tower from inside a Claude session, spawn a builder, and confirm with ps -E that neither Tower nor the agent claude process carries the marker and the agent shows no transcript-off banner.
Not in scope: cleaning up already-contaminated shellpers (forward-looking fix only).
Activity
waleedkadous commentedon Sep 5, 2026
Recurred again 2026-09-05 (a
pnpm -w run local-installfrom an architect session whose env scrub silently failed). Spawning a BUGFIX builder. Design prescription so no plan gate is needed:CLAUDE_CODE_CHILD_SESSION,CLAUDE_CODE_SESSION_ID,CLAUDE_CODE_ENTRYPOINT,CLAUDE_CODE_EXECPATH,CLAUDE_CODE_MESSAGING_SOCKET,CLAUDE_CODE_MESSAGING_TOKEN,CLAUDECODE,CLAUDE_PID,CLAUDE_EFFORT. Denylist, not aCLAUDE*prefix wipe —CLAUDE_CONFIG_DIRand similar user settings must survive. One exported helper (sanitizeInheritedClaudeEnv(env)) used by every spawn path, with a unit test that pins the list.afx tower startscrubs its own env with the same helper before daemonizing, and prints one line when it detects it was launched from inside a Claude session.codev doctorcheck: read the running Tower daemon's env (ps -E -p <pid>on macOS,/proc/<pid>/environon Linux) and warn if the marker is present, with the exact restart command.ps -Ethat neither Tower nor the agent claude process carries the marker and the agent shows no transcript-off banner.Not in scope: cleaning up already-contaminated shellpers (forward-looking fix only).
waleedkadous commentedon Sep 5, 2026
On it! Working on a fix now.
Fix #1219: sanitize inherited CLAUDE_CODE_* env at every Tower spawn
Fix #1219: move getProcessesOnPort to a leaf module for the doctor check
[Bugfix #1219] docs: builder thread — investigate and fix
Fix #1219: sanitize the cron task env too (CMAP review)
Fix #1219: strip session-identity families, not the whole CLAUDE_CODE…
Fix #1219: doctor must check shellper sessions, not just the daemon
Fix #1219: pin per-site sanitizer counts, not just per-file presence
Fix #1219: two false-clean cases in the doctor check (CMAP review)
[Bugfix #1219] docs: builder thread — PR and CMAP rounds
Fix #1219: strip CLAUDE_PID (architect prescription, verified against…
[Bugfix #1219] docs: builder thread — verification incident and post-…
Merge pull request #1626 from cluesmith/builder/bugfix-1219