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

BuilderLeaderSoloClaude18 min read

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

  1. 1The Claude stack map (as of late 2026)
  2. 2Decision guide: which layer to build on
  3. 3Claude Code as a production agent harness
  4. 4Claude in the cloud
  5. 5Cost and reliability on Claude
  6. 6Security on Claude
  7. 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)

    1. Question 1 of 5

      Which layer actually stops Claude Code from editing tests/acceptance/ or evals/?

      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.

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

    3. Question 3 of 5

      What does --bare change in a claude -p run?

      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.

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

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

    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