fix: remove flag+empty-value pairs to prevent --permission-mode arg parsing error

The claude-agent-sdk generates --setting-sources with an empty string value
when settingSources defaults to []. Simply filtering empty strings (as before)
leaves --setting-sources without a value, causing the next flag --permission-mode
to be consumed as its value, resulting in "Invalid setting source" exit code 1.

Fix: remove the entire flag+empty-value pair instead of just the empty string.

Also includes: reset completed session on resume (mac sleep/resume fix).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
JOUNGWOOK KWON
2026-04-16 19:34:14 +09:00
parent 79170f007a
commit 8536eeb60a
+17 -1
View File
@@ -416,7 +416,23 @@ export function createPidCapturingSpawn(sessionDbId: number) {
// causing subsequent flags to be consumed as values for the preceding flag.
// The Agent SDK may produce empty-string args (e.g., settingSources defaults to []
// which joins to ""). Node preserves these, but Bun drops them, breaking CLI parsing.
const args = spawnOptions.args.filter(arg => arg !== '');
//
// FIX: Simply filtering empty strings has the same effect as Bun dropping them —
// it leaves the preceding flag (e.g. --setting-sources) without a value, causing
// the next flag (e.g. --permission-mode) to be consumed as that value.
// Instead, we must remove the entire flag+empty-value pair.
const args: string[] = [];
for (let i = 0; i < spawnOptions.args.length; i++) {
const arg = spawnOptions.args[i];
if (arg === '') continue; // skip standalone empty strings
// If this is a --flag followed by an empty string, skip both (remove the pair entirely)
if (arg.startsWith('--') && i + 1 < spawnOptions.args.length && spawnOptions.args[i + 1] === '') {
i++; // skip the empty value too
continue;
}
args.push(arg);
}
const child = useCmdWrapper
? spawn('cmd.exe', ['/d', '/c', spawnOptions.command, ...args], {