Skip to content
Closed
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
015814a
test: cover claude node options restore path cleanup
austinywang May 12, 2026
bf0f982
fix: keep claude node options restore module persistent
austinywang May 12, 2026
292802f
Merge remote-tracking branch 'origin/main' into issue-3463-node-optio…
austinywang May 12, 2026
4f36117
fix: handle empty home for claude restore module
austinywang May 12, 2026
e4755ab
test: cover inherited claude node options preload cleanup
austinywang May 12, 2026
6a45f51
fix: strip inherited claude node options preloads
austinywang May 12, 2026
502e4a7
test: cover remote claude node options restore cleanup
austinywang May 12, 2026
d85a52e
test: cover stale claude passthrough node options cleanup
austinywang May 13, 2026
cae98a6
fix: strip stale claude node options before passthrough
austinywang May 13, 2026
ce8f6a0
test: cover whitespace home claude restore fallback
austinywang May 13, 2026
bf7ee7c
fix: ignore whitespace home for claude restore path
austinywang May 13, 2026
8ed76be
refactor: share claude node options walker
austinywang May 14, 2026
6fbdc44
Merge remote-tracking branch 'origin/main' into issue-3463-node-optio…
austinywang May 17, 2026
af8113e
fix: preserve user claude heap options
austinywang May 17, 2026
d79e31c
fix: update claude wrapper heap test callsite
austinywang May 17, 2026
bcebd60
fix: skip whitespace home for claude node options
austinywang May 17, 2026
7d9cfc9
Merge branch 'main' of https://github.com/manaflow-ai/cmux into issue…
austinywang May 19, 2026
7fb07e2
fix: align restore home whitespace filtering
austinywang May 19, 2026
ac29259
Merge branch 'main' of https://github.com/manaflow-ai/cmux into issue…
austinywang May 19, 2026
1d88efd
Merge remote-tracking branch 'origin/main' into issue-3463-node-optio…
austinywang May 19, 2026
9c71c85
Merge remote-tracking branch 'origin/main' into issue-3463-node-optio…
austinywang May 22, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 104 additions & 32 deletions CLI/cmux.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13367,9 +13367,10 @@ struct CMUXCLI {
unsetenv("CMUX_ORIGINAL_NODE_OPTIONS")
return
}
if let existing = processEnvironment["NODE_OPTIONS"] {
if let existing = processEnvironment["NODE_OPTIONS"],
let originalNodeOptions = normalizedNodeOptionsForRestore(existing) {
setenv("CMUX_ORIGINAL_NODE_OPTIONS_PRESENT", "1", 1)
setenv("CMUX_ORIGINAL_NODE_OPTIONS", normalizedNodeOptionsForRestore(existing), 1)
setenv("CMUX_ORIGINAL_NODE_OPTIONS", originalNodeOptions, 1)
} else {
setenv("CMUX_ORIGINAL_NODE_OPTIONS_PRESENT", "0", 1)
unsetenv("CMUX_ORIGINAL_NODE_OPTIONS")
Expand Down Expand Up @@ -13411,12 +13412,42 @@ struct CMUXCLI {
}

private func createClaudeNodeOptionsRestoreModule() throws -> URL {
let root = URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true)
.appendingPathComponent("cmux-claude-node-options", isDirectory: true)
try FileManager.default.createDirectory(at: root, withIntermediateDirectories: true, attributes: nil)
let restoreModuleURL = root.appendingPathComponent("restore-node-options.cjs", isDirectory: false)
try writeShimIfChanged(Self.claudeNodeOptionsRestoreModule, to: restoreModuleURL)
return restoreModuleURL
var candidates: [URL] = []
let environment = ProcessInfo.processInfo.environment
let homePath: String = {
guard let rawHome = environment["HOME"] else {
return NSHomeDirectory()
}
let trimmedHome = rawHome.trimmingCharacters(in: .whitespacesAndNewlines)
return trimmedHome.isEmpty ? NSHomeDirectory() : trimmedHome
}()
// The NODE_OPTIONS helpers below use whitespace tokenization, so use
// the TMPDIR fallback when HOME would require quote-aware parsing.
if !homePath.isEmpty,
homePath.rangeOfCharacter(from: .whitespacesAndNewlines) == nil {
candidates.append(
URL(fileURLWithPath: homePath, isDirectory: true)
.appendingPathComponent(".claude", isDirectory: true)
.appendingPathComponent("cmux", isDirectory: true)
)
}
candidates.append(
URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true)
.appendingPathComponent("cmux-claude-node-options", isDirectory: true)
)

var lastError: Error?
for root in candidates {
do {
try FileManager.default.createDirectory(at: root, withIntermediateDirectories: true, attributes: nil)
let restoreModuleURL = root.appendingPathComponent("restore-node-options.cjs", isDirectory: false)
try writeShimIfChanged(Self.claudeNodeOptionsRestoreModule, to: restoreModuleURL)
return restoreModuleURL
} catch {
lastError = error
}
}
throw lastError ?? CocoaError(.fileWriteUnknown)
}

