Part 8: Building on Claude
Building on Claude: Code, Agent SDK and the cloud
A vendor-specific field guide for teams whose stack is Claude
In short
Pick the lowest Claude layer that does the job, and bind it with permissions, fail-closed hooks and managed settings rather than instructions.
Key ideas
- Messages API for fixed paths, Agent SDK inside your service, Claude Code for repositories, Managed Agents when hosting is the hard part
- Policy hooks are synchronous command or http hooks with onFailure set to block; the sandbox bounds shell commands
- Cost and throughput share levers: a stable cache prefix, batch for offline work, routing by effort, per-run budget caps
A summary only. The reasoning, examples, checklist and what to do on Monday are in the chapter. Read it in the book
0.05x
cache-read price on Opus 5.5 and Sonnet 5.5
50%
Batch API price vs standard
Inside the chapter
- 1The Claude stack map (as of late 2026)
- 2Decision guide: which layer to build on
- 3Claude Code as a production agent harness
- 4Claude in the cloud
- 5Cost and reliability on Claude
- 6Security on Claude
- 7Reference setups
Try it: which layer stops this call?
Score: 0 / 7
The chapter's .claude/settings.json in a CI run with --permission-mode dontAsk: allow npm run and git commit, deny git push, .env and secrets, and a Bash PreToolUse hook with onFailure set to block. Pick what happens to each call.
Item 1 of 7
Bash: git push origin main
Show the answers
Bash: git push origin main
Answer: Deny rule stops it. Matches Bash(git push *). Rules evaluate deny, then ask, then allow, and deny applies in every mode, including bypass.
Bash: npm run test, and the hook passes
Answer: Runs (allow rule). Matches Bash(npm run *). The hook ran first and found nothing to block, so the allow rule lets it run.
Read: ./.env
Answer: Deny rule stops it. Read(./.env) is denied. Keep secrets out of reach, and prefer a proxy that injects credentials outside the agent.
Bash: curl to an unknown site
Answer: Denied: it would prompt in dontAsk. No rule matches, so it would prompt. dontAsk denies anything that would prompt; it is intended for locked-down CI.
Bash: npm run build, and the hook script times out
Answer: Policy hook stops it. Hooks fail open by default. With onFailure set to block, a crashed or timed-out policy hook blocks the call.
Bash: git commit -m wip, and the hook exits with code 2
Answer: Policy hook stops it. Exit code 2 blocks the action and feeds stderr back to Claude, even though an allow rule matched.
Bash: git push --force, and the hook approves it
Answer: Deny rule stops it. Hook decisions do not override deny rules: deny-first precedence holds.
Bash rules match command text, so a deny rule is not a security boundary around the program. Use the sandbox or a container for that.
Go further: free on this site
Questions readers asked about this chapter, a 5-question self-check with explanations, and every source it cites.
Questions readers ask (5)
5 questions. Open one to read the answer.
We already use Claude Code on every laptop. Do we also need the Agent SDK?
Only for agents that run inside your own service. Claude Code covers repository work, interactively, headless with claude -p or in the GitHub Action. The Agent SDK gives the same loop, tools, hooks and permissions as a Python or TypeScript library, so a product feature can host it. Its use falls under Anthropic's Commercial Terms, and third parties may not offer claude.ai login in their products. Pick one harness per job type: two harnesses for one job means two permission models to audit.
Our CLAUDE.md says never to edit the acceptance tests. Is that enough?
No. The memory docs say Claude treats CLAUDE.md files "as context, not enforced configuration". Keep the rule there so the agent knows it, then enforce it: deny rules such as Edit(/tests/acceptance/**) and Edit(/evals/**), which applies in every permission mode, and a PreToolUse hook with "onFailure": "block" (v2.1.295 or later) so a crashed hook blocks too. Agents may still add other tests. Add required review on tests/acceptance/ and evals/ in your Git host as the last gate.
When should CI use --bare?
When the checkout is untrusted. A trusted checkout (a label on the default branch, a scheduled job) can run without it and load the committed .claude/ hooks and skills, where your policy hook lives. An untrusted one (fork PRs, outside contributions) needs --bare: without it, a -p session runs the hooks in the project's .claude/settings.json and connects its .mcp.json servers "even in a folder you've never trusted" (headless docs). Bare mode loads only what you pass: --settings from a path outside the checkout, plus --mcp-config, --append-system-prompt-file or --agents as needed. It reads ANTHROPIC_API_KEY, an apiKeyHelper from --settings or cloud provider credentials; it ignores OAuth logins and the keychain.
Our compliance team requires zero data retention. What can we still use?
Check per feature. ZDR for Claude Code is for qualified Claude for Enterprise accounts, enabled per organization by Anthropic; it disables cloud sessions and Remote Control, and does not cover MCP servers or other third-party integrations. Fable models are Covered Models that require retention by default. On the API, batch, the MCP connector and Agent Skills are not ZDR eligible, and Managed Agents is eligible only when self-hosted. Write the terms down per agent.
Can auto mode replace permission prompts for unattended runs?
Check first whether you already use it. The GitHub Action runs Claude in auto mode by default: reads and workspace edits run without asking, a safety review decides other calls your allow rules do not cover, and broad rules such as Bash(*) are ignored (usage). If your workflow relies on --allowedTools as a strict list, opt out in claude_args: --permission-mode default for workflows with a prompt, acceptEdits for @claude mentions. For locked-down claude -p runs, dontAsk denies every call that would prompt (headless docs). Chapter 8 has the classifier's measured miss rate.
Answered in the book, not repeated here: See Chapter 19, Models: choose by task, then by effort; See Chapter 19, Cost and reliability on Claude
Self-check (5)
Score: 0 / 5 (0 answered)
Question 1 of 5
Which layer actually stops Claude Code from editing
tests/acceptance/orevals/?Show the answer
Answer: B.
CLAUDE.md and skills are context, not enforcement. Deny rules apply in every mode, and a hook with onFailure set to block also stops the call when the hook itself fails.
Question 2 of 5
A policy hook times out. What happens to the tool call by default?
Show the answer
Answer: B.
Hooks fail open by default. Setting onFailure to block, on v2.1.295 or later, makes a crash or timeout block the call.
Question 3 of 5
What does
--barechange in aclaude -prun?Show the answer
Answer: B.
Bare mode loads only what you pass on the command line, so every machine behaves the same and a checkout cannot inject its own hooks or MCP servers.
Question 4 of 5
Your system prompt starts with the current timestamp. What happens to prompt caching?
Show the answer
Answer: B.
The cache covers tools, then system, then messages; a change to system invalidates system and everything after it. Each call pays the write premium with no read.
Question 5 of 5
Which harness does Chapter 19 suggest when hosting the sandbox and sessions is the hard part and the data terms fit?
Show the answer
Answer: D.
Managed Agents runs the harness, sandbox and session log for you. It is in beta and not ZDR or HIPAA eligible unless self-hosted, so check the terms first.
Sources
Sources cited
- Anthropic, Models overview, accessed November 2026. platform.claude.com
- Anthropic, Effort, accessed November 2026. platform.claude.com
- Anthropic, Claude Opus 5.5, September 2026. anthropic.com
- Anthropic, Pricing, accessed November 2026. platform.claude.com
- Anthropic, Claude Platform release notes, accessed November 2026. platform.claude.com
- Anthropic, Features overview, accessed November 2026. platform.claude.com
- Anthropic, Tool runner, accessed November 2026. platform.claude.com
- Anthropic, Structured outputs, accessed November 2026. platform.claude.com
- Anthropic, Prompt caching, accessed November 2026. platform.claude.com
- Anthropic, Batch processing, accessed November 2026. platform.claude.com
- Anthropic, MCP connector, accessed November 2026. platform.claude.com
- Anthropic, Agent Skills guide, accessed November 2026. platform.claude.com
- Anthropic, Claude Code overview, accessed November 2026. code.claude.com
- Anthropic, Claude Code GitHub Actions, accessed November 2026. code.claude.com
- Anthropic, Claude Code in the cloud, accessed November 2026. code.claude.com
- Anthropic, Agent SDK overview, accessed November 2026. code.claude.com
- Anthropic, Agent SDK quickstart, accessed November 2026. code.claude.com
- Anthropic, Commercial Terms of Service, accessed November 2026. anthropic.com
- Anthropic, Claude Managed Agents overview, accessed November 2026. platform.claude.com
- Anthropic, Scaling Managed Agents with stable interfaces, April 2026. anthropic.com
- Anthropic, Skills (Claude Code), accessed November 2026. code.claude.com
- Anthropic, Donating Agent Skills to the Agentic AI Foundation, October 2026. anthropic.com
- Anthropic, Plugins overview, accessed November 2026. code.claude.com
- Anthropic, Memory (CLAUDE.md), accessed November 2026. code.claude.com
- Anthropic, Permission modes, accessed November 2026. code.claude.com
- Anthropic, Configure permissions, accessed November 2026. code.claude.com
- Anthropic, Hooks reference, accessed November 2026. code.claude.com
- Anthropic, Subagents, accessed November 2026. code.claude.com
- Anthropic, Run Claude Code programmatically, accessed November 2026. code.claude.com
- Anthropic, CLI reference, accessed November 2026. code.claude.com
- Anthropic, An update on Claude Code quality reports, April 2026. anthropic.com
- Anthropic, Self-hosted environments, accessed November 2026. code.claude.com
- Anthropic, Scheduled tasks, accessed November 2026. code.claude.com
- Anthropic, Enterprise deployment and third-party integrations, accessed November 2026. code.claude.com
- Anthropic, Zero data retention, accessed November 2026. code.claude.com
- Anthropic, Feature availability, accessed November 2026. code.claude.com
- Anthropic, Rate limits, accessed November 2026. platform.claude.com
- Anthropic, How we built Claude Code auto mode, March 2026. anthropic.com
- Anthropic, Sandboxing, accessed November 2026. code.claude.com
- Anthropic, Secure deployment (Agent SDK), accessed November 2026. code.claude.com
- GitLab Advisory Database, CVE-2026-55607: Claude Code: Sandbox Escape via Git Worktree Path Confusion Allows Unsandboxed Code Execution, July 2026. advisories.gitlab.com
- Anthropic, Managed MCP configuration, accessed November 2026. code.claude.com
- Claude blog, Claude in Chrome is generally available, August 2026. claude.com
- Anthropic, Session storage (Agent SDK), accessed November 2026. code.claude.com
- Anthropic, MCP in the Agent SDK, accessed November 2026. code.claude.com
- Anthropic, Plugin evals, accessed November 2026. code.claude.com
- Anthropic, Measure plugins, accessed November 2026. code.claude.com
Further reading
- Anthropic, Building effective agents, December 2024. anthropic.com
- Anthropic, Writing effective tools for agents, with agents, September 2025. anthropic.com
- Agent Skills, Specification, accessed November 2026. agentskills.io
- Model Context Protocol, python-sdk (GitHub), accessed November 2026. github.com
- Anthropic, claude-code-action (GitHub), accessed November 2026. github.com