Skip to content

Claude Agent SDK vs Claude CLI: System Prompts and Output Consistency

Executive Summary

When sending the same message (e.g., "What is the capital of Norway?") through the Claude Agent SDK versus the Claude CLI (Claude Code), the system prompts accompanying these messages are fundamentally different. The CLI uses a modular system prompt architecture (~269 base tokens with additional context conditionally loaded based on features), while the SDK uses a minimal prompt by default. There is no guarantee of identical output between the two, even with matching configurations, due to the absence of a seed parameter and inherent non-determinism in Claude's architecture.

1. System Prompt Comparison

Claude CLI (Claude Code)

The Claude CLI uses a modular system prompt architecture with a ~269-token base prompt, with additional context conditionally loaded:

ComponentDescriptionLoading
Base System PromptCore instructions and behaviorAlways (~269 tokens)
Tool Instructions18+ builtin tools (Write, Read, Edit, Bash, TodoWrite, etc.)Always
Coding GuidelinesCode style, formatting rules, security practicesAlways
Safety RulesRefusal rules, injection defense, harm preventionAlways
Response StyleTone, verbosity, explanation depth, emoji usageAlways
Environment ContextWorking directory, git status, platform infoAlways
Project ContextCLAUDE.md content, settings, hooks configurationConditional
Subagent PromptsPlan mode, Explore agent, Task agentConditional
Security ReviewExtended security instructions (~2,610 tokens)Conditional

Key Characteristics:

  • Modular architecture with 110+ system prompt strings loaded conditionally
  • Base prompt is modest (~269 tokens), total varies by features activated
  • Includes extensive security and injection defense layers
  • Automatically loads CLAUDE.md files in the working directory
  • Session-persistent context in interactive mode

Claude Agent SDK

The Agent SDK uses a minimal system prompt by default containing:

ComponentDescriptionToken Impact
Essential Tool InstructionsOnly tools explicitly providedMinimal
Basic SafetyMinimal safety instructionsMinimal

Key Characteristics:

  • No coding guidelines or style preferences by default
  • No project context unless explicitly configured
  • No extensive tool descriptions
  • Requires explicit configuration to match CLI behavior

2. What Each Interface Sends

Example: "What is the capital of Norway?"

Via Claude CLI

System Prompt: [modular, ~269+ base tokens]
  Base system prompt (~269 tokens)
  Tool instructions (Write, Read, Edit, Bash, Grep, Glob, etc.)
  Git safety protocols
  Code reference guidelines
  Professional objectivity instructions
  Security and injection defense rules
  Environment context (OS, directory, date)
  CLAUDE.md content (if present) [conditional]
  MCP tool descriptions (if configured) [conditional]
  Plan/Explore mode prompts [conditional]
  Session/conversation context

User Message: "What is the capital of Norway?"

Via Claude Agent SDK (Default)

System Prompt: [minimal]
  Essential tool instructions (if any tools provided)
  Basic operational context

User Message: "What is the capital of Norway?"

Via Agent SDK (with claude_code preset)

typescript
const response = await query({
  prompt: "What is the capital of Norway?",
  options: {
    systemPrompt: {
      type: "preset",
      preset: "claude_code"
    }
  }
});
System Prompt: [modular, matches CLI]
  Full Claude Code system prompt
  Tool instructions
  Coding guidelines
  Safety rules

// NOTE: Still does NOT include CLAUDE.md unless settingSources is configured

3. Customization Methods

Claude CLI Customization

MethodCommandEffect
Append to promptclaude -p "..." --append-system-prompt "..."Adds instructions while preserving defaults
Replace promptclaude -p "..." --system-prompt "..."Completely replaces the system prompt
Project contextCLAUDE.md fileAutomatically loaded, persistent
Output styles/output-style [name]Apply predefined response styles

Agent SDK Customization

MethodConfigurationEffect
Custom promptsystemPrompt: "..."Replaces default entirely (loses tools)
Preset with appendsystemPrompt: { type: "preset", preset: "claude_code", append: "..." }Preserves CLI functionality + custom instructions
CLAUDE.md loadingsettingSources: ["project"]Loads project-level instructions
Output stylessettingSources: ["user"] or settingSources: ["project"]Loads saved output styles

Configuration Comparison Table

FeatureCLI DefaultSDK DefaultSDK with Preset
Tool instructionsFullMinimalFull
Coding guidelinesYesNoYes
Safety rulesYesBasicYes
CLAUDE.md auto-loadYesNoNo*
Project contextAutomaticNoNo*

*Requires explicit settingSources: ["project"] configuration

4. Output Consistency Guarantees

Critical Finding: NO Determinism Guaranteed

WARNING

The Claude Messages API does not provide a seed parameter for reproducibility. This is a fundamental architectural limitation.

Factors Preventing Identical Output