private func runClaudeTeams(
Expand Down Expand Up @@ -15360,9 +15391,10 @@ struct CMUXCLI {
unsetenv("CMUX_ORIGINAL_NODE_OPTIONS")
return
}
if let existing = processEnvironment["NODE_OPTIONS"] {
if let existing = processEnvironment["NODE_OPTIONS"],
let originalNodeOptions = normalizedNodeOptionsForRestore(existing) {
setenv("CMUX_ORIGINAL_NODE_OPTIONS_PRESENT", "1", 1)
setenv("CMUX_ORIGINAL_NODE_OPTIONS", normalizedNodeOptionsForRestore(existing), 1)
setenv("CMUX_ORIGINAL_NODE_OPTIONS", originalNodeOptions, 1)
} else {
setenv("CMUX_ORIGINAL_NODE_OPTIONS_PRESENT", "0", 1)
unsetenv("CMUX_ORIGINAL_NODE_OPTIONS")
Expand Down Expand Up @@ -18960,48 +18992,88 @@ struct CMUXCLI {
}

private func cleanedNodeOptions(_ existing: String?) -> String {
walkNodeOptions(existing).joined(separator: " ")
}

private func normalizedNodeOptionsForRestore(_ existing: String) -> String? {
let joined = walkNodeOptions(existing)
.joined(separator: " ")
.trimmingCharacters(in: .whitespacesAndNewlines)
return joined.isEmpty ? nil : joined
}

private func walkNodeOptions(_ existing: String?) -> [String] {
let tokens = (existing ?? "")
.split(whereSeparator: \.isWhitespace)
.map(String.init)
guard !tokens.isEmpty else { return "" }
guard !tokens.isEmpty else { return [] }

var filtered: [String] = []
var index = 0
var shouldDropInjectedHeapCap = false
while index < tokens.count {
let token = tokens[index]
if token == "--max-old-space-size" {
index += min(2, tokens.count - index)
if shouldDropInjectedHeapCap, isInjectedNodeHeapCap(tokens, index: index) {
index += nodeHeapCapWidth(tokens, index: index)
shouldDropInjectedHeapCap = false
continue
}
shouldDropInjectedHeapCap = false

if isRequireOption(token), index + 1 < tokens.count,
isCmuxNodeOptionsRestoreModulePath(tokens[index + 1]) {
index += 2
shouldDropInjectedHeapCap = true
continue
}
if token.hasPrefix("--max-old-space-size=") {
if let path = inlineRequireOptionPath(token),
isCmuxNodeOptionsRestoreModulePath(path) {
index += 1
shouldDropInjectedHeapCap = true
continue
}
if token == "--max-old-space-size", index + 1 < tokens.count {
filtered.append("--max-old-space-size=\(tokens[index + 1])")
index += 2
continue
}
filtered.append(token)
index += 1
}
return filtered.joined(separator: " ")
return filtered
}

private func normalizedNodeOptionsForRestore(_ existing: String) -> String {
let tokens = existing
.split(whereSeparator: \.isWhitespace)
.map(String.init)
guard !tokens.isEmpty else { return "" }
private func isRequireOption(_ token: String) -> Bool {
token == "--require" || token == "-r"
}

var normalized: [String] = []
var index = 0
while index < tokens.count {
let token = tokens[index]
if token == "--max-old-space-size", index + 1 < tokens.count {
normalized.append("--max-old-space-size=\(tokens[index + 1])")
index += 2
continue
}
normalized.append(token)
index += 1
private func inlineRequireOptionPath(_ token: String) -> String? {
for prefix in ["--require=", "-r="] where token.hasPrefix(prefix) {
return String(token.dropFirst(prefix.count))
}
return nil
}

private func isCmuxNodeOptionsRestoreModulePath(_ value: String) -> Bool {
let trimmed = value.trimmingCharacters(in: CharacterSet(charactersIn: "'\""))
guard URL(fileURLWithPath: trimmed).lastPathComponent == "restore-node-options.cjs" else {
return false
}
return trimmed.contains("/cmux-") || trimmed.contains("/.claude/cmux/")
}

private func isInjectedNodeHeapCap(_ tokens: [String], index: Int) -> Bool {
guard index < tokens.count else { return false }
let token = tokens[index]
if token == "--max-old-space-size" {
return index + 1 < tokens.count && tokens[index + 1] == "4096"
}
return normalized.joined(separator: " ")
return token == "--max-old-space-size=4096"
}

private func nodeHeapCapWidth(_ tokens: [String], index: Int) -> Int {
guard index < tokens.count else { return 1 }
return tokens[index] == "--max-old-space-size" ? min(2, tokens.count - index) : 1
}

// MARK: - Codex hooks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public enum AgentLaunchEnvironmentPolicy {
guard URL(fileURLWithPath: trimmed).lastPathComponent == "restore-node-options.cjs" else {
return false
}
return trimmed.contains("/cmux-")
return trimmed.contains("/cmux-") || trimmed.contains("/.claude/cmux/")
}

private static func isInjectedNodeHeapCap(_ tokens: [String], index: Int) -> Bool {
Expand Down
Loading
Loading