Setup guide · Essentials
Install Claude Code
Claude Code installed, signed in with your own Claude subscription, and answering scripted claude -p calls with JSON output.
Claude Code is the agent you'll use for nearly every hands-on exercise. You run it in an empty folder and paste the exercise prompt in, and many exercise projects also call it from code as claude -p when they need a model. Both run on your Claude subscription, so you don't need an API key for them.
Before you start
- A paid Claude plan: Pro, Max or Ultra on your personal claude.ai account. The free plan doesn't include Claude Code.
- OS: macOS 13+, Windows 10 1809+, Ubuntu 20.04+, Debian 10+ or Alpine 3.19+, with 4 GB of RAM or more.
- Windows: you can run Claude Code natively or inside WSL. Native Windows works without extra software. If you install Git for Windows, Claude Code uses Git Bash for shell commands; without it, it uses PowerShell.
1. Install Claude Code
Use the native installer. It updates itself in the background.
macOS, Linux, WSL
curl -fsSL https://claude.ai/install.sh | bashWindows PowerShell
irm https://claude.ai/install.ps1 | iexWindows CMD
curl -fsSL https://claude.ai/install.cmd -o install.cmd && install.cmd && del install.cmdThe installer shows no progress while it downloads. When it finishes, open a new terminal window and check the install:
claude --versionIf you'd rather use Homebrew, run brew install --cask claude-code. That cask follows the stable channel and doesn't update itself, so run brew upgrade claude-code from time to time.
2. Sign in with your subscription
Start Claude Code in any folder:
mkdir claude-sandbox && cd claude-sandbox
claudeA browser window opens. Sign in with your claude.ai account and approve access. The terminal shows Login successful. If the browser doesn't open, press c to copy the login URL and paste it into a browser yourself.
You can also sign in from the shell without starting a session, and check which credential is active:
claude auth login
claude auth status --text3. Run a first session
Inside the session, type a request in plain English:
Create a file hello.py that prints the current date, then run it.Claude Code shows each file edit and shell command and asks for permission before running it. Useful commands inside a session:
| Command | What it does |
|---|---|
/help | List commands |
/status | Show the account, model and credential in use |
/model | Switch model |
/mcp | Show connected MCP servers |
/resume | Reopen an earlier conversation |
/login, /logout | Switch or re-authenticate accounts |
For exercises, start each one in a fresh, empty folder so earlier files don't confuse it.
4. Use Claude Code headless with claude -p
-p (or --print) runs one prompt non-interactively, prints the answer and exits. It reads stdin too:
claude -p "Explain what a context window is in two sentences."
cat notes.txt | claude -p "Summarise these notes as five bullets."JSON output
--output-format json returns one JSON object. The answer is in result, and there's also session_id, usage and an estimated total_cost_usd. On a subscription that figure is only an estimate; you aren't billed per call.
claude -p "Name three sorting algorithms." --output-format json | jq -r '.result'Structured output with a schema
Add --json-schema with a JSON Schema, and the validated object comes back in structured_output:
claude -p "Extract the people and dates from: Ada met Charles on 5 June 1833." \
--output-format json \
--json-schema '{"type":"object","properties":{"people":{"type":"array","items":{"type":"string"}},"dates":{"type":"array","items":{"type":"string"}}},"required":["people","dates"]}' \
| jq '.structured_output'If Claude can't produce valid output, for example because it declined, the response has no structured_output field. Check that it's there before you use it.
Controlling tools
In a -p run nobody can answer a permission prompt, so any tool call that needs approval is denied. Two flags control this:
--tools "Read,Grep"limits which built-in tools exist at all.--tools ""turns them all off, which makesclaude -pa pure text-in, text-out model call.--allowedTools "Read,Edit,Bash(npm test *)"lets the listed tools run without asking. Rules use permission syntax:Bash(git diff *)allows any command starting withgit diff.
Other flags exercises use: --model sonnet (aliases sonnet, opus, haiku), --max-turns 3, --append-system-prompt "…" and --no-session-persistence.
Calling it from code
Exercise projects run claude -p as a subprocess and parse the JSON:
import json, subprocess
def ask(prompt: str) -> str:
out = subprocess.run(
["claude", "-p", prompt, "--output-format", "json", "--tools", ""],
capture_output=True, text=True, check=True,
)
return json.loads(out.stdout)["result"]
print(ask("Reply with the single word: ready"))Passing arguments as a list avoids shell quoting, which matters for JSON schemas on Windows.
Check it works
claude -p "Reply with the single word: ready" --output-format json | jq -r '.result'Expected output:
readyWithout jq, drop the pipe and look for "result":"ready" in the JSON.
Troubleshooting
claude: command not found after installing. Open a new terminal. If it still fails, the install directory (~/.local/bin on macOS and Linux) isn't on your PATH; claude doctor and the install troubleshooting page show the fix.
'irm' is not recognized or The token '&&' is not a valid statement separator. You ran the PowerShell command in CMD, or the other way round. Use the command for the shell you're in.
claude -p says you're not logged in, or charges show up on an API or OpenRouter account. Run claude auth status. If authMethod is api_key, or /status inside a session shows an OpenRouter or Ollama base URL, unset ANTHROPIC_API_KEY, ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN, then run claude auth login.
A -p run stops without doing the work. A tool it needed was denied. Add it to --allowedTools, or run the task interactively once to see which permission it asks for.
Going further
- MCP servers in Claude Code
- OpenRouter or a local model? for exercises whose code calls a model API directly
- Point Claude Code at a local model
Sources
- Advanced setupDocs · AnthropicSystem requirements, the native installer for each OS, updates and uninstalling.
- Run Claude Code programmaticallyDocs · AnthropicEverything about `claude -p`, including JSON output, `--json-schema` and auto-approving tools.
- AuthenticationDocs · AnthropicHow subscription login works and the order in which Claude Code picks a credential.
- CLI referenceDocs · AnthropicEvery flag, including `--tools`, `--allowedTools`, `--model` and `--max-turns`.
Exercises that use this
- Watch the agent loop in Claude CodeAgent Foundations · What is an agent?
- Run the same task through the Agent SDKAgent Foundations · What is an agent?
- Build a register tool and give it to Claude CodeAgent Foundations · Tools and the agent-computer interface
- Turn the tool into an MCP serverAgent Foundations · Tools and the agent-computer interface
- Measure context and move procedure into a skillAgent Foundations · Context engineering
- Isolate lease reading in a subagentAgent Foundations · Context engineering
- Produce and verify grounded title reportsAgent Foundations · Structured outputs and grounding
- Same report through the Agent SDKAgent Foundations · Structured outputs and grounding
- Build a chain with a code gate, then add routingAgent Foundations · Workflow patterns
- Orchestrator-workers and an evaluator loop with subagentsAgent Foundations · Workflow patterns
- Build and run a 10-case evalAgent Foundations · Risk and first evals
- Block outbound actions with a hookAgent Foundations · Risk and first evals
- Build a fleet compute and token cost modelInfrastructure for Agents · Where agents run
- Measure active CPU against wall timeInfrastructure for Agents · Where agents run
- Build and attack a local code runnerInfrastructure for Agents · Sandboxes for agent code
- Egress allowlists and credential brokering in a microVMInfrastructure for Agents · Sandboxes for agent code
- Build a toy durable execution engineInfrastructure for Agents · Durable execution engines
- A completion workflow on Temporal with signals and a deadlineInfrastructure for Agents · Durable execution engines
- Simulate leases, redelivery and fairnessInfrastructure for Agents · Queues, schedules and background jobs
- An idempotent consumer against a local queueInfrastructure for Agents · Queues, schedules and background jobs
- Build and test a session store adapterInfrastructure for Agents · State, sessions and checkpoints
- Find every copy: an erasure dry runInfrastructure for Agents · State, sessions and checkpoints
- Row-level security that fails closedInfrastructure for Agents · Secrets, identity and tenant isolation
- A per-firm credential proxyInfrastructure for Agents · Secrets, identity and tenant isolation
- Simulate fallbacks, correlation and budgetsInfrastructure for Agents · AI gateways
- A self-hosted gateway with per-firm keysInfrastructure for Agents · AI gateways
- Build a paired eval gate for CIInfrastructure for Agents · Environments and delivery for agents
- Roll out a prompt by matter, with shadow runsInfrastructure for Agents · Environments and delivery for agents
- Inventory the memory of an agent you useAgent Memory · Memory types for agents
- Measure fact drift across repeated compactionAgent Memory · The context window as working memory
- Re-inject matter state after compaction in Claude CodeAgent Memory · The context window as working memory
- Build and attack a per-matter memory-tool handlerAgent Memory · Files, skills and memory tools
- Write a skill that survives compactionAgent Memory · Files, skills and memory tools
- Build a miniature knowledge-update benchmarkAgent Memory · Memory frameworks and benchmarks
- Do due diligence on a memory frameworkAgent Memory · Memory frameworks and benchmarks
- Build a scoped memory store with provenance-based deletionAgent Memory · Scoping, retention and erasure
- Build the write-update-forget pipeline for a 12-week matterAgent Memory · Write, update and forget
- Design a reviewed consolidation jobAgent Memory · Write, update and forget
- Build shared matter state and attack itAgent Memory · Shared state and memory poisoning
- Red-team persistence across sessionsAgent Memory · Shared state and memory poisoning
- Run a memory ablation on synthetic mattersAgent Memory · Evaluating memory
- Model memory cost for your session patternAgent Memory · Evaluating memory
- One task, two modes of the same harnessBuilding Agents with Claude and eve · Choosing a harness
- Guardrails in Claude Code: tool, permissions, hooksBuilding Agents with Claude and eve · The Claude Agent SDK
- Run the title-review agent on the SDKBuilding Agents with Claude and eve · The Claude Agent SDK
- Build and break a contract-pack reader in eveBuilding Agents with Claude and eve · Agents as files with eve
- Make a side-effecting tool safe to replayBuilding Agents with Claude and eve · Agents as files with eve
- An enquiries skill and a search-reviewer subagent in Claude CodeBuilding Agents with Claude and eve · Skills and subagents
- Port the skill and subagent to eveBuilding Agents with Claude and eve · Skills and subagents
- A solicitor-approved send in eveBuilding Agents with Claude and eve · Human approval for high-stakes actions
- The same gate in the Agent SDKBuilding Agents with Claude and eve · Human approval for high-stakes actions
- Route auth and tenant isolation, checkedBuilding Agents with Claude and eve · Shipping agents
- Deploy to Vercel with a deployable modelBuilding Agents with Claude and eve · Shipping agents
- Build and tune a page triageDocument Ingestion Pipelines · What a real case file contains
- Unpack and deduplicate a matter's emailDocument Ingestion Pipelines · What a real case file contains
- Run a four-way parser bake-offDocument Ingestion Pipelines · Parsing: text layers to vision models
- Self-host an open parsing modelDocument Ingestion Pipelines · Parsing: text layers to vision models
- Verify tables and plan references in codeDocument Ingestion Pipelines · Tables, plans and handwriting
- Measure two-reader agreement on handwritingDocument Ingestion Pipelines · Tables, plans and handwriting
- Extract lease terms with page-verified evidenceDocument Ingestion Pipelines · Structured extraction at scale
- Compare long-document strategiesDocument Ingestion Pipelines · Structured extraction at scale
- Build a crash-safe ingest workflowDocument Ingestion Pipelines · Durable ingest pipelines
- Simulate retry granularityDocument Ingestion Pipelines · Durable ingest pipelines
- Build incremental re-ingestion with early cutoffDocument Ingestion Pipelines · Re-ingestion, versioning and backfills
- Build and measure a hybrid PII detectorDocument Ingestion Pipelines · PII detection and redaction
- Redact a PDF and prove itDocument Ingestion Pipelines · PII detection and redaction
- Build an ingest eval harnessDocument Ingestion Pipelines · Ingest evals and the hand-off
- Specify and test the retrieval hand-offDocument Ingestion Pipelines · Ingest evals and the hand-off
- Write an eval charter for one agentEvaluating and Scoring Agents · Why evals, and their vocabulary
- Run your first repeated trials in Claude CodeEvaluating and Scoring Agents · Why evals, and their vocabulary
- Build a trace viewer and a counted taxonomyEvaluating and Scoring Agents · Error analysis from traces
- Generate a balanced 24-task datasetEvaluating and Scoring Agents · Error analysis from traces
- Write five eve evals for the enquiries agentEvaluating and Scoring Agents · Code-based graders
- Mutation-test your gradersEvaluating and Scoring Agents · Code-based graders
- Build a Claude Code judge and measure its position biasEvaluating and Scoring Agents · LLM-as-judge
- Wire a judge into your eve evalsEvaluating and Scoring Agents · LLM-as-judge
- Calibrate your Claude Code judge against your own labelsEvaluating and Scoring Agents · Calibrating judges
- Pick a t.judge threshold and correct a reported rateEvaluating and Scoring Agents · Calibrating judges
- Implement and stress-test a byte-level BPE tokenizerLLMs for Engineers · Tokens and embeddings
- Probe embedding geometryLLMs for Engineers · Tokens and embeddings
- Implement attention and verify it against PyTorchLLMs for Engineers · Attention, step by step
- Find an induction head in GPT-2LLMs for Engineers · Attention, step by step
- Build a block and verify parameter counts against real modelsLLMs for Engineers · The transformer block
- Prove RoPE is relative, numericallyLLMs for Engineers · The transformer block
- Fit your own scaling law on a laptopLLMs for Engineers · Pretraining and scaling laws
- Base model versus assistant on conveyancing promptsLLMs for Engineers · Pretraining and scaling laws
- Build a verifiable reward and simulate GRPO advantagesLLMs for Engineers · Post-training an assistant
- Measure and catch hallucinations in lease extractionLLMs for Engineers · Sampling and hallucination
- Simulate decoding strategiesLLMs for Engineers · Sampling and hallucination
- Watch prompt caching hit and missLLMs for Engineers · Context windows, KV cache and caching
- Implement a KV cache and measure the speed-upLLMs for Engineers · Context windows, KV cache and caching
- Run an effort sweep on conveyancing calculationsLLMs for Engineers · Reasoning models and extended thinking
- Self-consistency versus more thinkingLLMs for Engineers · Reasoning models and extended thinking
- Run a model bake-off on title-register extractionLLMs for Engineers · Choosing and comparing models
- Add an open-weight model to the bake-offLLMs for Engineers · Choosing and comparing models
- Build a per-matter cost model from usage logsLLM Cost Engineering · Token economics of an agent fleet
- Calibrate the model against real token countsLLM Cost Engineering · Token economics of an agent fleet
- Simulate cache hits and costs for a matterLLM Cost Engineering · Prompt caching as system design
- Measure warm-then-fan-out on your subscriptionLLM Cost Engineering · Prompt caching as system design
- Simulate context policies with and without cachingLLM Cost Engineering · Trimming and compacting context
- Test what compaction forgetsLLM Cost Engineering · Trimming and compacting context
- Build a resumable batch extraction jobLLM Cost Engineering · Batch, flex and fast tiers
- Measure a cost-quality curve and test a cascadeLLM Cost Engineering · Cost-quality curves, routing and cascades
- Does a learned router beat self-confidence?LLM Cost Engineering · Cost-quality curves, routing and cascades
- Distil a clause tagger and measure the gapLLM Cost Engineering · Distilling into small models
- Build a serving cost calculatorLLM Cost Engineering · Self-hosting break-even
- Benchmark an engine yourselfLLM Cost Engineering · Self-hosting break-even
- Build a cost ledger with budgets and alertsLLM Cost Engineering · Attribution, budgets and alerts
- Single agent versus lead plus subagents in Claude CodeProduction Agent Systems · Multi-agent systems
- Build and break an idempotent outboxProduction Agent Systems · Durable, long-running agents
- Red-team and harden a pack-reading agent in Claude CodeProduction Agent Systems · Security and prompt injection
- Build a hash-chained audit log and a supervision samplerProduction Agent Systems · Compliance and auditability
- Audit hook and retention policy in eveProduction Agent Systems · Compliance and auditability
- Trace Claude Code runs and build a per-matter budget reportProduction Agent Systems · Observability and cost
- Session budgets and redacted exports in eveProduction Agent Systems · Observability and cost
- Build a paired upgrade gate for Claude Code runsProduction Agent Systems · Continuous improvement
- An eval-gated model swap in eve CIProduction Agent Systems · Continuous improvement
- Rewrite the searches summariser and measure itPrompt and Context Optimisation · Prompting current Claude models
- Effort versus prose instructionsPrompt and Context Optimisation · Prompting current Claude models
- Run an example ablation on the enquiries drafterPrompt and Context Optimisation · Choosing few-shot examples
- Three disciplined iterations on the enquiries drafterPrompt and Context Optimisation · Eval-driven prompt iteration
- Measure prompt fragilityPrompt and Context Optimisation · Eval-driven prompt iteration
- Build a small reflective optimiser on claude -pPrompt and Context Optimisation · Automatic prompt optimisation
- DSPy: MIPROv2 versus GEPAPrompt and Context Optimisation · Automatic prompt optimisation
- Build a skill-trigger eval in Claude CodePrompt and Context Optimisation · Optimising tools, instructions and skills
- Transcript-driven tool improvementPrompt and Context Optimisation · Optimising tools, instructions and skills
- Build and break an experiment analysisPrompt and Context Optimisation · Prompt registries and online tests
- Wire a registry with labels and trace linkagePrompt and Context Optimisation · Prompt registries and online tests
- Migrate the summariser behind a regression suitePrompt and Context Optimisation · Model migration and regression suites
- Gate prompt changes in CIPrompt and Context Optimisation · Model migration and regression suites
- Structure-aware and contextual chunking, measuredRetrieval and Knowledge Systems · Chunking structured documents
- Build and run a labelled query setRetrieval and Knowledge Systems · Measuring retrieval
- Verify citations end to end (stretch)Retrieval and Knowledge Systems · Measuring retrieval
- Build and measure a hybrid pipelineRetrieval and Knowledge Systems · Hybrid search and reranking
- Compare single-shot, grep-only and full agentic retrievalRetrieval and Knowledge Systems · Agentic retrieval
- Build scoped matter tools with the Agent SDK (stretch)Retrieval and Knowledge Systems · Agentic retrieval
- Build a graph from verified records, and compare with an LLM-extracted oneRetrieval and Knowledge Systems · Knowledge graphs and GraphRAG
- Trial GraphRAG on a global question (stretch)Retrieval and Knowledge Systems · Knowledge graphs and GraphRAG
- Compare long context, RAG and a router on your questionsRetrieval and Knowledge Systems · Long context versus RAG
- Simulate the three buckets and the cache cliffScaling AI Systems · Rate limits and quotas
- Log rate-limit headers and cache usageScaling AI Systems · Rate limits and quotas
- Build and test a token-aware, fair limiterScaling AI Systems · Concurrency and flow control
- Adaptive concurrency under a moving limitScaling AI Systems · Concurrency and flow control
- Simulate a retry storm and stop itScaling AI Systems · Retries, backoff and overload
- A circuit breaker with deadlines in front of a flaky mockScaling AI Systems · Retries, backoff and overload
- Simulate the month-end rushScaling AI Systems · Backpressure, load shedding and batching
- A deferrable-work batch pipeline against a mockScaling AI Systems · Backpressure, load shedding and batching
- Instrument and speed up a real agent turnScaling AI Systems · Latency engineering for agents
- When is speculation worth it?Scaling AI Systems · Latency engineering for agents
- Measure a semantic cache as a classifierScaling AI Systems · Response caching and failover
- Simulate failover with a cold cacheScaling AI Systems · Response caching and failover
- Load test a fleet slice against a mockScaling AI Systems · Load testing and capacity planning
- Write a capacity plan for doubling the fleetScaling AI Systems · Load testing and capacity planning
- Measure what parsing prose costsSystem One Models with Jev · What a System One model is
- Build a calibration toolkit and test it on two modelsSystem One Models with Jev · Calibrated probabilities
- Build and test your first requestSystem One Models with Jev · Your first Jev request
- Log the model that answered, and catch an alias moveSystem One Models with Jev · Your first Jev request
- Build an enquiry question set and an option-order checkSystem One Models with Jev · Choice, Score and Noul
- Route through a taxonomy with chained Choices and beam searchSystem One Models with Jev · Choice, Score and Noul
- Build a state builder and a reads-then-computes pipelineSystem One Models with Jev · State and decomposition
- Red-team your questions with injected instructionsSystem One Models with Jev · State and decomposition
- Build a cost-derived confidence routerSystem One Models with Jev · Routing on confidence
- Build a draft-then-gate reply pipelineSystem One Models with Jev · Jev alongside LLMs
- Build an eval harness for System One answersSystem One Models with Jev · Evaluating Jev on your data