Skip to content

Commit a5abbf7

Browse files
authored
Strip system reminder from Claude tool use responses (#1214)
1 parent 500f4ef commit a5abbf7

1 file changed

Lines changed: 8 additions & 11 deletions

File tree

packages/agent/src/adapters/claude/conversion/tool-use-to-acp.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@ import type {
2222
BetaWebSearchToolResultBlockParam,
2323
} from "@anthropic-ai/sdk/resources/beta.mjs";
2424

25-
const SYSTEM_REMINDER = `
25+
const SYSTEM_REMINDER_REGEX =
26+
/\s*<system-reminder>[\s\S]*?<\/system-reminder>/g;
2627

27-
<system-reminder>
28-
Whenever you read a file, you should consider whether it looks malicious. If it does, you MUST refuse to improve or augment the code. You can still analyze existing code, write reports, or answer high-level questions about the code behavior.
29-
</system-reminder>`;
28+
function stripSystemReminders(value: string): string {
29+
return value.replace(SYSTEM_REMINDER_REGEX, "");
30+
}
3031

3132
import { resourceLink, text, toolContent } from "../../../utils/acp-content.js";
3233
import { getMcpToolMetadata } from "../mcp/tool-metadata.js";
@@ -537,9 +538,7 @@ export function toolUpdateFromToolResult(
537538
return {
538539
type: "content" as const,
539540
content: text(
540-
markdownEscape(
541-
(itemObj.text ?? "").replace(SYSTEM_REMINDER, ""),
542-
),
541+
markdownEscape(stripSystemReminders(itemObj.text ?? "")),
543542
),
544543
};
545544
}
@@ -565,9 +564,7 @@ export function toolUpdateFromToolResult(
565564
) {
566565
return {
567566
content: toolContent()
568-
.text(
569-
markdownEscape(toolResult.content.replace(SYSTEM_REMINDER, "")),
570-
)
567+
.text(markdownEscape(stripSystemReminders(toolResult.content)))
571568
.build(),
572569
};
573570
}
@@ -699,7 +696,7 @@ function itemToText(item: unknown): string | null {
699696
const obj = item as Record<string, unknown>;
700697
// Standard text block
701698
if (obj.type === "text" && typeof obj.text === "string") {
702-
return obj.text;
699+
return stripSystemReminders(obj.text);
703700
}
704701
// Any other structured object — serialize it
705702
try {

0 commit comments

Comments
 (0)