Claude Code deny rules
Permission entries that block Claude Code from executing matching shell commands or tool calls under any circumstance.
What is Claude Code deny rules?
Claude Code deny rules are permission entries that block matching shell commands or tool calls, no matter what the model asks for. In practice, teams use them to hard-stop risky actions and keep Claude Code away from sensitive files, commands, or tools. (docs.anthropic.com)
Understanding Claude Code deny rules
Claude Code’s permission system is built around simple rules like Tool and Tool(specifier). Anthropic’s docs state that rules are evaluated in order with deny first, then ask, then allow, and the first matching rule wins. That means a deny rule is the strongest common policy control in the stack. (docs.anthropic.com)
You’ll usually define deny rules in .claude/settings.json or a user-level settings file. The official docs show examples such as denying WebFetch, blocking specific Bash patterns like Bash(curl:*), or preventing reads of sensitive paths like Read(./.env) and Read(./secrets/). Claude Code also documents hooks that can return permissionDecision: "deny" to stop a tool call before it runs. (docs.anthropic.com)
Key aspects of Claude Code deny rules include:
- Strongest precedence: deny rules are checked before ask and allow rules, so they are the most reliable way to block a specific action.
- Pattern-based matching: rules can target a whole tool or a narrower command or path pattern.
- File protection: deny rules are commonly used to hide credentials, secrets, and environment files from Claude Code.
- Tool-level enforcement: deny can apply to Bash, Read, WebFetch, and other supported tool types.
- Policy-friendly: rules can live in shared project settings or managed settings for consistent team behavior.
Advantages of Claude Code deny rules
Key advantages include:
- Clear guardrails: they create an explicit block list for actions you never want Claude Code to attempt.
- Reduced blast radius: a bad prompt or mistaken model action is less likely to reach sensitive systems.
- Team consistency: project settings let teams share the same safety policy.
- Fine-grained control: you can block one command pattern instead of disabling a whole tool.
- Better auditability: deny rules make permissions easier to reason about during reviews.
Challenges in Claude Code deny rules
Key challenges include:
- Rule design: overly broad patterns can block useful workflows, while narrow ones can miss risky variants.
- Maintenance: permissions need to evolve as repositories, tools, and command patterns change.
- Policy overlap: deny, ask, allow, and hook behavior can be confusing without a clear governance model.
- Coverage gaps: no rule set replaces careful sandboxing, code review, and least-privilege access.
- User friction: aggressive blocking can slow legitimate work if the policy is too strict.
Example of Claude Code deny rules in action
Scenario: a team allows Claude Code to help edit docs and run tests, but never to read production secrets or make outbound fetches to unapproved endpoints.
They add deny rules for Read(./.env), Read(./secrets/), and WebFetch to a project settings file. When Claude tries to inspect credentials or fetch external content, the request is blocked before execution, and the tool call does not proceed. That keeps the assistant useful for code tasks while enforcing a hard boundary around sensitive data. (docs.anthropic.com)
In a CI or shared development setup, the same pattern can be paired with hooks or managed policy settings so the rule set stays consistent across users. The result is a more controlled Claude Code workflow without changing how developers prompt the assistant.
How PromptLayer helps with Claude Code deny rules
PromptLayer helps teams manage the prompts, evaluations, and agent workflows that sit around systems like Claude Code. If you are standardizing safer assistant behavior, PromptLayer gives you a place to observe prompt changes, test behaviors, and keep the workflow understandable as policies like deny rules evolve.
Ready to try it yourself? Sign up for PromptLayer and start managing your prompts in minutes.