Claude Code 2.1.319 Can Deny Instead of Asking. Build Your Allowlist From the Denials

2026-11-28来源 dev.toEnglish
Claude Code 2.1.319 Can Deny Instead of Asking. Build Your Allowlist From the Denials

Claude Code 2.1.319, released on November 6, 2026, changes what a session does when it reaches a permission prompt and you're away from the keyboard: it can refuse the call and keep working. The changelog entry reads: "Added permissions.denyInsteadOfPrompting setting: a tool call that would wait on a permission prompt is denied and the turn continues, in terminal sessions, subagents and teammates."

Until now, an unattended task stopped at the first prompt it hit and stayed there until you came back.

A denial is also a record. Every call that got denied is something the agent wanted to do and your rules didn't cover. So run one task with the setting on, read the denials, and turn the safe ones into allow rules. The rest stay denied.

What the setting changes, and what it doesn't

It only changes what happens at the moment a prompt would appear. Your allow, ask and deny rules still decide first, and so does your permission mode. A command your rules already allow still runs, and anything your mode already approves (file edits in acceptEdits, say) goes through as before. The setting allows nothing on its own.

That is the difference from the dontAsk permission mode. The permissions docs describe dontAsk as a mode that "auto-denies every call that would otherwise prompt", and a mode replaces the one you were in. The new setting sits on top of whichever mode you picked, as the Developers Digest write-up puts it.

For claude -p runs there was already a route: the headless docs cover --permission-prompts none (v2.1.259 or later), and with --output-format stream-json the final result message lists denied calls in permission_denials. The new setting brings that behavior to interactive terminal sessions, which is where an agent you left alone actually sits and waits.

Two caveats before you configure it. At the time of writing, the official settings pages don't list the key yet, so the changelog is the primary source. And the setting's schema description, as quoted by Developers Digest, says the key is read from user settings, --settings and managed settings, and that project and local settings are ignored, so a repository's .claude/settings.json can't turn it on. I haven't checked that myself, so this guide sets the key where the schema says it's read: a --settings file for one run, or your user settings.

A robot arm reaches for a stack of tool cards at a closed gate; rejected cards drop into a tray, while the arm keeps working on a workbench
A denied call doesn't stop the turn. It lands in the tray, and the agent keeps going.

Step 1: one task, its own worktree, the setting on

Keep the trial small: one task, on a branch you can throw away. A git worktree gives it its own folder, so whatever the agent does stays off your main checkout.

Put the setting in a file outside the repo, for example ~/.claude/unattended.json:

{ "permissions": { "denyInsteadOfPrompting": true } } 

Then start the task with that file. The settings docs say --settings takes inline JSON or a path, applies for that session only, and sits above your user and project files:

git worktree add -b try/deny-run ../app-deny-run cd ../app-deny-run claude --settings ~/.claude/unattended.json \ --permission-mode acceptEdits \ "Add input validation to the signup handler, with tests" 

acceptEdits lets file edits through, so the denials you collect are the shell commands, fetches and other calls your rules don't cover yet. That is the list you want.

Add one paragraph to the task prompt. Per the release note, the turn carries on after a denial, and Developers Digest reports Claude is told about it. Tell it what to do next:

If a tool call is denied, don't try another way to do the same thing. Note it and move on. Finish with a list of every call that was denied and what it was for. 

An agent that can't run npm test might reach for npx jest, and a deny rule written for one spelling of a command doesn't cover another. The permissions docs give the example: a Bash(git push *) rule doesn't match git -C . push. The prompt can't enforce anything, since the docs say rules are enforced by Claude Code, not by the model. It does make the agent's own summary something you can check against the transcript.

Step 2: pull the denials out of the transcript

The sessions docs say each session is stored as JSONL at ~/.claude/projects/<project>/<session-id>.jsonl, where <project> is the working directory with every non-alphanumeric character replaced by - (paths over 200 characters get truncated plus a hash).

The same page warns that "the entry format is internal to Claude Code and changes between versions." So treat this as a script for today's files, not a stable API. In current transcripts, tool calls show up as tool_use blocks in assistant messages, and results as tool_result blocks with an is_error flag, the same block shapes the Messages API documents. Save this as ~/.claude/deny-report.jq, outside the worktree:

# deny-report.jq: every tool call whose result was an error ([.[] | select(.type == "assistant") | .message.content[]? | objects | select(.type == "tool_use") | {key: .id, value: {name, input}}] | from_entries) as $calls | .[] | select(.type == "user") | .message.content[]? | objects | select(.type == "tool_result" and .is_error == true) | $calls[.tool_use_id] as $c | select($c != null) | [$c.name, ($c.input.command // $c.input.file_path // $c.input.url // ($c.input | tostring)), (.content | tostring | .[0:60])] | @tsv 

Run it from the task's worktree folder with jq, against the newest transcript for that folder:

