skip to content

A nightly `claude -p` lint-triage job must neither stall on a permission prompt nor run commands nobody approved; how do you set its permissions?

level: seniorimportance: must knowfreq 20%

answer

  1. nobody is there to answer
  2. set the mode explicitly, every time
  3. dontAsk denies instead of asking
  4. scope Bash rules, never bare Bash
  5. --permission-prompts none, 2.1.259

basics

~20 s

Pass the mode explicitly, usually --permission-mode dontAsk with narrowly scoped --allowedTools rules, so anything unlisted is denied rather than prompted; add --permission-prompts none (2.1.259+) when a permission host could otherwise wait, and never a bare Bash allow.

solid answer

~40 s

Under `-p` nobody answers prompts, so decide every call up front. Pass `--permission-mode` explicitly: on Claude Code 2.1.286 a `-p` run with no mode configured starts in `default`, except on a third-party provider or with telemetry off, where since 2.1.285 it starts in `auto`. For a locked-down job use `--permission-mode dontAsk` plus scoped rules such as `--allowedTools "Read" "Edit" "Bash(npx eslint *)"`: reads in the working directory and read-only commands still run, listed calls run, everything else is denied and the run continues. A bare `Bash` entry would approve every shell command. When the run has a permission host, an Agent SDK `canUseTool` callback or a `--permission-prompt-tool`, add `--permission-prompts none` (2.1.259+) so unanswerable requests are denied instead of waiting. Afterwards, read `permission_denials` in the result.

code

bash · 6 lines
bash
claude -p "Read lint.log, apply the ESLint autofixes, and list what still needs a human" \
  --permission-mode dontAsk \
  --allowedTools "Read" "Edit" "Bash(npx eslint *)" \
  --permission-prompts none \
  --output-format json > triage.json
jq '.permission_denials' triage.json

go deeper

for a junior

Recall that nobody can answer prompts under -p, so tools are pre-approved with --allowedTools or a mode is chosen with --permission-mode.

for a middle

Explain dontAsk against acceptEdits for a script, how a scoped rule like Bash(npx eslint *) differs from bare Bash, and that denials do not stop the run.

for a senior

Show that an unset mode can start in auto since 2.1.285, when --permission-prompts none matters, and how permission_denials turns silent refusals into a failing job.

for a principal

Decide how much autonomy unattended jobs get across a team: dontAsk allowlists everywhere versus auto with prompts off, and what isolation would justify anything looser.

