fix(claude-cli): --resume for continuing turns (reusing --session-id errored on turn 2)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
root
2026-06-01 22:18:13 +10:00
parent c73be6681f
commit 1e8bbca2a5
2 changed files with 11 additions and 1 deletions

View File

@@ -59,6 +59,7 @@ import { createInterface } from 'readline';
* @param {function} [opts.onEvent] Called for each normalized event
* @param {string} [opts.claudeExe] Path or name of claude binary (default: CLAUDE_EXE env or 'claude')
* @param {string[]} [opts.tools] Exclusive available-tools allowlist (--tools); removes built-ins
* @param {boolean} [opts.resume] Continue an existing session (--resume) vs create (--session-id)
* @param {string} [opts.home] If set, overrides HOME in child env (for service-user creds)
* @param {string} [opts.cwd] Working directory for the child process
* @param {number} [opts.timeoutMs] Milliseconds before SIGTERM (default: 600000)
@@ -73,6 +74,7 @@ export async function runClaudeTurn(opts) {
mcpConfigPath,
allowedTools = [],
tools = [],
resume = false,
onEvent,
claudeExe = process.env.CLAUDE_EXE || 'claude',
home = process.env.VOID_CLAUDE_HOME,
@@ -89,7 +91,9 @@ export async function runClaudeTurn(opts) {
'--verbose',
'--include-partial-messages',
'--append-system-prompt', systemPrompt,
'--session-id', sessionId,
// First turn creates the session (--session-id); later turns MUST continue
// it with --resume (reusing --session-id on an existing session errors).
...(resume ? ['--resume', sessionId] : ['--session-id', sessionId]),
];
if (mcpConfigPath) {