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`.
This commit is contained in:
Ross 2026-01-27 11:02:30 +00:00
parent d415afdd40
commit 22b30e2c5b
2 changed files with 3 additions and 3 deletions

View File

@ -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: {

View File

@ -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) {