Pre-Action Checks for AI Coding Agents: Tools and Patterns
Will
Updated on August 3, 2026
Will
Updated on August 3, 2026

The best pre-action check tools for AI coding agents are the controls built into the agent harness itself: permission modes, plan review, and pre-execution hooks, backed by sandboxed execution at the OS level and protected paths at the git level. A pre-action check is any control that runs before the agent acts. It inspects a proposed command, edit, or tool call and decides whether it proceeds, gets rewritten, or stops for a human. That is a different job from post-action verification, which runs after the change exists and asks whether it is correct.
Keeping those two jobs separate is the organizing principle of this guide, and we call it the two-gate model:
Teams that run agents in production code run both. A pre-action gate cannot tell you the checkout button stopped working, and a test suite cannot un-drop a table. The failure mode we see most often is a team that invests heavily in one gate and assumes it covers the other.
The rest of this article walks through the seven mechanisms worth knowing, roughly ordered from the agent harness outward: approval prompts, plan review, hooks, sandboxes, git-level rules, CI required checks, and the post-action browser verification that completes the picture. Each entry covers what the mechanism actually intercepts, because "guardrail" is doing a lot of vague work in most writing on this topic.
A pre-action check evaluates an action the agent has proposed but not yet executed. The evaluation can be:
All three appear below. Structural controls (sandboxes, branch protection) are the strongest because they hold even when the agent is confused or a prompt injection is steering it. Rules in a system prompt or a CLAUDE.md file are not pre-action checks: they shape what the agent tries, but nothing enforces them. In Claude Code, for example, permission rules are enforced by the harness, not by the model, and that distinction is the whole point.
The baseline pre-action check in every serious agent harness is the approval prompt: the agent proposes a command or edit, and a human says yes or no before it runs. What makes this a tool rather than a chore is the mode system that decides which actions prompt. Claude Code ships permission modes set via defaultMode in settings: default (prompt on first use of each tool), acceptEdits (auto-accept file edits, still prompt for risky commands), plan (read-only analysis), and stricter or looser modes for special environments. Alongside modes, allow/ask/deny rules give per-tool precision: Bash(git push:*) can require approval while Bash(git status) runs freely. Other harnesses ship equivalents under different names. The pattern to copy: broad categories by mode, sharp edges by rule, and deny for anything you never want proposed at all.
Approval prompts gate one action at a time. Plan review gates the whole approach. In plan mode the agent can read code and search the repo but cannot edit files or run mutating commands; it produces a plan you approve before any execution begins. This is the highest-value pre-action check for large or ambiguous tasks, because the most expensive agent failure is not a bad command, it is thirty minutes of confident work in the wrong direction. Reviewing a plan takes two minutes; reviewing a 40-file diff built on a wrong assumption takes an afternoon. Use it for refactors, migrations, anything touching auth or payments, and any task where you cannot state the expected diff shape in advance. We cover the workflow in detail in Claude Code plan mode. Skip it for small, well-specified fixes, where the planning round-trip costs more than it saves.
Hooks are the programmable pre-action check: your own script runs before every matching tool call and decides its fate. In Claude Code, a PreToolUse hook is configured in settings.json with a matcher on the tool name ("Bash", "Edit", regex like "mcp__github__.*" for MCP tools) and receives the full tool input as JSON on stdin. The hook can block by exiting with code 2 (stderr becomes the explanation the agent sees), or return JSON with a permissionDecision of allow, deny, or ask, and can even rewrite the tool input via updatedInput before execution. That last part matters: a hook can transparently swap npm test for your faster test runner, or append --dry-run to anything scary. Because hooks are deterministic scripts, they enforce policy the model cannot talk its way around: block edits to migrations/, deny any command containing a production hostname, require an issue reference before git commit. Full walkthrough in Claude Code hooks.
Prompts and hooks gate what the agent asks to do. A sandbox limits what any process it spawns can do, which is a stronger guarantee: a Python script the agent writes and runs is invisible to permission rules, but not to the OS. Three tiers, in increasing isolation:
Git hosting gives you pre-action checks that hold even if the agent's own guardrails fail, because they are enforced server-side at push time. Branch protection on main blocks direct pushes and force-pushes regardless of which tool, agent, or human attempts them. GitHub rulesets can restrict changes to specific file paths, so deploy/, .github/workflows/, or a lockfile cannot be modified by a push at all. CODEOWNERS requires a designated human's review before anything touching a listed path merges. The pattern for agent work: agents commit only to feature branches, every change reaches main through a pull request, and the paths that could hurt you (CI config, infrastructure, migrations) carry both a path rule and a code owner. This layer costs nearly nothing to set up and is the one most teams already half-have.
Required status checks sit at the boundary between the two gates. The check itself (tests, lint, type-check, build) is post-action verification: it runs on a diff that already exists. But marking it required turns it into a pre-merge gate: the merge is the action being blocked, and no human override short of an admin bypass lets an unverified agent change into main. For agent-written code this is the single highest-value configuration change in most repos, because it converts "someone should look at this" into "this cannot land otherwise." What belongs in the required set, and how to keep it fast enough that agents iterating on failures do not stall, is the subject of quality gates for AI pull requests and CI/CD for agent-written code.
The final entry is not a pre-action check, and that is the point: it is the complement the first six cannot replace. Every gate above can pass while the app is broken, because "this action is safe to take" and "this change is correct in the browser" are different questions. Shiplight (disclosure: Shiplight is our product) covers the second one. It installs into coding agents as a browser MCP server plus Skills, one-line install, and gives the agent eyes and hands in a real browser: after a change, /shiplight verify loads the app and confirms the flow the change was supposed to affect still works. Verifications become intent-based YAML tests in your repo, self-healing, and transpile to standard Playwright so there is no lock-in. Details in verifying AI-written UI changes and the coding agents overview. If your stack has entries 1 through 6 and nothing here, you have an agent that cannot hurt you and also cannot tell you whether it helped.
| Risk | Right gate | Mechanism |
|---|---|---|
| Destructive command (rm, drop, force-push) | Pre-action | Deny rules, PreToolUse hook, sandbox |
| Agent goes down the wrong path on a big task | Pre-action | Plan mode review |
| Edit to CI config, migrations, or infra paths | Pre-action | Hooks + path rulesets + CODEOWNERS |
| Credential or production-host exposure | Pre-action | Hook on command content, sandbox network allowlist |
| Prompt injection steering the agent | Pre-action | Sandbox (structural, model-independent) |
| Code compiles but logic is wrong | Post-action | Tests as required CI checks |
| Change is safe but the UI flow breaks | Post-action | Browser verification |
| Regression in a flow nobody thought to test | Post-action | E2E suite in CI |
Read the table top-down when triaging an incident: if the damage happened at execution time, you were missing a pre-action gate; if it shipped and users found it, you were missing a post-action one.
Pre-action checks evaluate actions, not outcomes. An edit to CheckoutForm.tsx that renames a field and silently breaks form submission is, by every pre-action measure, a perfectly safe action: an ordinary file, an ordinary edit, no dangerous command in sight. Every permission mode allows it, no sensible hook denies it, the sandbox is irrelevant, and branch rules wave it through on a feature branch. The change is safe to make and wrong in the browser, and only the post-action side can tell you that. This is also why tightening pre-action gates past a certain point buys nothing: you add friction to every action without adding any ability to detect a bad outcome. Whether agents can close that loop on their own code is a real question, and we take it up in can coding agents test their own code. The inverse limit holds too: no test suite runs early enough to stop terraform destroy. Budget for both gates, and spend the deterministic, cheap controls up front and the correctness checks behind the change.
The best pre-action check tools are the agent harness's own controls: permission modes and approval prompts, plan mode review, and PreToolUse hooks, layered with OS-level sandboxing, git branch protection with path rulesets, and required CI status checks at merge time. No single tool covers all risks; the harness controls stop bad commands, while git and CI controls stop bad merges.
Pre-action checks run before an agent acts and decide whether an action may proceed; post-action verification runs after the change exists and checks whether it is correct. Pre-action gates prevent damage like destructive commands and protected-path edits. Post-action gates, tests, CI, and browser checks, prove the change works. Mature teams run both.
Yes. In Claude Code, a PreToolUse hook script receives the proposed tool call as JSON and can block it by exiting with code 2 or by returning a permissionDecision of deny. It can also escalate to a human with ask or rewrite the tool input before execution.
Yes, because permission rules only govern actions the harness can see. A script the agent writes and executes opens files and network connections directly, outside any permission rule. An OS sandbox restricts those child processes too, which also makes it the control that holds against prompt injection.
Usually not. Plan mode pays off when the task is large or ambiguous enough that a wrong approach wastes significant work: refactors, migrations, auth changes. For a small fix where you can predict the diff, the planning round-trip costs more than it saves. Match the gate to the blast radius.
Because it evaluates an outcome, not a proposed action: it needs the change to exist before it can load the app and test the flow. Pre-action checks decide whether an edit is safe to make; browser verification decides whether the made edit actually works. They answer different questions, which is why the two-gate model needs both.
External references: Claude Code documentation on hooks and permissions.