Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/selfhost/ai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function toCliPrompt(options: AiRunOptions, systemAppend: string | undefined): s
.join("\n\n");
}

function prependCodexSystemAppend(prompt: string, systemAppend: string | undefined): string {
function prependCliSystemAppend(prompt: string, systemAppend: string | undefined): string {
return systemAppend
? `ADDITIONAL SYSTEM INSTRUCTIONS:\n${systemAppend}\n\n${prompt}`
: prompt;
Expand Down Expand Up @@ -736,10 +736,9 @@ export function createClaudeCodeAi(parentEnv: Record<string, string | undefined>
OTEL_METRIC_EXPORT_INTERVAL: parentEnv.OTEL_METRIC_EXPORT_INTERVAL,
});
const systemAppend = normalizedSystemAppend(options);
const prompt = toCliPrompt(options, systemAppend);
const prompt = prependCliSystemAppend(toCliPrompt(options, systemAppend), systemAppend);
const spawn = spawnImpl ?? (await defaultSpawn());
const args = ["--print", "--output-format", "json", "--model", claudeModel, "--permission-mode", "plan", "--effort", effort, "--disallowedTools", "Bash,Edit,Write,WebFetch,WebSearch"];
if (systemAppend) args.push("--append-system-prompt", systemAppend);
attempted = true;
const { stdout, code, stderr, timedOut } = await spawn(
"claude",
Expand Down Expand Up @@ -808,7 +807,7 @@ export function createCodexAi(
await authCheckImpl(parentEnv);
const env = codexCliEnv(parentEnv);
const systemAppend = normalizedSystemAppend(options);
const prompt = prependCodexSystemAppend(toCliPrompt(options, systemAppend), systemAppend);
const prompt = prependCliSystemAppend(toCliPrompt(options, systemAppend), systemAppend);
const spawn = spawnImpl ?? (await defaultSpawn());
const args = ["exec", "--json", "--skip-git-repo-check", "--sandbox", "read-only"];
if (codexModel) args.push("--model", codexModel);
Expand Down
7 changes: 4 additions & 3 deletions test/unit/selfhost-ai.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,7 @@ describe("subscription CLI helpers + fail-safe", () => {
expect(seen[seen.indexOf("--effort") + 1]).toBe("medium");
});

it("Claude Code passes systemAppend through --append-system-prompt and strips the duplicate stdin copy (#1471)", async () => {
it("Claude Code keeps systemAppend out of argv and supplies it through stdin once (#1471)", async () => {
const systemAppend = "REPOSITORY REVIEW INSTRUCTIONS: Follow async-error conventions.";
let seen: string[] = [];
let capturedInput = "";
Expand All @@ -995,10 +995,11 @@ describe("subscription CLI helpers + fail-safe", () => {
],
systemAppend,
});
expect(seen[seen.indexOf("--append-system-prompt") + 1]).toBe(systemAppend);
expect(seen).not.toContain("--append-system-prompt");
expect(seen).not.toContain(systemAppend);
expect(capturedInput).toContain("Base system.");
expect(capturedInput).toContain("Review this diff.");
expect(capturedInput).not.toContain(systemAppend);
expect(countOccurrences(capturedInput, systemAppend)).toBe(1);

await createClaudeCodeAi({ CLAUDE_CODE_OAUTH_TOKEN: "t" }, cap).run("", {
prompt: "Review this diff.",
Expand Down
Loading