Claude Code permissions: allow, ask and deny rules, rule syntax and allowed tools
How do Claude Code permissions work, and how do I allow or block specific tools?
Claude Code checks every tool call against permission rules in your settings files. Rules go in permissions.allow, permissions.ask and permissions.deny, use the format Tool or Tool(specifier), and are evaluated deny first, then ask, then allow. Use /permissions to see every rule and the file it comes from, or pass --allowedTools and --disallowedTools for one session.
Also in: 简体中文 · 日本語 · 한국어 · Español · Português (Brasil)
Compare: allow all commands in every AI coding agent →
Allow, ask and deny
- Allow rules let Claude Code use the matching tool without asking you.
- Ask rules prompt for confirmation every time the matching tool is used.
- Deny rules block the matching tool.
- Order is deny, then ask, then allow. The first match wins and specificity does not change the order, so a broad deny like Bash(aws *) beats a narrower allow like Bash(aws s3 ls).
- A deny rule with a bare tool name, such as Bash, removes the tool from Claude's context. A scoped deny such as Bash(rm *) keeps the tool and blocks only matching calls.
Rules are enforced by Claude Code, not by the model. Instructions in CLAUDE.md shape what Claude tries to do but do not change what it is allowed to do.
Rule syntax by tool
- Whole tool: Bash, Read or WebFetch with no parentheses. Bash(*) is the same as Bash.
- Bash: Bash(npm run build) matches that exact command. Bash(npm run *) matches every npm script. Put the * after the subcommand: Bash(git log *) allows only git log, while Bash(git *) allows every git command.
- Bash(ls *) needs a space after ls, so it does not match lsof. Bash(ls:*) is an equivalent way to write the trailing wildcard.
- Read and Edit use gitignore patterns. Read(./.env) blocks the .env file in the current directory, Read(./secrets/**) blocks a folder. Use Edit rules, not Write rules, for paths no tool may change.
- Paths: //path is absolute from the filesystem root, ~/path is from your home folder, /path is relative to the settings file's project, and path or ./path is relative to the current directory.
- WebFetch: WebFetch(domain:example.com) matches example.com only. Add WebFetch(domain:*.example.com) for subdomains.
- MCP: mcp__github matches every tool from the github server, mcp__github__get_* matches its get_ tools, and mcp__github__create_issue matches one tool.
- Subagents: Agent(Explore) or Agent(my-custom-agent). Put one in deny to stop Claude from using that subagent.
Example settings
.claude/settings.json
{
"permissions": {
"allow": [
"Bash(npm run *)",
"Bash(git commit *)",
"WebFetch(domain:docs.example.com)",
"mcp__github__get_*"
],
"ask": ["Bash(git push *)"],
"deny": [
"Read(./.env)",
"Read(./secrets/**)",
"Bash(rm *)"
]
}
}Allow rules and additionalDirectories in a project's .claude/settings.json only take effect after you accept the workspace trust dialog for that folder. Deny and ask rules apply right away.
Allowed tools on the command line
- --allowedTools (or --allowed-tools): tools that run without prompting, using the same rule syntax.
- --disallowedTools (or --disallowed-tools): deny rules for this session. "mcp__*" removes every MCP tool.
- --tools: limits which built-in tools exist at all, for example "Bash,Edit,Read".
- --add-dir: adds working directories Claude can read and edit. Save them in permissions.additionalDirectories to keep them.
Terminal
claude -p "summarize recent changes" \ --allowedTools "Bash(git log *)" "Bash(git diff *)" "Read" \ --disallowedTools "Edit"
What asks by default, and what "don't ask again" saves
- Read-only tools such as file reads and Grep: no prompt inside your working directory and additional directories.
- Bash commands: prompt, except a built-in set of read-only commands. "Yes, and don't ask again" is saved permanently for that repository and command.
- File edits and writes: prompt. "Don't ask again" lasts only until the session ends and is not saved to a file.
- WebFetch: prompt, except a built-in set of preapproved documentation domains. Approval is saved per repository and domain.
- WebSearch: prompt. Approval is saved per repository.
A saved approval is written as a rule to .claude/settings.local.json at the root of the git repository (resolved through worktrees to the main checkout), so it also applies in subdirectories and worktrees. Approving a compound command such as git status && npm test saves a separate rule for each subcommand that needed approval, up to 5 rules. You can open /permissions while Claude is working; a rule you add or remove applies from Claude's next tool call.
Bash commands that never prompt, and wrappers Claude Code sees through
- Read-only commands run without a prompt in every mode: the built-in set includes ls, cat, echo, pwd, head, tail, grep, find, wc, which, diff, stat, du, cd and read-only forms of git. The set is not configurable; add an ask or deny rule to make one of them prompt.
- Some read-only commands still prompt in Manual mode, for example find, sort, sed or git with an unquoted glob, or a cd into another directory combined with git.
- Before matching, Claude Code strips timeout, time, nice, nohup, stdbuf, command, builtin and zsh noglob, so Bash(npm test *) also matches timeout 30 npm test. It also strips bare xargs (with no flags) and a leading assignment of known-safe environment variables.
- Runners such as npx, docker exec, direnv exec, devbox run and mise exec are not stripped. Bash(devbox run *) would match anything after run, so write one exact rule per inner command, such as Bash(devbox run npm test).
- Prefix rules cannot auto-approve exec wrappers like watch, setsid, ionice and flock, or find with -exec, -delete or -fprint. Use an exact rule for the full command, or a PreToolUse hook.
What a Bash deny rule does not stop
Bash rules match the command text Claude writes. Deny and ask rules apply when any subcommand matches, including inside a subshell, a command substitution or a for loop. They do not catch the same program called another way.
- Bash(curl *) stops curl https://example.com but not /usr/bin/curl https://example.com or sh -c 'curl https://example.com'.
- Bash(rm *) stops rm -rf build/ but not /bin/rm -rf build/ or bash -c 'rm -rf build/'.
- Bash(git push *) stops git push origin main but not git -C . push origin main.
- Patterns that try to limit arguments, such as Bash(curl http://github.com/ *), miss flags before the URL, https, redirects and variables.
- Output redirects (>, >>, 2>) and tee targets are checked against your Edit rules and working directories, so Bash(git commit *) allows the command but not where its output is written.
For a limit that holds regardless of command text, use the sandbox network and filesystem rules, or a PreToolUse hook that inspects the full command. To restrict web access, deny curl and wget and allow WebFetch(domain:...) for the sites you trust; WebFetch rules alone do not block network access while Bash is allowed.
Which settings win
- A deny at any level cannot be allowed by another level. If user settings allow something and project settings deny it, it is denied, and the reverse is also true.
- Managed settings are highest. Even --allowedTools cannot override a managed deny, while --disallowedTools can add more restrictions.
- allowManagedPermissionRulesOnly makes managed settings the only source of permission rules.
- Set permissions.disableBypassPermissionsMode or permissions.disableAutoMode to "disable" to block those modes. They are most useful in managed settings.
Permission modes
Rules sit on top of the session's permission mode: default (Manual), acceptEdits, plan, auto, dontAsk or bypassPermissions. Set one with claude --permission-mode <mode> or permissions.defaultMode in settings. dontAsk denies anything that would prompt except tools your allow rules already approve. To run with no prompts at all, see the guide on allowing all commands in Claude Code.
Sources
More Claude Code guides
- How to allow Claude Code to run all commands: permission modes, allow rules and skip permissions
- Claude Code telemetry and data retention: what is sent and how to turn it off
- CLAUDE.md: where it goes, how it loads, and how it works with AGENTS.md
- Claude Code hooks: all events, exit codes, PreToolUse and PermissionRequest JSON, examples
- Claude Code subagents: create one, limit its tools, and call it
- Add MCP servers to Claude Code (claude mcp add, .mcp.json, scopes)
- Claude Code custom slash commands and skills (SKILL.md)
- Claude Code settings.json: file locations, precedence, and key settings
- Claude Code plugins and marketplaces: install, create, and share
- Claude Code headless mode: claude -p, --output-format json, --bare and CI flags
- Claude Code statusline: custom status bar in settings.json with context %, cost and git branch
- Claude Code /model: switch models, aliases (opus, sonnet, haiku, opusplan), ANTHROPIC_MODEL and effort
- Claude Code /cost and /usage: check token spend, usage limits and reduce costs
- Claude Code VS Code extension: install, shortcuts, settings and /ide (works in Cursor too)
- MCP 2026-07-28 Migration Guide: Stateless Protocol, No Sessions, server/discover, MRTR, and SDK v2 Upgrade
- Subagents and Custom Agents Compared: Claude Code vs Codex vs Cursor vs Gemini CLI vs GitHub Copilot (2026)
- Allow all commands in any AI coding agent: Cursor, Claude Code, Codex, Gemini CLI, Copilot CLI and 7 more (2026)
- How to deploy a remote MCP server (Streamable HTTP): Cloudflare Workers, Vercel, Railway and more (2026)
- Claude Code sandbox: /sandbox, sandbox.enabled, allowedDomains, excludedCommands and strict mode
Reviewed Oct 23, 2026. Settings change often; the linked vendor docs are the source of truth.
Built an MCP server? Get it listed everywhere →
Shipping an Android app? Google Play needs 12 testers for 14 days first. Get them with Tester Exchange →