From 22b30e2c5bc998af4de76bf3d384cb60e3b4bcec Mon Sep 17 00:00:00 2001 From: Ross Date: Tue, 27 Jan 2026 11:02:30 +0000 Subject: [PATCH] fix(cli): always pass system prompt to Claude CLI on resume Claude CLI loses its system message context when resuming a session unless the system prompt is explicitly passed on every call. Previously, we only sent it on the first call (`systemPromptWhen: "first"`), which caused resumed sessions to lose their system prompt context. Changes: - Switch from `--append-system-prompt` to `--system-prompt`: the former only appends to an existing system prompt, while the latter completely replaces it (per Claude CLI docs). This ensures consistent behavior. - Change `systemPromptWhen` from "first" to "always" so the system prompt is sent on every CLI invocation, including resumes. - Remove the redundant `!params.useResume` guard in `buildCliArgs()` - the `resolveSystemPromptUsage()` function already handles the "when to include system prompt" logic via `systemPromptWhen`. --- src/agents/cli-backends.ts | 4 ++-- src/agents/cli-runner/helpers.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/agents/cli-backends.ts b/src/agents/cli-backends.ts index 1efc3b0c4..e32d112cb 100644 --- a/src/agents/cli-backends.ts +++ b/src/agents/cli-backends.ts @@ -44,9 +44,9 @@ const DEFAULT_CLAUDE_BACKEND: CliBackendConfig = { sessionArg: "--session-id", sessionMode: "always", sessionIdFields: ["session_id", "sessionId", "conversation_id", "conversationId"], - systemPromptArg: "--append-system-prompt", + systemPromptArg: "--system-prompt", systemPromptMode: "append", - systemPromptWhen: "first", + systemPromptWhen: "always", clearEnv: ["ANTHROPIC_API_KEY", "ANTHROPIC_API_KEY_OLD"], serialize: true, usageFields: { diff --git a/src/agents/cli-runner/helpers.ts b/src/agents/cli-runner/helpers.ts index 50891959b..f245e5b3a 100644 --- a/src/agents/cli-runner/helpers.ts +++ b/src/agents/cli-runner/helpers.ts @@ -438,7 +438,7 @@ export function buildCliArgs(params: { if (!params.useResume && params.backend.modelArg && params.modelId) { args.push(params.backend.modelArg, params.modelId); } - if (!params.useResume && params.systemPrompt && params.backend.systemPromptArg) { + if (params.systemPrompt && params.backend.systemPromptArg) { args.push(params.backend.systemPromptArg, params.systemPrompt); } if (!params.useResume && params.sessionId) {