Skip to content

All posts

AI

AI coding agent security controls that don't slow developers

Ritesh Patel

AI: AI coding agent security controls that don't slow developers

To keep developers moving, deny a short list of actions and allow everything else. Put destructive commands, secret files and unapproved network tools in deny. Let read-only commands and routine work run without a prompt. Send only the high-risk middle tier to ask, and lock the policy in managed settings so no developer file can loosen it.

Start with a short deny list

The steps and keys below were checked against the Claude Code settings, permissions and hooks docs as of 2026-11-15. The docs do not give one CLI version for these keys. Some keys carry their own minimum, such as v2.1.319 for permissions.denyInsteadOfPrompting.

Keep the deny list to the actions that destroy data, expose secrets or reach the network. A long list fails in two ways: developers route around it, and the team stops reading what it blocks. Each entry should be easy to explain in code review.

  1. Open .claude/settings.json at the repository root. Commit it so every clone gets the same rules.
  2. Add a deny list under permissions.
  3. Save, then run /status in Claude Code to confirm the project file loaded.
{
  "permissions": {
    "deny": [
      "Bash(rm *)",
      "Bash(sudo *)",
      "Bash(git reset --hard *)",
      "Bash(curl *)",
      "Read(./.env)",
      "Read(./.env.*)"
    ]
  }
}

Why deny rules come first

Claude Code evaluates rules in a fixed order: deny, then ask, then allow. The first match decides the outcome, and specificity does not change that. A broad deny beats a narrow allow, so you cannot carve an exception out of a deny rule with an allow entry. That order is what makes a short deny list safe to keep. You do not need a long allow list to make the deny list hold.

The same order covers scopes. A user-level deny blocks a project-level allow, and a managed deny cannot be overridden by --allowedTools. A developer who adds an allow rule in their own file gets nothing from it if the team denies the same call.

Allow reads and routine work by default

Most agent activity is reading files and running normal build, test and lint commands. Those calls should not prompt. Claude Code already runs a built-in set of read-only commands without a prompt in every mode. The set includes ls, cat, grep, find, head, tail, diff and read-only forms of git. You cannot change that set. To prompt for one of those commands, add an ask or deny rule for it.

For project commands, add explicit allow entries. Each one names the exact command, so a developer can see what runs without a prompt.

{
  "permissions": {
    "allow": [
      "Bash(npm run lint)",
      "Bash(npm run test *)"
    ]
  }
}

Escalate only the high-risk calls

The ask tier is for actions that a person should judge in the moment: a terraform apply, a push to a protected branch, or a write to a deployment manifest. Keep the list short. Every ask rule adds a prompt for every developer, every time, so an ask rule for a common command will cost more time than it saves.

For a check a pattern cannot express, use a PreToolUse hook. A hook that exits with code 2 blocks the tool call, and Claude sees the hook’s stderr as the reason. A hook can also return a JSON permissionDecision. A silent exit 0 leaves the normal permission flow in place, so a logging hook does not change any decision.

{
  "hookSpecificOutput": {
    "hookEventName": "PreToolUse",
    "permissionDecision": "deny",
    "permissionDecisionReason": "Destructive command blocked by hook"
  }
}

A hook can add a restriction. It cannot remove one. Claude Code still evaluates deny and ask rules whatever the hook returns, so a hook that returns allow does not lift a deny.

Lock the policy in managed settings

Developer files can be edited, so a policy that lives only there is advisory. Managed settings sit above user, project, local and --settings values. Two keys make the lock stronger.

Key Where What it does
allowManagedPermissionRulesOnly managed Ignores allow, ask and deny rules in user, project, local and --settings files, and hides the always-allow choices in prompts
permissions.disableBypassPermissionsMode any file, usually managed Set to "disable" to stop anyone entering bypass mode
permissions.denyInsteadOfPrompting user or managed Denies calls that would wait on a prompt, so an unattended session keeps running

Use allowManagedPermissionRulesOnly only after the managed file holds the complete deny, ask and allow policy. Project and user rules are ignored once it is on, so a deny list that lives only in a project file stops blocking, and developers also lose the allow entries they rely on, so the prompts return. For the file locations and delivery options, see the managed settings post.

Avoid the friction traps

