What you need to know
Claude Code and the Agent SDK share one model of control: permission modes decide how much runs without asking, rules allow or deny specific tools and paths, hooks run your own code at points in the loop, and subagents get their own instructions and tools. This skill asks you to combine them so a team workflow runs as freely as it safely can.
Permission modes
| Mode | Behaviour | Fits |
|---|---|---|
default (Manual) | Reads run; edits, commands and network access ask first | Sensitive work, unfamiliar code |
acceptEdits | File edits in the working directory run without asking; other actions keep their rules | Working with changes reviewed afterwards in the diff |
plan | Claude explores and writes a plan; source edits wait until the plan is approved | Understanding a codebase before changing it |
auto | A classifier reviews actions before they run and blocks those that look risky or driven by hostile content | Long interactive tasks with fewer prompts; reduces prompts, does not guarantee safety |
dontAsk | Anything not pre-approved by a rule is denied; the session never waits for input | Locked-down CI and scripts |
bypassPermissions | Permission prompts and safety checks are skipped | Isolated containers or VMs only |
Two facts matter in many items. Deny rules block in every mode, including bypassPermissions, so they are the hard limit. And administrators can disable bypassPermissions and auto through managed settings, which users and projects cannot override.
Hooks
Hooks run your code at points such as before a tool call (PreToolUse), after it (PostToolUse) or when a session ends. A PreToolUse hook can inspect the command or file path and block it, which makes a rule like "never push to main" deterministic. Hooks also run formatters and linters after edits, and record what the agent did for audit.
Subagent definitions
A subagent is defined with its own prompt and its own restricted tool list. A review subagent that only reads files cannot change them, whatever it is asked. Defining subagents per role keeps the main session's context lean and limits what each part of a workflow can do.
Headless and CI operation
Claude Code runs non-interactively with -p, returning structured output that a pipeline can parse. In CI, pair it with dontAsk, an explicit allow list (for example the test command and file edits), deny rules for secrets and protected branches, and hooks for anything that needs checking in code. The Agent SDK offers the same controls in code, including a permission callback that decides each tool request.
In the exam
Configuration items describe a team workflow with safety and automation requirements (interactive or unattended, what must never happen, how much can run without review) and ask which mode, rules, hooks or subagent definitions fit. Use dontAsk with allow and deny rules for CI, plan before large changes, acceptEdits when edits are reviewed afterwards, deny rules and hooks for hard limits, restricted tool lists for subagents, and managed settings to forbid risky modes. Distractors use bypassPermissions outside an isolated environment, rely on instructions, or leave an unattended run waiting for approval.
Check your understanding
A CI job runs Claude Code to fix lint errors on every pull request. It must never wait for input, may only edit files and run the linter, and must never read .env files. Which configuration fits?
Show answer
Answer: A. dontAsk denies anything not pre-approved, so the job never waits, and the deny rule is a hard limit. Bypassing removes protection, acceptEdits would leave the linter waiting, and nobody approves CI steps live.
Which statement about deny rules is correct?
Show answer
Answer: D. Deny rules are the hard limit in every permission mode, which is why they carry the rules that must never be broken.
A team wants a review subagent that can read the codebase and comment, but can never modify files. How should it be defined?
Show answer
Answer: B. A restricted tool list makes editing impossible for that subagent. A prompt can be ignored, and reverting edits afterwards is cleanup, not prevention.
Apply it: Configure Northgate's nightly migration bot
Northgate wants a nightly job that uses Claude Code to migrate one service at a time to the new logging library, run the tests and open a draft pull request. It runs on a CI runner with no one watching. Security requires: no secrets read into context, no pushes to protected branches, no production access, and SOC 2 evidence of what the job did.
- Choose the permission mode and justify it.
- Write the allow rules, deny rules and hooks.
Done when: every security requirement is enforced by a rule or a hook, not an instruction. - Define one subagent the job uses, with its tool list.
- Say what is set centrally in managed settings and what is set in the repository.
Show model answer
1. Mode. dontAsk: the job never waits for input, and anything not pre-approved is denied.
2. Rules and hooks
| Type | Setting |
|---|---|
| Allow | Edit files in the service directory; run the build and test commands; git commit and push to migration/* branches; open a draft pull request |
| Deny | Read .env*, key files and the secrets directory; push to main or release branches; any production hostnames |
PreToolUse hook | Blocks any shell command that pushes outside migration/* or reaches production hosts, and logs the attempt |
PostToolUse hook | Runs the secrets scanner on changed files and the linter after edits |
| Session-end hook | Writes a record of tool calls, files changed and test results to the audit store for SOC 2 evidence |
3. Subagent. A "usage finder" subagent with read and search tools only, which lists the old library's call sites before the main session edits anything.
4. Central versus repository. Managed settings: bypassPermissions and auto disabled, the secrets deny rules, the approved marketplace for plugins. Repository settings: the service's build and test commands and the migration/* branch rule.