dir=$(pwd | sed 's/[^[:alnum:]]/-/g') t=$(ls -t ~/.claude/projects/"$dir"/*.jsonl | head -1) jq -rs -f ~/.claude/deny-report.jq "$t" | sort | uniq -c | sort -rn 

Each line is a count, the tool name, the command or path, and the start of the error text. The script catches every errored call, not only denials: a failing test run shows up too. The wording of the denial message isn't documented, so read the third column rather than grepping for a phrase. Then compare the list with the agent's own summary from Step 1.

Step 3: allow the safe ones, deny the rest

Sort each line into one of two piles.

Allow what you would have said yes to without reading it: the test and lint scripts, read-only git commands, the build. Deny what you would never want unattended: pushes, deploys, curl to arbitrary hosts, reads of secrets. Anything you're unsure about stays out of both lists, so it keeps being denied on unattended runs and keeps prompting when you're at the keyboard.

Then write the rules, using the syntax from the permissions docs:

{ "permissions": { "allow": [ "Bash(npm run test *)", "Bash(npm run lint)", "Bash(git diff *)" ], "deny": [ "Bash(git push *)", "Bash(curl *)", "Read(./.env)" ] } } 

Four rules from the docs decide whether these behave the way you expect:

  • A trailing * also matches the bare command, so Bash(npm run test *) covers npm run test with or without arguments.
  • Deny wins. If a tool is denied at any level, no other level can allow it.
  • Compound commands need every part allowed. Bash(npm run lint) doesn't approve npm run lint && rm -rf dist.
  • Allow rules in a committed .claude/settings.json apply only after each person trusts the folder. Deny and ask rules apply right away.

For team rules, commit them to .claude/settings.json on the task branch, so they arrive through review like any other change. For personal ones, use .claude/settings.local.json. The settings docs note that in a worktree, Claude Code reads that local file from the main checkout's root, so one file covers every worktree of the repo.

Then run the same kind of task again. The report should get shorter. What's left is either something you meant to keep denied, or a new gap.

Two piles of tool cards on a desk: a short stack moving through an open gate, a taller stack locked behind it, with a magnifier over one card
Each denial goes into one of two piles. The unsure ones stay denied.

Doing the same run in Hermes IDE

I build Hermes IDE, so weigh this section with that in mind. Hermes is not affiliated with Anthropic or any other agent vendor. It runs each agent in a real terminal, and ⌘N (Ctrl+Shift+N on Windows and Linux) starts a task on its own hermes/ branch in its own worktree, with the task as the agent's first prompt. That covers the git worktree add from Step 1.

The Hermes New task sheet with a refund-endpoint task typed, Claude Code selected, a new hermes/ worktree, Accept edits, and the preview of the claude command Hermes will run
The ⌘N New task sheet: Claude Code, the orders-api project, a new hermes/ worktree, Accept edits, model and effort, and the "Hermes will run" preview of the claude command.

Pick Accept edits in the approval chip. Hermes builds the claude command itself, and the sheet shows it, so I'd set the key in ~/.claude/settings.json for the trial rather than rely on a --settings flag. That file applies to every Claude Code session on the machine, and the settings docs say permission edits reach running sessions without a restart. Turn it off when the trial is done. If you keep it on, every Claude Code session on the machine denies instead of asking, including the ones you're sitting in front of.

Hermes gives every session one status: working, needs approval, asked you, done, error or idle. Without the setting, a blocked task sits in needs approval and shows up in the attention inbox until you answer it in Claude's own terminal. Hermes never answers a permission prompt for you. With the setting on, Claude Code never shows a permission prompt, so the task should have no approval to wait on. I'd expect it to keep working and end up done rather than sit in needs approval, unless the agent stops to ask you a question, which Hermes shows as asked you. I haven't run this exact combination myself yet, so if the status does something else, I'd like to hear about it.

When it's done, ⌘G (Ctrl+Shift+G) opens the Review Desk, with the task's changes by turn. Read what the agent did with the calls it could make before you promote anything. Then run the Step 2 report from a shell in the task's worktree.

If this was useful

The denials are half of this. The other half is the paragraph in your task prompt that tells the agent what to do when it's refused, so it doesn't quietly route around a rule. Writing instructions an agent follows when nobody is watching is the kind of thing my Prompt Engineering Pocket Guide covers.

If you want to try the Hermes route, Hermes IDE is free to download, source-available under BSL 1.1, and runs on macOS, Windows and Linux. Version 2.3.7 shipped on November 7, 2026. If it saves you a morning, star it on GitHub.

Prompt Engineering Pocket Guide: Techniques for Getting the Most from LLMs

原文:https://www.a8q9.cn/en/article/claude-code-2-1-319-can-deny-instead-of-asking-build-your-allowlist-from-the-den-4e2dba.html

相关文章