Skip to content
Agentic Control Plane

Claude Code headless permissions: run unattended without --dangerously-skip-permissions

David Crowe David Crowe · · Updated · 10 min read
claude-code headless ci approvals permissions reference
Share X HN LinkedIn

Just want the answer? Headless, a permission prompt has no one to answer it, so anything that would have asked is denied. Decide in advance instead: allow the tools the job needs, deny the ones it must never touch, and keep a hook on the path for everything else.

claude -p "run the test suite and fix the failing test" \
  --permission-mode acceptEdits \
  --allowedTools "Bash(npm test:*)" "Bash(npm run lint:*)" "Edit" "Read" \
  --disallowedTools "Bash(git push:*)" "Bash(rm:*)"

Ready unattended policies (Fenced Worker) →  ·  the empty chair test →  ·  free up to 5 agents

Most tutorials for running Claude Code in a pipeline reach for --dangerously-skip-permissions. The first unattended run stops on a permission prompt nobody can answer, and the flag makes the stop go away. It also auto-allows everything the permission system would have asked about. That is the widest setting Claude Code has, used when nobody is watching.

This page covers what happens to a permission prompt in claude -p, the four documented ways through, and a setup that runs unattended with permissions still on.

Why the first run fails

A permission prompt is a question for whoever is watching. Headless, nobody is. In print mode the prompt “only exists when the Agent SDK’s canUseTool callback supplies it,” so a call that would have prompted is denied. That is a sensible default. The job asked a question and nobody was there.

Codex CLI does the same thing and cancels the call. The Codex version of this page covers it. On both, the fix is to stop generating questions.

The four ways through

1. --permission-mode. default prompts, which headless means deny. acceptEdits auto-approves file edits and common filesystem commands. plan reads first and still prompts for writes. dontAsk denies anything not pre-approved, the strictest headless setting and a good one for read-only jobs. auto runs a background classifier instead of prompting. bypassPermissions auto-allows everything.

2. --allowedTools and --disallowedTools. These are standing answers to the questions you would have been asked. Bash(npm test:*) allows one command family. Edit allows a tool. Bash(git push:*) in the disallowed list denies one. Deny beats allow at every scope. They are the same rules as permissions.allow and permissions.deny in settings, passed on the command line.

3. --permission-prompt-tool <mcp_tool>. This names an MCP tool that is called wherever a prompt would have appeared. Claude Code waits for that tool’s server to connect before the first turn, up to MCP_TIMEOUT (30 seconds by default). The tool returns allow or deny. It cannot approve an MCP tool that is itself marked as requiring user interaction.

ACP does not ship a tool for this flag. You would supply your own MCP server for it. What ACP does for headless runs is separate: the Claude Code plugin treats claude -p, SDK-driven runs, CI and bypassPermissions sessions as unattended (the background tier). When policy holds a call there, Claude Code has no one to ask, so the call is denied with a reason the model sees. The approval is created, and a person approves it on the console Approvals page or from the email. Then the run is retried and the call passes under the grant. An agent can also call acp_wait_approval to wait for the decision instead of polling by hand. An approval nobody answers expires as a deny.

4. The Agent SDK. If the job is code, the SDK’s canUseTool callback is the prompt. Your function receives the tool call and returns the decision.

What a hook ask means headless

A PreToolUse hook can return permissionDecision: "ask" to force a prompt. In print mode there is nothing to prompt, so the call does not run. Treat ask as deny when nobody is on stdin.

That changes the policy you write. Attended, an ask on rm costs you a click. Unattended, it stops the job at the first cleanup step. So an unattended policy answers in advance: the deletes the job may do are allow, the ones it may never do are deny. The empty chair test is the checklist. The exception is an ACP hold: the call is still denied, but it leaves an approval a person can grant, and the retry then runs.

ACP’s safety floor works the same way. A force-push, destructive SQL through a database client, curl | sh or a delete outside the project is held for approval. In an unattended session that hold goes to the console and the owner’s email, and an unanswered one expires as a deny.

