refactor: pass envOverrides via tmux export instead of disk write#74
Conversation
CLAUDE_CODE_EFFORT_LEVEL (and any CLAUDE_CODE_* / OPENCODE_* key) now flows:
UI dropdown → POST /api/sessions { envOverrides }
→ new Session({ envOverrides })
→ this._envOverrides
→ tmux-manager.buildEnvExports appends `export KEY=<shellescape(VALUE)>`
Previously the API wrote envOverrides to <case>/.claude/settings.local.json, which
created stale state (UI dropdown disagreeing with disk) and polluted user project
directories. Now envOverrides are ephemeral spawn-time state, preserved across
respawnPane cycles via this._envOverrides and across server restart via
SessionState.envOverrides in state.json.
Also removes the now-unused updateCaseEnvVars import from session-routes.ts.
Resolved conflict in src/web/public/session-ui.js by keeping this PR's buildEnvOverrides() helper — it already covers both CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS (this PR) and CLAUDE_CODE_EFFORT_LEVEL (added in Ark0N#73), so the master-side inline block is fully replaced. Also fixed test/session-manager.test.ts MockSession to add a getEnvOverridesForPersist() stub — without it, SessionManager.updateSessionState's new call breaks 19 tests with "TypeError: session.getEnvOverridesForPersist is not a function". Verified: typecheck, lint, format:check, build, and test/{session-manager,session-state,tmux-manager,tmux-restart-recovery}.test.ts all pass. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Thanks for this — the refactor is well-thought-out and addresses a real wart (silent writes into user case dirs). The Two things I had to handle before merging:
Verified locally: typecheck, lint, format:check, build, and the four most-relevant test files ( Merging now. 🙏 |
Summary
Before this change,
POST /api/sessionspersistedenvOverrides(e.g.CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS) to<case>/.claude/settings.local.jsonso Claude CLI would pick them up on spawn. That had two problems: UI dropdown state could drift from the file on disk, and the backend was silently writing into user project directories as a side-effect of opening a session.This refactor makes envOverrides ephemeral spawn-time state:
respawnPanecycles viasession._envOverridesSessionState.envOverridesinstate.jsonsession-ui.js#buildEnvOverrides(caseSettings, globalSettings)as the single source of truth for the payloadupdateCaseEnvVarsimport fromsession-routes.ts(now unused)Benefits
.claude/settings.local.jsonfiles in user project directoriesTest plan
agentTeamsenabled → tmux pane seesCLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1in env~/.codeman/state.jsoncontainsenvOverridesfor each session, restored on server restart<case>/.claude/settings.local.jsontriggered by session creationnpm run typecheck/npm run lint/npm run buildpass