FactorDescriptionControllable?
Different system promptsCLI vs SDK have different defaultsYes (with configuration)
Floating-point arithmeticParallel hardware quirksNo
MoE routingMixture-of-Experts architecture variationsNo
Batching/schedulingCloud infrastructure differencesNo
Numeric precisionInference engine variationsNo
Model snapshotsVersion updates/changesNo

Temperature and Sampling

Even with temperature=0.0 (greedy decoding):

5. Achieving Maximum Consistency

To get the closest possible identical outputs between SDK and CLI:

Agent SDK Configuration

typescript
import Anthropic from "@anthropic-ai/sdk";

const client = new Anthropic();

// Option 1: Use claude_code preset
const response = await client.messages.create({
  model: "claude-sonnet-4-20250514",
  max_tokens: 1024,
  // Match CLI system prompt as closely as possible
  system: "Your exact system prompt matching CLI",
  messages: [
    { role: "user", content: "What is the capital of Norway?" }
  ],
  // Use greedy decoding for maximum consistency
  temperature: 0
});

// Option 2: With Agent SDK query function
import { query } from "@anthropic-ai/agent-sdk";

for await (const message of query({
  prompt: "What is the capital of Norway?",
  options: {
    systemPrompt: {
      type: "preset",
      preset: "claude_code"
    },
    temperature: 0,
    model: "claude-sonnet-4-20250514",
    // Load project context like CLI does
    settingSources: ["project"]
  }
})) {
  // Process response
}

CLI Configuration

bash
# Match the SDK configuration as closely as possible
claude -p "What is the capital of Norway?" \
  --model claude-sonnet-4-20250514 \
  --temperature 0

Still Not Guaranteed

Even with perfectly matching configurations:

  • Output may differ between runs
  • Output may differ between SDK and CLI
  • No seed parameter exists to force reproducibility

6. Practical Implications

When to Use Each Interface

Use CaseRecommended InterfaceReason
Interactive developmentClaude CLIFull tool suite, project context
Programmatic integrationAgent SDKFine-grained control, embedding
Consistent API responsesAgent SDK + custom promptMore control over system prompt
Batch processingAgent SDKBetter for automation pipelines
One-off tasksClaude CLIFaster setup, immediate context

Design Recommendations

  1. Don't rely on bit-perfect reproducibility

    • Build applications robust to minor output variations
    • Use structured outputs and validation
  2. For production pipelines requiring consistency:

    • Cache results when possible
    • Use structured outputs with JSON schema validation
    • Combine with deterministic logic and validation
    • Consider multiple generations with consensus
  3. For matching CLI behavior in SDK:

    typescript
    systemPrompt: {
      type: "preset",
      preset: "claude_code",
      append: "Your additional instructions"
    },
    settingSources: ["project", "user"]

7. System Prompt Token Impact

ConfigurationArchitectureNotes
SDK (minimal)Minimal defaultOnly essential tool instructions
SDK (claude_code preset)Modular (~269+ base)Matches CLI, varies by features
CLI (default)Modular (~269+ base)Additional context loaded conditionally
CLI (with MCP tools)Modular + MCPMCP tool descriptions add significant tokens

INFO

Claude Code uses a modular architecture with 110+ system prompt strings. The base prompt is ~269 tokens, with individual components ranging from 18 to 2,610 tokens depending on features activated.

Implication: The SDK's minimal default gives you more context for your actual task, but at the cost of Claude Code's full capabilities.

8. Summary Table

AspectClaude CLIAgent SDK (Default)Agent SDK (Preset)
System promptModular (~269+ base)MinimalModular (matches CLI)
Tools included18+ builtinOnly if provided18+ builtin
CLAUDE.md auto-loadYesNoNo (needs config)
Coding guidelinesYesNoYes
Safety rulesFullBasicFull
Temperature controlYesYesYes
Determinism guaranteeNoNoNo
Identical outputs?N/ANo (vs CLI)Closer, but no

9. Conclusion

Q: What system prompts accompany the same message in SDK vs CLI?

The CLI uses a modular system prompt architecture with a ~269-token base prompt and 110+ conditionally-loaded components (tool instructions, coding guidelines, safety rules, project context). The SDK uses a minimal default with only essential tool instructions, though it can be configured to match CLI behavior using the claude_code preset.

Q: Is there a guarantee of identical output?

No. Even with matching system prompts, identical inputs, and temperature=0, there is no guarantee of identical outputs due to:

  • Absence of a seed parameter in Claude's API
  • Floating-point arithmetic variations
  • Infrastructure-level non-determinism
  • Model architecture (Mixture-of-Experts) routing variations

Recommendation

Design systems to be robust to output variations rather than relying on deterministic behavior. For consistency-critical applications, use structured outputs, caching, and validation layers.

Sources