Claude Certification Program · Five exams · Guides updated December 7, 2026

Home › Study guides › CCAR-P › Domain 7 › Lesson 7.2

CCAR-P · Domain 7 · 8% of the exam · Lesson 7.2 · 19 min read Updated for the December 7, 2026 exam guide (v1.1)

Configuring the Agent SDK and Claude Code for a team workflow

Configure permission modes, rules, hooks, subagent definitions and headless runs so a team's Claude Code workflow stays inside its safety guardrails.

Written against skill 7.2 of the official CCAR-P exam guide (Version 1.1, effective December 7, 2026). An independent resource, not affiliated with Anthropic; the practice questions are written from scratch.

7.2.1 Why a guardrail needs a setting, not a promise

Fennick Outfitters sells outdoor gear through 140 stores and an online shop. Its checkout team of 14 engineers piloted Claude Code for six weeks. Now they want it in three places: daily work in the terminal, a reviewer for every payments change, and a nightly job that upgrades dependencies while everyone sleeps. Ingvild, the solution architect, has to make that happen. Obiora, the head of application security, has handed her four guardrails.

  1. No push, no deploy. Nothing Claude runs may push to main or deploy.
  2. Payments need a person. Every edit under payments/ is approved by an engineer before it lands.
  3. Unattended means fail closed. A job with nobody watching never waits for an answer and never does more than its task needs.
  4. Done means green. Every edited file is formatted, and no run reports success with failing tests.

The engineers add a fifth wish: fewer permission prompts. The pilot's answer to all of this was a paragraph in CLAUDE.md. That paragraph is context. Claude reads it and usually follows it, but nothing stops a run that drifts, and nobody reads it at 3 a.m. when the nightly job meets an unexpected prompt.

What Ingvild needs is configuration: the settings that Claude Code and the Claude Agent SDK enforce in code, whatever the model decides. The SDK runs the same agent loop and tools as Claude Code, so the same five levers exist in both, and each one enforces a different kind of rule.

Five levers for one team workflow

A team workflowinside stated guardrails
Permission modethe baseline for calls no rule settles
Permission rulesmust never (deny), must ask (ask)
Hookssteps that must always run
Subagent definitionswhat delegated work may touch
Headless optionshow an unattended run fails closed
Each guardrail belongs to the lever that can enforce it; CLAUDE.md informs Claude but enforces nothing.

7.2.2 Permission modes: the baseline, not the guardrail

Here is the question that trips people up: which permission mode is the safe one? It sounds reasonable, and it is the wrong frame. A permission mode decides only the tool calls that nothing earlier has settled. Claude Code and the Agent SDK check every call in a fixed order, and the mode sits in the middle of it.

How one tool call is decided

HOOKSPreToolUse can block
DENY rulesblocked in every mode
ASK rulesa person must approve
MODEdecides what is left
ALLOW rulespre-approved calls
Prompt or callbackor denied if nobody can answer
Hooks and deny rules come first, so no mode, allow rule or hook approval can carve an exception out of a deny.