A setup that works today

  1. Pin the mode. Use acceptEdits for jobs that write to the repo and dontAsk for jobs that only read. Avoid bypassPermissions for anything that touches a credential, a deploy target or a real MCP server.
  2. Pre-decide the tools. Use --allowedTools for what the job needs and --disallowedTools for what it must never do. Or put the same lists in .claude/settings.json so they are reviewed with the code.
  3. Keep a hook on the path. Hooks fire in print mode and in every permission mode. A PreToolUse deny blocks the call with a reason the model sees, with stdin closed. That catches what step 2 misses through a different spelling. For calls you want a person to decide, hold them with ACP and approve on the console or from the email.
  4. Write the unattended policy as its own tier. The ACP hook reports bypassPermissions sessions as background, along with CI and headless runs (claude -p, SDK entrypoints, claude mcp serve, the GitHub Action). A Task-spawned subagent is subagent. With the plugin, auto mode counts as interactive. So a rule written for the background tier is the one an unattended session gets. The Fenced Worker persona is a ready-made policy for it.
  5. Know how it fails. If the gateway is unreachable, the Claude Code plugin keeps subagent, background and api sessions blocked until it answers. Interactive sessions carry on with a loud UNGOVERNED banner. The shared hook other harnesses use fails open unless you set ACP_FAIL_MODE=closed.

With that in place you do not need the bypass flag. If someone uses it anyway, deny rules and hooks still run, because the flag removes the prompts, not the hooks. A workspace starts in audit mode, so run /acp-enforce before you rely on your own rules.

Troubleshooting

The job stops on a tool you expected to run. It was not pre-approved. Add it to --allowedTools or the settings allow list. Check the rule syntax: Bash(npm test:*), not npm test.

The job runs a tool you thought was denied. Deny rules are string patterns, and one command has many spellings. Put the decision behind a hook that classifies the command.

--permission-prompt-tool times out before the first turn. Your MCP server did not connect within MCP_TIMEOUT. Raise it, or move the decision to a hook, which needs no server.

Everything is denied under dontAsk. That is how it works. dontAsk only runs pre-approved tools. Add the allow list.

Frequently asked questions

What happens when claude -p needs permission for a tool call?

The call is denied. Print mode has no interactive prompt, and the docs say that prompt only exists when the Agent SDK’s canUseTool callback supplies it. A tool that isn’t pre-approved by a rule, an --allowedTools entry, the permission mode, or a permission-prompt tool does not run.

Is --dangerously-skip-permissions the only way to run Claude Code unattended?

No. --permission-mode acceptEdits or dontAsk, --allowedTools with deny rules, and --permission-prompt-tool all run headless with the gate on. bypassPermissions auto-allows everything the permission system would have asked about; hooks and deny rules still apply under it, so it is not ‘no controls’, but it is the widest setting.

What does --permission-prompt-tool do?

It names an MCP tool that answers permission prompts in print mode. Claude Code waits for that tool’s server to connect (up to MCP_TIMEOUT, 30 seconds by default) and calls it whenever a prompt would have appeared. ACP does not ship a tool for this flag. With ACP, a held call in a headless session is denied with a reason, a person approves it on the console Approvals page or from the email, and the run is retried. It cannot approve an MCP tool that is marked as requiring user interaction.

What happens if a PreToolUse hook returns ask in print mode?

There is no one to ask, so the call does not run. Treat ask as deny when designing unattended policy, and write the allow and deny rules you would have answered by hand as standing rules before the job starts.

Do hooks still fire in claude -p?

Yes. Hooks run in print mode and in every permission mode. A PreToolUse hook that returns deny blocks the call with a reason the model sees; that is the seam that makes controlled headless Claude Code possible.

Where to read more

Share X HN LinkedIn
Get the next data drop
What agents actually cost, new tool-surface captures, and the occasional incident post-mortem — sent when we publish something worth your inbox, not on a schedule. Unsubscribe anytime.
Share: Twitter LinkedIn
Related posts

← back to blog