From 0adc0ed7a6d0959acdb483a98ee3c44b6225bce4 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Tue, 25 Nov 2025 06:41:27 +0100 Subject: [PATCH] claude: prefix prompt with Clawd identity --- src/auto-reply/claude.ts | 2 ++ src/auto-reply/reply.ts | 12 ++++++++++-- src/index.core.test.ts | 7 +++++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/auto-reply/claude.ts b/src/auto-reply/claude.ts index 5da400ae1..26500733a 100644 --- a/src/auto-reply/claude.ts +++ b/src/auto-reply/claude.ts @@ -3,6 +3,8 @@ import { z } from "zod"; // Preferred binary name for Claude CLI invocations. export const CLAUDE_BIN = "claude"; +export const CLAUDE_IDENTITY_PREFIX = + "You are Clawd (Claude) running on the user's Mac via warelay. Be concise (<=1000 chars)."; function extractClaudeText(payload: unknown): string | undefined { // Best-effort walker to find the primary text field in Claude JSON outputs. diff --git a/src/auto-reply/reply.ts b/src/auto-reply/reply.ts index bea1492e9..9d1fe12e0 100644 --- a/src/auto-reply/reply.ts +++ b/src/auto-reply/reply.ts @@ -2,7 +2,7 @@ import crypto from "node:crypto"; import path from "node:path"; import type { MessageInstance } from "twilio/lib/rest/api/v2010/account/message.js"; -import { CLAUDE_BIN, parseClaudeJson } from "./claude.js"; +import { CLAUDE_BIN, CLAUDE_IDENTITY_PREFIX, parseClaudeJson } from "./claude.js"; import { applyTemplate, type MsgContext, @@ -270,9 +270,17 @@ const mediaNote = ]; } } - const finalArgv = argv; + let finalArgv = argv; const isClaudeInvocation = finalArgv.length > 0 && path.basename(finalArgv[0]) === CLAUDE_BIN; + if (isClaudeInvocation && finalArgv.length > 0) { + const bodyIdx = finalArgv.length - 1; + const existingBody = finalArgv[bodyIdx] ?? ""; + finalArgv = [ + ...finalArgv.slice(0, bodyIdx), + [CLAUDE_IDENTITY_PREFIX, existingBody].filter(Boolean).join("\n\n"), + ]; + } logVerbose(`Running command auto-reply: ${finalArgv.join(" ")}`); const started = Date.now(); try { diff --git a/src/index.core.test.ts b/src/index.core.test.ts index 83d3ef643..0aa286e36 100644 --- a/src/index.core.test.ts +++ b/src/index.core.test.ts @@ -389,7 +389,8 @@ describe("config and templating", () => { const argv = runSpy.mock.calls[0][0]; expect(argv[0]).toBe("claude"); - expect(argv.at(-1)).toBe("hi"); + expect(argv.at(-1)).toContain("You are Clawd (Claude)"); + expect(argv.at(-1)).toMatch(/hi$/); // The helper should auto-add print and output format flags without disturbing the prompt position. expect(argv.includes("-p") || argv.includes("--print")).toBe(true); const outputIdx = argv.findIndex( @@ -454,7 +455,9 @@ describe("config and templating", () => { ); expect(result?.text).toBe("Sure! What's up?"); - }); + const argv = runSpy.mock.calls[0][0]; + expect(argv.at(-1)).toContain("You are Clawd (Claude)"); + }); it("serializes command auto-replies via the queue", async () => { let active = 0;