Two consequences follow. A deny rule holds in every mode, bypassPermissions included. And an ask rule prompts even in modes that would otherwise approve the call, while in dontAsk the same ask rule becomes a denial. That makes an ask rule exactly right for guardrail 2: Edit(/payments/**) in the team's .claude/settings.json asks an engineer in an interactive session and is refused in an unattended one.

Mode Runs without asking When it fits a team
default (Manual) Reads in the working directory and other calls that need no approval Unfamiliar code, or anyone new to Claude Code
acceptEdits Also file edits and common filesystem commands in the working directory Iterating on code the engineer reviews as a diff
plan Reads and exploration; no source edits until a person approves the plan Risky or broad changes, such as anything in payments/
auto Everything, with a classifier model reviewing actions first Long interactive tasks where prompts cause fatigue
dontAsk Reads and pre-approved tools; anything that would prompt is denied Locked-down CI and scheduled jobs
bypassPermissions Everything, except the few actions no mode auto-approves Isolated containers or VMs only

Memorise the second column; the third is judgement. Auto mode answers the wish for fewer prompts, and Anthropic is explicit that it reduces prompts without guaranteeing safety. Its classifier blocks risky actions such as force pushes and production deploys by default, but pushing to the repository you are working in, including its default branch, is allowed by default. So auto mode does not satisfy guardrail 1; that takes a deny rule and a guard hook, backed by branch protection on the git host. Auto mode also drops broad allow rules such as Bash(*) when it starts, keeping narrow ones.

Three configuration facts shape the rollout. Since Claude Code v2.1.283, auto mode is the built-in starting mode for interactive terminal and VS Code sessions wherever it is available, which takes a supported model and no disableAutoMode setting; claude -p and SDK runs still start in Manual. The shared .claude/settings.json can set defaultMode to default, acceptEdits, plan or dontAsk, but auto or bypassPermissions set there does not take effect; those work only from user or managed settings or a command-line flag. And dontAsk never appears in the Shift+Tab cycle; you start a run in it on purpose.

Ingvild's choice: engineers keep the auto mode their sessions start in, and use acceptEdits where auto mode is unavailable. Payments changes start in plan mode. bypassPermissions is not used on laptops at all.

7.2.3 Rules and hooks: what must, or must never, happen

Rules cover the "never" and the "ask". Guardrail 4 is different: it says something must ALWAYS happen. No permission rule can make the formatter run. That is the job of a hook: a command, HTTP call, prompt or agent check that Claude Code runs at a fixed moment in the session, whatever Claude decides. Hooks live in the same settings files as rules, so the team's hooks are committed and reviewed with the code.

Three events do most of the work. PreToolUse runs before a tool call and can block it. PostToolUse runs after a call succeeds; it can add feedback for Claude but cannot undo what the tool already did. Stop runs when Claude finishes responding and can send it back to work. In the excerpt below, look at the ask rule, the Bash matcher on the guard script and the Stop hook.

{
  "permissions": {
    "allow": ["Bash(npm test *)", "Bash(npm run lint *)"],
    "ask": ["Edit(/payments/**)"],
    "deny": ["Bash(git push *)", "Bash(npm publish *)", "Read(./.env)"]
  },
  "hooks": {
    "PreToolUse": [{ "matcher": "Bash", "hooks": [
      { "type": "command", "command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/guard-git.sh" } ] }],
    "PostToolUse": [{ "matcher": "Edit|Write", "hooks": [
      { "type": "command", "command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/format.sh" } ] }],
    "Stop": [{ "hooks": [
      { "type": "command", "command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/tests-green.sh" } ] }]
  }
}

Why a guard script when a deny rule already names git push? Because a Bash rule matches the command text Claude writes. Bash(git push *) stops git push origin main but not git -C . push origin main. A PreToolUse hook receives the full command and can refuse any form of a push. Even so, the hook is a second line inside the tool; the boundary for guardrail 1 stays on the git host.

The details decide whether a hook enforces anything. A command hook blocks by exiting with code 2; any other non-zero exit is a non-blocking error, and the call goes ahead. A timed-out PreToolUse hook does not block either, unless you set onFailure to block. A hook's allow never overrides a deny or ask rule. Hooks keep running in every mode, so a hook deny holds even in bypassPermissions. The Stop hook needs a loop guard: Claude Code sets stop_hook_active when a Stop hook has already sent Claude back, and the script should let it stop then.

7.2.4 Subagent definitions: scope the work you delegate

Fennick's second workflow is a reviewer for payments changes. Claude can hand that review to a subagent: a separate agent instance with its own system prompt, tools and fresh context window, which returns only its final report to the main conversation. In Claude Code a subagent is a Markdown file with YAML front matter in .claude/agents/; in the Agent SDK it is an AgentDefinition passed in the agents option.

---
name: payments-reviewer
description: Reviews diffs under payments/ for card-data handling and error paths. Use after any payments change.
tools: Read, Grep, Glob
model: sonnet
maxTurns: 20
---
You review payment code. Report each finding with file, line and severity. You never change files.

Look at three fields. The description is how Claude decides when to delegate, so it names the trigger. The tools list is the allowlist: this reviewer can read and search, and nothing else exists for it. maxTurns caps the run, and output that hits the cap is marked partial.

Now the trap the exam likes. A tempting way to make the reviewer read-only is permissionMode: plan. But a subagent's own permissionMode applies only when the main session is in default or dontAsk. When the main session runs in acceptEdits, auto or bypassPermissions, the subagent runs in the parent's mode and its setting is ignored. Under a plan-mode parent, every subagent stays in plan mode. Fennick's engineers mostly work in auto mode or acceptEdits, so a reviewer scoped by mode would quietly gain edit rights.

Which mode a subagent actually runs in

Parent in acceptEdits, auto or bypass

Subagent's permissionModeignored
Runs in the parent's mode

Parent in plan

Subagent stays in plan mode
Delegating cannot skip plan review

Parent in default or dontAsk

Subagent's own mode applies
Except: never escalates to bypass
The parent's mode wins in most sessions, so scope a subagent by its tool list, not by its permission mode.

Two smaller rules complete the picture. In a subagent's disallowedTools, an entry like Bash(git push *) removes the whole Bash tool, so use a deny rule to block one command and keep the tool. In the SDK, listing a tool in a definition's tools makes it available but does not pre-approve it; approval still comes from rules, hooks or the mode. When two definitions share a name, managed settings win, then the --agents flag, then the project, then the user, then plugins; in the SDK, programmatic agents beat files of the same name.

7.2.5 Headless and CI: when nobody can answer

The nightly upgrade job has no engineer at the keyboard. Claude Code runs it non-interactively with claude -p (--print), or as a program built on the Agent SDK; the two are the same engine. The first design question is what happens to a call that would normally prompt. A -p or SDK run that sets no mode starts in Manual, and a call needing approval is denied unless an allow rule, hook, callback or permission-prompt tool approves it. Ingvild makes the choice explicit with dontAsk: everything pre-approved runs, everything else is denied and reported, and nothing waits. In the SDK version below, look at the mode, the two tool lists and the caps.

from claude_agent_sdk import query, ClaudeAgentOptions, AgentDefinition

options = ClaudeAgentOptions(
    cwd=checkout_of_main,
    permission_mode="dontAsk",            # not pre-approved = DENIED, never a prompt
    allowed_tools=["Read", "Grep", "Glob", "Edit", "Agent",
                   "Bash(npm outdated *)", "Bash(npm install *)", "Bash(npm test *)"],
    disallowed_tools=["Bash(git push *)", "Edit(/payments/**)", "WebFetch"],  # DENY in every mode
    agents={"test-runner": AgentDefinition(
        description="Runs the test suite after a dependency change and reports failures.",
        prompt="Run npm test. Report each failure with file, test and error. Never edit files.",
        tools=["Bash", "Read", "Grep"], model="haiku")},
    max_turns=60, max_budget_usd=4.0,     # CAP the run; the result says why it stopped
)

The job edits files but cannot push or touch payments, so Claude proposes and the pipeline disposes. A later pipeline step, not Claude, commits the change to a branch and opens a pull request with a token that branch protection keeps off main. The same run from the command line is claude -p with --permission-mode dontAsk, --allowedTools, --disallowedTools, --max-turns and --max-budget-usd, and --output-format json returns the result, cost and session ID for the pipeline to check. Documented alternatives exist: --permission-mode auto --permission-prompts none lets a classifier approve or block, and denies anything that would still prompt. bypassPermissions belongs only in an isolated container or VM, and note that an allow list does not limit it.

The second design question is subtler: whose configuration does the run load? A -p or SDK run never shows the workspace trust dialog. The project's allow rules are not applied in a folder nobody trusted, but its hooks run and its .mcp.json servers connect. For the nightly job that is fine, because main is reviewed. For a job that checks out a contributor's pull request, it means the contributor decides what runs on the runner.

Whose configuration an unattended run trusts

Loads the checkout's .claude/

Pull request edits .claude/settings.json
Its hooks run on the runner
Its .mcp.json servers connect

Job owns its configuration

--bare, or setting_sources without project
Allow list, denies and caps in the job
Secrets and token scope set by the pipeline
A run over a checkout it did not write takes its guardrails from the job, never from the checkout.

For such runs, start with --bare, which skips the project's hooks, skills, subagents, plugins and MCP servers (its env block still applies), or with --setting-sources user, which reads neither the project's settings nor its .mcp.json. With the Claude Code GitHub Action (anthropics/claude-code-action@v1), the same flags go in claude_args. A plain-text prompt gets no shell or GitHub API access until --allowedTools grants it, the API key lives in GitHub Secrets, and the workflow gets only the permissions it needs.

7.2.6 The exam traps

Most traps here put a guardrail in a lever that cannot enforce it.

  • ✗ Writing a must-never rule in CLAUDE.md or the subagent's prompt. ✓ Use a deny rule, or an ask rule for approve-first. Context shapes what Claude tries; rules decide what Claude Code allows.
  • ✗ Choosing a permission mode as the guardrail, for example trusting auto mode's classifier to prevent pushes. ✓ Put the guardrail in a rule or hook; the mode only decides calls nothing else settled, and auto mode allows pushes to the working repository by default.
  • ✗ A hook that exits with code 1 to block, or a PostToolUse hook to prevent an action. ✓ Block with exit code 2 or a deny decision in PreToolUse; PostToolUse runs after the tool has already acted.
  • ✗ Making a subagent read-only with permissionMode: plan. ✓ Give it a tools allowlist; the parent's acceptEdits, auto or bypassPermissions mode overrides the subagent's own.
  • ✗ Running CI with --dangerously-skip-permissions so it never stalls. ✓ Pre-approve the job's commands and run in dontAsk; bypass mode ignores the allow list and belongs only in an isolated container.
  • ✗ Letting a pull-request job load the checkout's .claude/ files. ✓ Run it with --bare or without project settings, so the job, not the contributor, decides what executes.

7.2.7 Put it together: configure a guarded workflow and break it

This exercise shows the difference between a rule that matches text and a hook that enforces.

The configuration you built serves one team in one repository. Accountability for AI-generated code (7.3) takes the next step: who reviews and owns what these runs produce once it reaches a pull request.

Key takeaways

  • ✓ Map each guardrail to the lever that enforces it; CLAUDE.md and prompts inform Claude but enforce nothing.
  • ✓ Every call passes hooks, deny rules, ask rules, the mode, then allow rules; deny rules hold in every mode, and ask rules prompt or, under dontAsk, deny.
  • ✓ The six modes run from default through acceptEdits, plan and auto to dontAsk and bypassPermissions; auto mode reduces prompts without guaranteeing safety.
  • ✓ Hooks make steps happen every time: block in PreToolUse with exit code 2, react in PostToolUse, gate the finish in Stop with a loop guard.
  • ✓ Scope a subagent with its tools allowlist and a clear description, because the parent's acceptEdits, auto or bypassPermissions mode overrides its own.
  • ✓ Headless runs fail closed with dontAsk, an exact allow list, denies and caps, while the pipeline performs irreversible steps.
  • ✓ A run over an untrusted checkout takes its configuration from the job, with --bare or without project settings.

Check your understanding

4 questions written for this lesson. Every answer option is explained, including the ones you did not pick. Nothing is stored.

CCAR-P practice questions are being rewritten

The 189 CCAR-P practice questions here were written for the previous exam guide and are tagged to its domains. New questions for the December 7, 2026 guide (v1.1) are being written. Until they are ready, the practice for the new guide is the questions at the end of every lesson, with every answer option explained. The old bank stays open for general practice.

Back to Domain 7 → The previous-guide bank →

Sources