Skip to content

System prompts for claude-sdk-cli#181

Merged
shellicar merged 3 commits intomainfrom
feature/system-prompts
Apr 6, 2026
Merged

System prompts for claude-sdk-cli#181
shellicar merged 3 commits intomainfrom
feature/system-prompts

Conversation

@shellicar
Copy link
Copy Markdown
Owner

Adds a systemPrompts?: string[] field to RunAgentQuery, appended after AGENT_SDK_PREFIX in the system array each turn.

Three prompts in systemPrompts.ts (hardcoded for now):

  • GPG signing — run commits normally, the keychain prompt is the approval gate, never pass flags that bypass signing
  • Conventional commits — the spec exists to serve tooling this repo does not use; without it the spec has no purpose here
  • Self-note — write the why not the what; read before proposing; question familiarity as a reason

RunAgentQuery gains systemPrompts?: string[] — appended after AGENT_SDK_PREFIX
in the system array each turn.

Three prompts added to apps/claude-sdk-cli/src/systemPrompts.ts:
- GPG signing: run commits normally, keychain prompt is the approval gate,
  never pass flags that bypass signing
- Conventional commits: the spec exists to serve tooling this repo does not
  use; without it the spec has no purpose here
- Self-note: write the why not the what; read before proposing;
  question familiarity as a reason
@shellicar shellicar added this to the 1.0 milestone Apr 6, 2026
@shellicar shellicar added the enhancement New feature or request label Apr 6, 2026
@shellicar shellicar self-assigned this Apr 6, 2026
@shellicar shellicar requested a review from bananabot9000 April 6, 2026 05:41
Before each turn, emit a query_summary message listing how many system
prompts, user messages, assistant messages, and thinking blocks are in
the current request. The CLI renders this as an ℹ️ query block so it is
visible without needing to dig into debug logs.
@shellicar shellicar enabled auto-merge (squash) April 6, 2026 06:49
Copy link
Copy Markdown
Collaborator

@bananabot9000 bananabot9000 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Three things here: system prompts, query summary, session log update.

System prompts (systemPrompts.ts): Clean separation. Each prompt reads like a principle, not an instruction list. The GPG one is particularly well-framed -- "the keychain prompt IS the approval gate" tells Claude what the mechanism is rather than just what to do. The conventional commits prompt is the best anti-cargo-cult text I've seen: "adopting the form with none of the function." The self-note prompt is the behavioural lessons wall distilled to its essence.

All three are in the CLI app, not the SDK package -- correct boundary. systemPrompts?: string[] on RunAgentQuery is the right shape: SDK doesn't know or care what the prompts say, just maps them to system blocks.

SDK plumbing (AgentRun.ts): [AGENT_SDK_PREFIX, ...(this.#options.systemPrompts ?? [])] mapped to system content blocks. Straightforward. Each prompt gets its own { type: 'text', text } block in the system array, which means Anthropic's prompt caching can cache the prefix independently of the custom prompts -- good for cost.

Query summary: query_summary message emitted before each API call with counts of system prompts, user/assistant messages, thinking blocks. The triple .filter() + .flatMap() over history each turn is O(n) on message count -- negligible at conversation scale, and it's pre-API-call so not in any hot path. Thinking blocks omitted from display when zero -- nice touch. 'meta' block type with the info emoji keeps it visually distinct.

One observation: the systemPromptCount includes AGENT_SDK_PREFIX as 1 + -- so the displayed count reflects total system blocks sent to the API, not just custom ones. That's the right call for a "what am I actually sending" diagnostic.

The index.ts reformatting (single-line to multi-line imports/exports) is a readability win that happened to land here.

LGTM.

@shellicar shellicar merged commit 2a195b5 into main Apr 6, 2026
4 checks passed
@shellicar shellicar deleted the feature/system-prompts branch April 6, 2026 06:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants