Keep Claude NODE_OPTIONS restore preload out of TMPDIR
Fixes #12022.
Claude's NODE_OPTIONS restore preload lived in $TMPDIR/cmux-claude-node-options/. Every Node child of a wrapped Claude session loads it through --require, so once macOS purges $TMPDIR under a long-lived session, each new Node child exits with MODULE_NOT_FOUND.
The preload now lives in ~/.cmuxterm/cmux-claude-node-options/restore-node-options.cjs, next to the other CLI shims (createTmuxCompatShimDirectory already uses ~/.cmuxterm/<name>). Both writers move:
Resources/bin/cmux-claude-wrapper(ensure_node_options_restore_module): directory is0700, symlinked directory or file is refused, and the module is written to a temp file in the same directory and renamed into place.CLI/cmux.swift(createClaudeNodeOptionsRestoreModule, used byclaude-teamsandomc): directory is created and kept at0700; the write goes through the existing atomicwriteShimIfChanged.
--require is quoted when the path contains whitespace, since NODE_OPTIONS splits on it and $HOME is no longer a system-chosen path.
This is a minimal re-cut of #12067 by @austinywang, which bundles this fix with unrelated agent-journal, cloud rename and CI changes. It leaves out #12067's legacy $TMPDIR module recreation and quoted-token parser.
Related, not fixed here: #14681. With the native (Mach-O) Claude Code binary the preload never runs, so the injected NODE_OPTIONS leaks to every child, and a sandboxed app that cannot read the preload crash-loops. Moving the file out of $TMPDIR does not change that: a sandbox cannot read ~/.cmuxterm either. The fix there is to skip the injection for non-Node claude binaries.
Validation
tests/test_claude_wrapper_node_options_survives_tmpdir_purge.py(ported from #12067, registered intests/test-execution.toml): launches the wrapper withHOMEcontaining a space, purges$TMPDIRwhile the fake Claude is alive, then starts a Node child.- d7a23bc7991 (test only): fails with
Error: Cannot find module '.../session-tmp/cmux-claude-node-options/restore-node-options.cjs', the #12022 symptom. - a1414162aca (fix): passes; the child restores the user's original
NODE_OPTIONSand the directory is0700.
- d7a23bc7991 (test only): fails with
tests/test_claude_wrapper_hooks.py: the old "unusableTMPDIRskips injection" case now expects injection from~/.cmuxterm; it and the other NODE_OPTIONS cases pass locally. Two subcommand-cache cases failed once under a load average of ~300 and passed on rerun, same as on main.bash -n Resources/bin/cmux-claude-wrapper.- The Swift change is not compiled locally (no local app builds on this machine); CI compiles
cmux-cli.
🤖 Generated with Claude Code
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.
Summary by cubic
Fixes Claude sessions failing with MODULE_NOT_FOUND once macOS purges $TMPDIR under long-lived sessions (issue #12022).
The restore preload every Node child loads via NODE_OPTIONS now lives in ~/.cmuxterm/cmux-claude-node-options/ instead of $TMPDIR.
- Both the bash wrapper and the Swift
claude-teams/omclaunchers write it there with 0700 permissions and atomic temp-and-rename. --requireis quoted when the path contains whitespace, and session resume now tokenizesNODE_OPTIONSthe way Node does so the quoted preload is stripped instead of leaving a broken fragment.- Adds a regression test that purges
$TMPDIRmid-session and verifies a Node child still restores the user's originalNODE_OPTIONS; a bypass-flag check dropped during that rewrite was restored.
Summary by CodeRabbit
- Bug Fixes
- Claude launches now retain user-provided Node.js options if temporary files are cleared during a session.
- Preload paths containing spaces are handled correctly, and unrelated Node.js options are preserved when resuming a Claude session.
- Restore files are kept in a private, restricted-access location under the home directory, so temporary-directory cleanup won’t interrupt launches.