Skip to main content
When sending the same message through the Claude Agent SDK versus the Claude CLI (Claude Code), the system prompts accompanying these messages are fundamentally different. 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.

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: | Component | Description | Loading | |-----------|-------------|---------|| | Base System Prompt | Core instructions and behavior | Always (~269 tokens) | | Tool Instructions | 18+ builtin tools (Write, Read, Edit, Bash, TodoWrite, etc.) | Always | | Coding Guidelines | Code style, formatting rules, security practices | Always | | Safety Rules | Refusal rules, injection defense, harm prevention | Always | | Response Style | Tone, verbosity, explanation depth, emoji usage | Always | | Environment Context | Working directory, git status, platform info | Always | | Project Context | CLAUDE.md content, settings, hooks configuration | Conditional | | Subagent Prompts | Plan mode, Explore agent, Task agent | Conditional | | Security Review | Extended security instructions (~2,610 tokens) | Conditional |
  • 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: | Component | Description | Token Impact | |-----------|-------------|--------------|| | Essential Tool Instructions | Only tools explicitly provided | Minimal | | Basic Safety | Minimal safety instructions | Minimal |
  • 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

What Each Interface Sends

Example: “What is the capital of Norway?”

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?"

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

| Feature | CLI Default | SDK Default | SDK with Preset | |---------|-------------|-------------|-----------------|| | Tool instructions | ✅ Full | ❌ Minimal | ✅ Full | | Coding guidelines | ✅ Yes | ❌ No | ✅ Yes | | Safety rules | ✅ Yes | ❌ Basic | ✅ Yes | | CLAUDE.md auto-load | ✅ Yes | ❌ No | ❌ No* | | Project context | ✅ Automatic | ❌ No | ❌ No* |
*Requires explicit settingSources: ["project"] configuration

Output Consistency Guarantees

Critical Finding: NO Determinism GuaranteedThe Claude Messages API does not provide a seed parameter for reproducibility. This is a fundamental architectural limitation.

Factors Preventing Identical Output

| Factor | Description | Controllable? | |--------|-------------|---------------|| | Different system prompts | CLI vs SDK have different defaults | ✅ Yes (with configuration) | | Floating-point arithmetic | Parallel hardware quirks | ❌ No | | MoE routing | Mixture-of-Experts architecture variations | ❌ No | | Batching/scheduling | Cloud infrastructure differences | ❌ No | | Numeric precision | Inference engine variations | ❌ No | | Model snapshots | Version updates/changes | ❌ No |

Temperature and Sampling

Even with temperature=0.0 (greedy decoding):

Achieving Maximum Consistency

To get the closest possible identical outputs between SDK and CLI:
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
}
Still Not GuaranteedEven with perfectly matching configurations:
  • Output may differ between runs
  • Output may differ between SDK and CLI
  • No seed parameter exists to force reproducibility

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

  • Build applications robust to minor output variations
  • Use structured outputs and validation
  • Cache results when possible
  • Use structured outputs with JSON schema validation
  • Combine with deterministic logic and validation
  • Consider multiple generations with consensus
systemPrompt: {
  type: "preset",
  preset: "claude_code",
  append: "Your additional instructions"
},
settingSources: ["project", "user"]

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
Note: 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.

Summary

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.
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

Build docs developers (and LLMs) love