Keep the remote daemon's Claude restore preload out of TMPDIR

Merged
TE
2mo ago
+95-32

Follow-up to #14814 (#12022).

#14814 moved Claude's NODE_OPTIONS restore preload from $TMPDIR to ~/.cmuxterm/cmux-claude-node-options/ on the Mac side. cmuxd-remote still wrote it under os.TempDir(), so remote Claude sessions keep the #12022 failure: once the OS purges the temp directory, every new Node child exits with MODULE_NOT_FOUND.

  • daemon/remote/cmd/cmuxd-remote/agent_launch.go: ensureClaudeNodeOptionsRestoreModule writes to ~/.cmuxterm/cmux-claude-node-options/restore-node-options.cjs, same rules as the wrapper: absolute home required, symlinked directory or module refused, directory 0700, atomic write through writeShimIfChanged. mergeNodeOptions quotes --require when the path has whitespace. The old random MkdirTemp directory guarded against same-UID tampering in a shared /tmp; a 0700 directory in the user's home gives the same protection without being purged.
  • CLI/cmux.swift: createClaudeNodeOptionsRestoreModule falls back to NSHomeDirectory() when HOME is empty or relative and refuses a symlinked directory or module, matching the wrapper. Callers already skip injection when it throws.

Validation

  • go test ./cmd/cmuxd-remote -run 'NodeOptions' and go vet ./cmd/cmuxd-remote pass locally. agent_launch_temp_test.go now checks the home path (with a space in it), 0700, stable reuse with a separate TMPDIR, the quoted --require, and symlink refusal.
  • The Swift change is not compiled locally (no local app builds on this machine); CI compiles cmux-cli.

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.


Summary by cubic

Moves the remote daemon's Claude NODE_OPTIONS restore preload from $TMPDIR to ~/.cmuxterm/cmux-claude-node-options/, fixing the MODULE_NOT_FOUND failures that occurred once the OS purged the temp directory during long-lived remote Claude sessions.

  • The daemon now matches the macOS wrapper's rules: absolute HOME required, symlinked directory or module refused, directory mode 0700, atomic write via writeShimIfChanged.
  • The restore module no longer deletes itself on load, which would break concurrent launches that share the file.
  • mergeNodeOptions quotes --require when the path contains whitespace.
  • The CLI writer now falls back to NSHomeDirectory() when HOME is empty or relative and refuses symlinked paths, matching the wrapper.

Summary by CodeRabbit

  • Bug Fixes
    • Claude restore support now falls back to the system home directory when the configured home path is not absolute, and reports an error if no valid absolute path is available.
    • Restore files use a consistent, private user directory with restricted access across launches. Symlinked restore locations are rejected.
    • Launch configuration correctly handles restore paths containing spaces, tabs, or newlines.