Keep Claude NODE_OPTIONS restore shim out of TMPDIR
Fixes https://github.com/manaflow-ai/cmux/issues/12022.
Summary
- Reproduce the long-lived Claude failure by deleting the restore preload directory while a wrapped session is alive.
- Store the restore module atomically in cmux's persistent per-user
~/.cmuxterm/cmux-claude-node-options/directory instead of$TMPDIR. - Quote the
--requirepath for homes containing spaces and recreate inherited legacy$TMPDIRrestore modules when a wrapper/launcher still references them. - Apply the same durable lifecycle to the Swift
claude-teamsandomclaunchers, extracted into a budget-safe helper file. - Restore semantic agent-journal delivery after the
origin/mainmerge, including attention identity, event timestamps,stop_hook_active, and non-fabricating idle/state-change classifications. - Wire the helper into the
cmux-clitarget, remove the stale duplicate implementation, and expose only the three target-internal helpers needed across CLI extension files. - Preserve a truly absent
NODE_OPTIONSvalue when migrating an inherited legacy restore-only preload.
Trade-offs
- A single per-user restore module remains on disk for the lifetime of the cmux installation instead of one temp module per session; this removes the macOS temp purge lifecycle and avoids stale per-session files.
- If the durable per-user directory cannot be written, cmux skips the optional
NODE_OPTIONSinjection rather than falling back to another purgeable directory. - Legacy temp paths are recreated only when an existing launch environment still references them; new launches never point
NODE_OPTIONSat$TMPDIR. - The pure helper remains in the existing CLI target rather than moving into
CMUXAgentLaunch: it uses cmux-specific cache ownership, localization, and legacy-path migration policy, and the behavior-level harness already exercises the external contract. This avoids expanding a package API and avoids unrelated package migration while still wiring the source into the realcmux-clibuild. - The tagged cloud dogfood uses
CMUX_DEV_BACKEND_MODE=offbecause the optional backend provisioning endpoint returned a DNS failure; the app build and wrapper behavior remain cloud-built, and no local Xcode build is used.
Validation
python3 tests/test_claude_wrapper_node_options_survives_tmpdir_purge.py(passes)- Focused legacy restore regression from
tests/test_claude_wrapper_hooks.py(passes) bash scripts/check-pbxproj.sh(passes)bash scripts/lint-pbxproj-test-wiring.sh(passes)python3 -m py_compile tests/test_claude_wrapper_node_options_survives_tmpdir_purge.pypython3 -m json.tool Resources/Localizable.xcstringsbash -n Resources/bin/cmux-claude-wrappergit diff --check- Hosted semantic-delivery CI previously identified and this branch fixed: cross-file CLI access control, missing
CMUXCLI+ClaudeNodeOptions.swifttarget wiring, stale duplicate helper declarations, and semantic event argument ordering.
End-to-end verification
- Tagged cloud build
issue-12022-wrapper-shim-tmpdir-83684edcd9d7succeeded withCMUX_DEV_BACKEND_MODE=off. - The running tagged app exercised the real shim and wrapper through
CMUX_SURFACE_ID=surface:1: it installed the durable preload outsideTMPDIR, deleted the launch temp directory, started a Node child successfully, restored the originalNODE_OPTIONS, and loaded the original preload. - No local Xcode build or local XCUITest was used.
[!NOTE]
Medium Risk
Changes how Claude/Node processes inherit and restore NODE_OPTIONS plus broad agent-hook notification and cloud catalog merge logic, which can affect long-lived sessions and UI attention state if miswired.
Overview
Moves the Claude NODE_OPTIONS restore preload out of purgeable $TMPDIR into ~/.cmuxterm/cmux-claude-node-options/, with shared logic in CMUXCLI+ClaudeNodeOptions.swift and matching updates to cmux-claude-wrapper, claude-teams, and omc. The helper quotes paths safely, strips duplicate managed --require / heap flags, preserves truly absent original options, and can recreate legacy temp restore modules still referenced by an inherited environment.
Agent integration changes clear pane notifications when a turn resumes, dedupe repeated hook notifications, adjust journal kinds (e.g. approval responses as turnStarted), and restore semantic hook argument ordering plus a Codex post-tool pane-scoped clear_notifications fallback when attention identity is missing.
Cloud work adds SurfaceCatalog+CloudRenameReconciliation for optimistic workspace renames on the legacy versioned snapshot path, expands the cloud VM SSH bootstrap script (workspace/surface exports, scoped tmux sessions), and tweaks CodeRouter help/errors to reflect an installed-only CLI passthrough.
CI wires Node 20 into Depot/Xcode tests via TEST_RUNNER_CMUX_NODE_BINARY, runs a new tmpdir-purge regression, and grandfather two flaky determinism findings.
Reviewed by Cursor Bugbot for commit e177006ab996fcbc84698d0338f2cfaff409fb4e. Bugbot is set up for automated code reviews on this repo. Configure here.
Final verification
- Final pushed HEAD:
6820f8fa14. - Cloud build
issue-12022-wrapper-shim-tmpdir-83684edcd9d7compiled successfully remotely withCMUX_SKIP_ZIG_BUILD=1,CMUX_DEV_BACKEND_MODE=off, andRELOAD_CLOUD_FALLBACK_LOCAL=0. - The exact tagged runtime path was exercised on the previously built app: deleting the launch
$TMPDIRleft the wrapped Node child alive, preserved and restored the originalNODE_OPTIONS, and kept the durable restore preload under~/.cmuxterm/cmux-claude-node-options/.claude-teams --versionalso treated restore-only inherited options as absent and injected the durable preload plus heap flag. - No app product source changed after that runtime verification; later commits only adjust CI/test harness execution. The local artifact-install leg was blocked by the shared Mac reaching 99% disk usage, so no local build or XCUITest was run.
- This is a CLI/runtime change, not a visual UI change; screenshots are not applicable.
CI fixes and trade-offs
- Added Node 20 to both
test-depot.ymland the sharded app-host job inci.yml. - Passed the absolute Node executable through
TEST_RUNNER_CMUX_NODE_BINARY; Xcode strips ordinary environment variables from app-host test bundles, so a plainCMUX_NODE_BINARYwas insufficient. - Kept the OpenCode harness’s UUID isolation but rooted its temporary socket directory at
/tmp; the hosted runner’s longNSTemporaryDirectory()path exceeded macOS Unix-socket limits and surfaced as a misleadingEADDRINUSE. - Added two determinism allowlist entries for findings introduced by
origin/main; this preserves strict detection of new findings without claiming pre-existing main-branch findings are regressions. - The current-head CI runs are
34320675254(CI) and34320675520(Agent notification semantics); they are being rechecked before merge.
Verification commands
python3 tests/test_claude_wrapper_node_options_survives_tmpdir_purge.pypython3 tests/test_claude_wrapper_hooks.pybash scripts/check-pbxproj.shbash scripts/lint-pbxproj-test-wiring.shpython3 scripts/check-test-determinism.py --strictpython3 tests/test_ci_change_areas.pypython3 -m json.tool Resources/Localizable.xcstringsbash -n Resources/bin/cmux-claude-wrappergit diff --check