## The problem: nobody answers An interactive session stops and asks before a call it has no rule for. A `claude -p` run has no terminal and nobody watching, so every call must be decided before the run starts. Two failures are possible: - **Stalling**: the run waits for an answer that never comes. - **Failing open**: the run is configured so loosely that it does things nobody approved. Who receives a prompt in print mode depends on whether the run has a **permission host**: an Agent SDK application with a `canUseTool` callback, or an MCP tool passed with `--permission-prompt-tool`. With a host, the run sends each prompt there and waits. With no host, a `-p` run denies anything that would prompt and carries on. The mode, the allow rules and the flags below decide which calls ever reach that point. ## Step 1: choose the mode yourself The permission modes are taught elsewhere; what matters here is that a `-p` run **must not inherit one by accident**. A session takes its mode from `--permission-mode` first, then `permissions.defaultMode` in a settings file, then the built-in default. On Claude Code 2.1.286 the built-in default for `claude -p` is: | Situation | Starting mode with nothing configured | | --- | --- | | Session that fetches feature flags | `default` (labelled Manual) | | Third-party provider, or telemetry off | `auto`, since 2.1.285 | | Any settings file sets `disableAutoMode` to `"disable"` | `default` | | Organization policy withholds the `auto` default | `default` | So the same script can run in `default` on one runner and in `auto` on a runner pointed at a cloud provider. Pass the mode on the command line every time. For an unattended job, the candidates are: - **`dontAsk`**: denies every call that would otherwise prompt. File reads in the working directories, the built-in read-only commands and calls covered by `--allowedTools` or `permissions.allow` still run. The session never waits for input. This is the docs' suggestion for locked-down CI. - **`acceptEdits`**: writes files and common filesystem commands such as `mkdir` and `mv` without prompting; other shell commands and network requests still need an allow entry. - **`auto`**: a classifier reviews most actions instead of a person. Pair it with `--permission-prompts none` so anything that falls back to a prompt is denied. - **`bypassPermissions`** (or `--dangerously-skip-permissions`) runs everything without prompting, leaving only deny rules and a few built-in safeguards in force, and belongs only in an isolated container or VM. ## Step 2: pre-approve exactly what the job needs `--allowedTools` lists calls that run without a prompt, in permission rule syntax: 1. Name whole tools that are safe for the job: `"Read"`, `"Edit"`. 2. Scope shell access to a command prefix: `"Bash(npx eslint *)"`. The space before `*` matters; without it the prefix also matches longer command names. 3. **Never list bare `"Bash"`**: it approves every shell command. (In a run that starts in `auto`, Claude Code drops a bare `Bash` allow and lets the classifier judge each command instead.) 4. Use `--disallowedTools` for calls that must never happen; deny rules block in every mode, including `bypassPermissions`. ## Step 3: `--permission-prompts none` for hosted runs Added in **2.1.259**, `--permission-prompts` sets who answers prompts in print mode. The default, `host`, sends them to the SDK host or the `--permission-prompt-tool`. **`none`** says nobody can answer: - Anything that would prompt is denied unless a `PermissionRequest` hook allows it, and the run continues. - Claude is told nobody can approve the request and not to retry it. - Tools that need a person, such as `AskUserQuestion`, are removed, and unanswered MCP elicitation requests are cancelled. Rules, hooks and the mode still decide every call first; the flag only resolves what nothing else did. In a `-p` run with no host, those requests were already denied; the flag still stops Claude retrying them. ## Step 4: check what was refused A denial does not end the run, so a job can finish having quietly skipped half its work. With `stream-json`, denials appear as `permission_denied` system messages, and the final result's `permission_denials` lists them. Fail or flag the job when that list is not empty, and widen the allow rules deliberately rather than switching to a looser mode. The resulting recipe for the nightly lint job is short: an explicit `dontAsk` mode, three scoped allow rules, prompts turned off, and a check on the denials. Each piece closes one specific way an unattended run can stall or fail open.

  • Why might the same `claude -p` script behave differently on a runner that uses a cloud provider's credentials?
    With no mode configured, a `-p` run starts in `default` when it fetches feature flags, but since 2.1.285 starts in `auto` on a third-party provider or with telemetry off. The classifier then approves most actions instead of denying them. Passing `--permission-mode` explicitly makes every runner start the same way.
  • When does `--permission-prompts none` change anything in a plain `claude -p` run with no SDK host?
    Little: without a host, requests that would prompt are already denied. The flag adds that Claude is told nobody can approve and not to retry, and it removes `AskUserQuestion`. It matters most when a `canUseTool` callback or `--permission-prompt-tool` would otherwise be waited on.
  • Why is `dontAsk` safer than `bypassPermissions` for this job?
    `dontAsk` runs only what needs no approval or what your allow rules cover, and denies the rest. `bypassPermissions` runs anything no deny rule blocks, with allow rules having no effect, so one bad instruction in a lint log can become an unreviewed command; the docs reserve it for isolated containers and VMs.

  • claude -p always starts in Manual mode, so leaving the mode unset is safe
  • dontAsk approves every call without asking anyone
  • Allowing bare Bash only covers the commands the prompt mentions
  • --dangerously-skip-permissions is the fix for a job that gets stuck on prompts
  • A denied call fails the run, so a missing permission always shows up as a red job
  • --permission-prompts none overrides allow rules and the permission mode

Assumes Claude Code 2.1.286: --permission-prompts needs 2.1.259 or later, and since 2.1.285 a -p run with no mode configured starts in auto on third-party providers or with telemetry off.