Three behaviors in the docs slow teams down without warning.

  • Project allow rules wait for trust. permissions.allow in a committed file applies only after each teammate trusts the folder. Until then they see prompts. deny and ask rules apply right away, so put the blocks in the committed file and treat the allow list as something a new clone needs to trust first.
  • Bypass and auto modes are not read from project files. permissions.defaultMode values auto and bypassPermissions do not take effect from project or local settings. Set them in user or managed settings, or pass --permission-mode for one session.
  • A saved approval lands in your local file. When a developer picks “Yes, and don’t ask again”, Claude Code writes an allow rule to .claude/settings.local.json. That file is personal and does not reach teammates, so the same prompt returns for them.

Measure the friction

A guardrail that nobody measures tends to grow. Two signals show whether the policy costs time.

  1. Count the allow entries that appear in each developer’s .claude/settings.local.json. Each one is a prompt someone decided was routine. A long list of them in the same repository suggests the committed allow list is missing entries.
  2. Count permission decisions that waited on a person. Export Claude Code’s OpenTelemetry tool_decision events, which carry the decision and where it came from, and filter to the ones a user answered. Auditing what your coding agent did shows the fields. Compare the weekly count before and after each new ask rule. A PreToolUse hook log is not a substitute: it runs before the permission decision, so it counts attempted calls, not prompts.

Where Kyverno and AIControls fit

Each layer sees a different action. Use the table to decide which layer owns which control.

Layer Sees Where it stops short
Settings deny and ask rules Claude’s Bash, Read, Edit and WebFetch calls Matches the command text, not every path to the program
PreToolUse hook Each tool call before the prompt Only what the hook checks, and it fails open unless configured otherwise
Managed settings Every developer machine it reaches Local admins can edit the file, so redeploy it on a schedule
Kyverno Kubernetes resources at admission, and JSON payloads it is given Does not see a developer’s local tool calls
AIControls Calls routed through the gateway Covers only what the gateway carries

Kyverno is the right tool when an agent’s output becomes a Kubernetes object. It validates that object at admission. It does not see a local rm in a developer terminal, so do not use it for that job.

Enforcing this with AIControls

AIControls sits on the Claude Code traffic path, so it can enforce policy that a local settings file cannot. The confirmed capabilities for this post are: Claude Code through the gateway, per-user and per-session cost and budget limits, and PII that is held for approval or redacted or blocked. Where the hold applies to your deployment, use it for the high-risk tier so that approvals go to the calls that carry sensitive data. Read the coding agent controls page and the AIControls platform page for the details.

Start with the local layers in this post. They cost nothing and they catch the common cases. Add the gateway when you need the same policy across Claude Code, Cursor and Copilot, or when you need a record of each decision. For the reasoning behind keeping people in the loop for high-stakes calls, read AI thinks, humans decide.

Sources

Frequently asked questions

Why not require approval for every Claude Code action?

Because developers then approve prompts without reading them. Claude Code already runs read-only commands such as ls, cat, grep and find without a prompt. If every edit and build also asks, the prompts stop carrying information. Keep the prompts for the few actions where a wrong answer is expensive, and let a deny rule handle the rest.

Is a deny rule enough to stop a destructive command?

It stops the form Claude usually writes. A Bash deny rule matches the command text, so Bash(rm *) blocks rm -rf build/ but not /bin/rm or sh -c 'rm ...'. Pair the deny rule with a PreToolUse hook for those forms, and treat the sandbox and network controls as the real boundary for anything the rules miss.

Can a developer loosen a managed policy in their own settings file?

Not for permission rules, if the organization sets allowManagedPermissionRulesOnly to true in managed settings. Claude Code then ignores allow, ask and deny rules in user, project, local and --settings files, so only managed rules apply. Move your deny and ask rules into the managed file before you turn it on, or the destructive-command and secret-read blocks stop applying.

What is the first control to add to a team's Claude Code setup?

A committed .claude/settings.json with a short deny list for rm, sudo, git reset --hard and reads of .env files. It takes a few minutes, applies to everyone who clones the repository, and does not prompt anyone. Add the ask tier and the managed lock once the team has used the deny list for a while and knows which prompts it actually wants.

Ritesh Patel, Founder & VP Product, Nirmata

Ritesh Patel is a founder of Nirmata and leads its products. He writes about governing AI coding agents, MCP security and Kubernetes policy as code.

LinkedIn

Govern AI agents with AIControlsControl what AI agents do, and prove it.
Share

Stay up-to-date with the latest in AI, governance, and infrastructure

Subscribe to our free monthly newsletter to get industry news, DevOps tips, and articles right to your inbox on Kyverno, containerization, Kubernetes deployment & management and more.