Tech Notes
AI Best Practices Part 1 Setting deny permissions before auto mode
Chris Byers
Giving an AI coding agent room to work can save a lot of time. It can inspect a repository, implement a change, and work through failures while you focus on the decisions that need your attention.
Before giving it that freedom, decide which operations should be outside its authority.
A request to fix a database problem should have a defined scope. Resetting the database might make an error disappear while destroying the information the business depends on. The same concern applies to clearing a directory, cleaning up cloud storage, or discarding local changes.
This first article in my AI Best Practices series focuses on explicit deny permissions, using Claude Code as the example.
Understand what auto mode does
Claude Code’s auto mode uses a classifier to review actions in place of routine permission prompts. Explicit deny rules still block matching calls. Auto mode and the separate permission-bypass mode have different behavior, so check which mode your session is actually using. Claude Code permission modes.
I would define the team’s boundaries before starting a long autonomous task. That gives developers a shared understanding of which work belongs in an agent session and which operations need a separate, deliberately authorized workflow.
Decide what belongs in the deny list
My starting rule is simple. If Claude gets an operation wrong and I can’t reliably undo it, that operation belongs in the deny list.
Think through the consequences of a mistake. Can you recover deleted files that were never committed? Restore customer records removed from a database? Retrieve an object after its stored versions have been deleted? If recovery is uncertain, expensive, or dependent on a backup you haven’t verified, keep that operation outside the agent’s autonomous workflow.
Having an undo command somewhere is only part of the question. You need to know that it can recover the affected data and that the business can tolerate the interruption. Use that judgment to identify the operations to restrict, then cover the tools and command forms your team uses to perform them.
Put shared rules in the project settings
Claude Code supports shared project settings in .claude/settings.json. Merge the following example into the existing permissions.deny array, preserving other settings. Commit the file if these are the rules you want the team to share. Organization-wide enforcement belongs in managed settings. Claude Code settings files.
These twelve rules are a deliberately restrictive starting point for a project where the agent develops code locally and production operations happen separately. Several block entire command families, including their harmless uses.
{
"permissions": {
"deny": [
"Bash(git reset --hard*)",
"Bash(git clean *)",
"Bash(rm *)",
"Bash(*prisma db push*)",
"Bash(*prisma migrate reset*)",
"Bash(psql *)",
"Bash(dropdb *)",
"Bash(aws s3 *)",
"Bash(aws s3api *)",
"Bash(git push *)",
"Read(./.env)",
"Read(~/.ssh/**)"
]
}
}
Bash(...) scopes a rule to shell commands. The * wildcard matches variable text. Deny rules take precedence over matching ask or allow rules. Use /permissions to inspect the rules loaded in your session. Claude Code permission syntax.
What each rule is intended to stop
-
Hard resets.
git reset --hardcan discard tracked working changes. The trailing wildcard covers the command with or without a following commit argument. Git reset documentation. -
Repository cleanup.
git cleancan remove untracked files, including work Git cannot restore. This broad rule also blocks dry runs. Git clean documentation. -
Shell file deletion.
rm *covers common commands such asrm -rf build/andrm -fr build/. Blocking the whole command avoids relying on one ordering of its flags. Routine deletion is included in this restriction. -
Direct Prisma schema pushes.
prisma db pushchanges the database schema without a migration history. Flags such as--accept-data-lossand--force-resetincrease the potential for destructive changes. The leading wildcard covers common launcher forms such asnpx prisma db pushandpnpm prisma db push. Prisma db push documentation. -
Prisma database resets.
prisma migrate resetresets the database and reapplies migrations, losing existing data. That can be useful against disposable development data, which is why the target connection matters so much. Prisma reset documentation. -
Direct PostgreSQL sessions. Blocking
psqlrestricts a common route for executing SQL, including destructive statements supplied inline or from a file. It also blocks legitimate queries through that command. PostgreSQL psql documentation. -
Dropping PostgreSQL databases.
dropdbis a separate utility that removes a database, so it gets its own rule. PostgreSQL dropdb documentation. -
High-level S3 commands. Blocking
aws s3covers common object removal commands, moves that delete their source, andsync --delete, which can remove destination objects. It also blocks listing and copying through this command family. AWS S3 command guide. -
Low-level S3 API commands. Blocking
aws s3apicovers another CLI route to S3, includingdelete-objectanddelete-objects. Read operations in this command family are also included. AWS DeleteObjects documentation. -
Publishing repository changes. Blocking
git pushkeeps matching pushes, including force pushes, out of this agent workflow. Your team can review and publish through its chosen process. -
Reading environment secrets.
Read(./.env)restricts access to a matching environment file through Claude Code’s file tools. These files often contain database passwords, API keys, and other credentials. Once a secret is exposed, recovery may require rotating it wherever it is used. Add separate coverage for files such as.env.localand.env.production, for exampleRead(./.env.*), if your project uses them. File rules also apply to recognized shell file reads, but arbitrary scripts can read files indirectly. Keep production secrets outside the agent’s environment and use sandbox restrictions where required. Claude Code file permissions. -
Reading SSH files.
Read(~/.ssh/**)restricts file-tool reads of the SSH directory in your home folder, including private keys and connection configuration. The~/anchor keeps the rule pointed at your home directory when the agent changes working directories. Shell and subprocess access still need the protections described below. Claude Code file path rules.
Match the rules to the commands your team uses
These patterns match command text. Alternative executable paths, options placed before subcommands, scripts, SDKs, and other tools can reach the same operation through a different invocation. Treat the list as coverage for common commands, then examine the actual tool calls in your environment. Claude Code Bash matching limitations.
For example, an npm script might call a database cleanup routine without mentioning Prisma or psql in the command the agent submits. An AWS SDK can delete an object without invoking the AWS CLI. Include equivalent tools and scripts when reviewing your team’s access.
Verify the loaded policy in a disposable environment with throwaway data. Check representative commands and variants using that isolated setup. Keep production credentials out of those tests.
Protect production at the service itself
These rules apply to matching commands in every environment. A filename or a database URL containing the word “production” is too fragile a basis for deciding which data an agent can modify.
Give the agent a dedicated development database and credentials restricted to it. Keep production migration credentials in the deployment workflow. Prisma schema changes, migration deployment, seed scripts, and application code can all write to a database when the connection and account permit it.
For S3, restrict the agent’s AWS identity to the resources and actions it needs. A policy can deny s3:DeleteObject, s3:DeleteObjectVersion, and s3:DeleteBucket for production resources. Review write access and configuration changes too, since overwriting an object or changing lifecycle behavior can also affect stored data. AWS S3 permissions reference.
I want an agent to make progress within an environment designed for its task. Explicit deny rules help express that scope, while restricted credentials, service permissions, and isolated development data enforce what the session can actually reach.