GenAI Systems Lab Open interactive version →
AI Engineering 8 min read

How Claude Works: Constitutional AI, 200K Context, and What Makes It Different

Anthropic's Constitutional AI training approach, the Opus/Sonnet/Haiku family, extended thinking, and where Claude outperforms competing frontier models.

Claude is Anthropic's AI assistant — and the model underneath it was built differently from other frontier models. Not just different architecture choices, but a fundamentally different philosophy about how to align an AI system with human values. That difference shows up in how Claude behaves at the edges: when asked something ambiguous, something borderline, or something where the right answer is genuinely hard.

[Video: Andrej Karpathy — Intro to Large Language Models (the best 1-hour overview of how frontier models like Claude are built from pretraining through fine-tuning)]

The model family (as of 2025)

ModelBest forContext windowRelative speed
Claude Opus 4Complex reasoning, research, long-form analysis, hard agentic tasks200K tokensSlowest / highest quality
Claude Sonnet 4Balanced performance and speed — most production use cases200K tokensFast
Claude Haiku 4High-volume, latency-sensitive, cost-sensitive tasks200K tokensFastest / most cost-effective

The naming convention: Opus > Sonnet > Haiku in capability (and cost). Sonnet is the workhorse for most production deployments. Haiku is what you use when you need Claude at scale. Opus is for when quality matters more than cost.

Constitutional AI: how Claude is aligned

Most AI assistants are aligned via RLHF — human labellers rank model outputs, a reward model learns human preferences, and the model is trained via RL to maximise that reward. Anthropic's Claude uses a different approach: Constitutional AI (CAI).

In CAI, the model is given a set of explicit principles — the 'constitution' — and trained to critique and revise its own outputs against those principles. Instead of relying entirely on human labellers to identify bad outputs, the model learns to reason about whether its outputs satisfy the principles directly.

This is why Claude often explains its reasoning when declining a request rather than just refusing. It's trained to be transparent about the principle it's applying — which makes it more useful for developers who need to understand where the guardrails are.

200K context window — and the lost-in-the-middle caveat

200K tokens (~150,000 words, ~500 pages) is a genuine capability advantage. You can pass an entire codebase, a full legal agreement, or a large corpus of documents in a single call. But there's a catch: attention doesn't distribute evenly across a long context.

Research (and empirical testing) consistently shows that information in the middle of a very long context is attended to less reliably than information near the start or end. For retrieval tasks in long-context RAG, this means your most relevant passage should be at the top or bottom of the injected context — not buried in the middle.

Prompt caching — Claude's cost advantage at scale

Claude's API supports prompt caching: if you mark a prefix of your prompt as cacheable, subsequent requests that share that prefix pay only 10% of the input token cost for the cached portion. For applications with long system prompts or large shared context (documentation, policy docs, codebase), this can reduce input costs by 70–90%.

import anthropic

client = anthropic.Anthropic()

# Cache a long system prompt — pay full cost first time, 10% on subsequent calls
response = client.messages.create(
    model="claude-sonnet-4-6",
    max_tokens=1024,
    system=[
        {
            "type": "text",
            "text": open("large_system_prompt.txt").read(),  # e.g. 10K tokens
            "cache_control": {"type": "ephemeral"}           # mark for caching
        }
    ],
    messages=[{"role": "user", "content": "Summarise the key risks."}]
)

# On subsequent calls with the same system prompt prefix:
# First 10K tokens cost 10% of normal input price — cache hit
print(response.usage.cache_read_input_tokens)   # tokens read from cache
print(response.usage.cache_creation_input_tokens)  # tokens written to cache

Extended thinking — Claude's reasoning mode

Claude's extended thinking feature allows the model to generate an internal chain of reasoning (visible in the API response as thinking blocks) before producing its final answer. This is most useful for: complex multi-step reasoning, hard math or coding problems, and tasks where explicit step-by-step planning improves quality.

Extended thinking increases latency significantly (seconds to minutes for complex problems) and consumes more tokens. Use it for hard reasoning tasks where quality matters more than speed — not for simple Q&A or classification.

What Claude is distinctively good at vs. peers

CapabilityClaude's strengthNotes
Instruction followingVery strong on complex, multi-constraint instructionsHandles competing requirements better than most
Long-context extractionStrong — 200K window with good mid-context recallUse positional anchoring for best results
Code generationTop-tier — consistently competitive on SWE-benchStrong on multi-file, real-repo tasks
Safety refusalsContextual — explains reasoning, not just blocksMore useful for developers than binary refusals
Tool / agentic useSpecifically optimised for multi-step tool useClaude 3+ models trained for agentic contexts
Mathematical reasoningStrong with extended thinking enabledUse thinking mode for hard math problems

The Anthropic API — quick start

import anthropic

client = anthropic.Anthropic()  # uses ANTHROPIC_API_KEY env var

# Basic generation
msg = client.messages.create(
    model="claude-sonnet-4-6",
    max_tokens=1024,
    system="You are an expert in production AI systems.",
    messages=[{"role": "user", "content": "What is prompt caching?"}]
)
print(msg.content[0].text)

# With tool use
tools = [{
    "name": "get_weather",
    "description": "Get current weather for a location",
    "input_schema": {
        "type": "object",
        "properties": {"location": {"type": "string"}},
        "required": ["location"]
    }
}]

msg = client.messages.create(
    model="claude-sonnet-4-6",
    max_tokens=1024,
    tools=tools,
    messages=[{"role": "user", "content": "What's the weather in London?"}]
)
# If stop_reason == "tool_use", extract tool call and execute

Compare Claude models in Playground →: Run the same prompt across Claude Haiku, Sonnet, and Opus and see quality and speed differences live.

Try it interactively

GenAI Systems Lab is a free platform for AI engineers — configure real failure modes, break things, and build the judgment that gets you hired.

Open GenAI Systems Lab →