Skip to content
mentoor

Topic 1 of 5 · 5 min read

Scoping allow, ask and deny rules

Goal: Write allow, ask and deny rules for a project and find the rule that permits far more than its author intended.

A permission rule is a sentence that says which tool call needs no question, which needs one, and which is refused: write it as narrowly as the task allows. Coding agents such as Claude Code, Codex and Cursor all work this way. Every shell command, file edit and tool call is checked against rules before it runs.

Check yourself · 1 of 3

Which allow rule is the narrowest way to let an agent run the project tests?

Choose one answer

Why it matters

Without rules, the agent asks about everything and you click yes without reading. With rules that are too wide, the agent runs things you never imagined. A good rule set removes the boring prompts and keeps the human for the risky ones.

How to do it

  1. Use three lists. allow runs silently, ask always prompts, deny always refuses. In Claude Code, deny wins over ask, and ask wins over allow, so a deny rule cannot be overridden by a broader allow.
  2. Start from the commands you approve every day: the test runner, the linter, the type checker, git status, git diff. Allow those by exact command or a tight prefix, for example Bash(npm run test:*).
  3. Deny what should never happen, for example reading secrets: Read(./.env) and Read(./secrets/**).
  4. Put each rule in the right file. A personal habit goes in your user settings. A team rule goes in the project settings file that is committed to git. A rule only for your machine goes in the local, git-ignored file.
  5. Review the list monthly. Rules pile up and never shrink on their own.

Before and after

Weak: Bash(git:*) allows every git command, including git push --force and git reset --hard. Also weak: Bash(npm:*) allows npm publish.

Better:

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

What goes wrong

  • Prefix traps. A prefix rule matches anything that starts the same way. Shell tricks such as chaining with && or a pipe can attach a second command to an allowed first one. Current tools try to parse compound commands, but you should not rely on that: keep prefixes tight.
  • Allow rules copied from a blog. They fit someone else's repo, not yours.
  • Deny rules for files, but not for the shell. Denying a file read does not stop cat .env if the shell is open. Pair file rules with a sandbox (see the sandbox topic).

Examples

The rule that allowed publishing

A developer approved npm run build once and chose "always allow". The tool saved Bash(npm:*). Weeks later an agent ran npm publish as part of a release task, and nothing asked. The fix is Bash(npm run build) plus an ask rule for Bash(npm publish:*).

Moving a rule to the team file

Every teammate allows Bash(pnpm test:*). Instead of five personal copies, put it in the committed project settings once. New joiners then get a quiet, safe default on day one.

Key points

  • Rules come in three lists, and deny beats ask, which beats allow.
  • Allow by exact command or a tight prefix, never by a bare tool name such as git or npm.
  • Where a rule lives decides who it affects: user, project (committed) or local (git-ignored).
  • A file deny rule does not stop the shell from reading the same file; combine it with a sandbox.
  • Review the rule list on a schedule, because rules accumulate and are rarely removed.

Common mistakes

  • Choosing "always allow" on a prompt without reading the exact rule that gets saved.
  • Allowing a whole program (git, npm, docker) because one subcommand was needed.
  • Relying on a deny rule for .env while the shell can still cat it.
  • Committing personal, machine-specific rules to the shared project file.

Check yourself · 2 of 3

An allow rule says Bash(git:) and a deny rule says Bash(git push --force:). The agent tries a force push. What happens?

Choose one answer

Check yourself · 3 of 3

Where should a rule that only suits your own laptop live?

Choose one answer

Practice items, not counted towards your mastery.

Start here

More for this topic