Claude prompt: only prepend on first turn

This commit is contained in:
Peter Steinberger
2025-11-27 03:53:13 +01:00
parent 8d995a8529
commit 9e6ad97cfb
2 changed files with 26 additions and 1 deletions

View File

@@ -91,6 +91,29 @@ describe("runCommandReply", () => {
expect(finalArgv.at(-1)).toContain("You are Clawd (Claude)");
});
it("omits identity prefix on resumed session when sendSystemOnce=true", async () => {
const captures: ReplyPayload[] = [];
const runner = makeRunner({ stdout: "ok" }, captures);
await runCommandReply({
reply: {
mode: "command",
command: ["claude", "{{Body}}"],
claudeOutputFormat: "json",
},
templatingCtx: noopTemplateCtx,
sendSystemOnce: true,
isNewSession: false,
isFirstTurnInSession: false,
systemSent: true,
timeoutMs: 1000,
timeoutSeconds: 1,
commandRunner: runner,
enqueue: enqueueImmediate,
});
const finalArgv = captures[0].argv as string[];
expect(finalArgv.at(-1)).not.toContain("You are Clawd (Claude)");
});
it("picks session resume args when not new", async () => {
const captures: ReplyPayload[] = [];
const runner = makeRunner({ stdout: "hi" }, captures);

View File

@@ -179,7 +179,9 @@ export async function runCommandReply(
let finalArgv = argv;
const isClaudeInvocation =
finalArgv.length > 0 && path.basename(finalArgv[0]) === CLAUDE_BIN;
if (isClaudeInvocation && finalArgv.length > 0) {
const shouldPrependIdentity =
isClaudeInvocation && !(sendSystemOnce && systemSent);
if (shouldPrependIdentity && finalArgv.length > 0) {
const bodyIdx = finalArgv.length - 1;
const existingBody = finalArgv[bodyIdx] ?? "";
finalArgv = [