Create a Verification Loop Script for AI Coding Agents

Generate a lightweight bash verification pipeline that validates linters, scoped test suites, and git diff budgets before an agent declares a task complete.

Agent prompt for Claude Code and Cursor

You get: Script File, agent Instruction and risk Note

Prompt

Prompt
Act as a principal DevOps automation engineer. Your job is to draft a single, deterministic POSIX bash verification loop script that an AI coding agent like Claude Code or Cursor must run and pass before submitting changes.

First, ask me 3 brief questions and wait for my response:
1. What is your repository language runtime and package manager?
2. What exact commands run your linter and your scoped unit test suite?
3. What is your maximum allowed line-diff budget (additions plus deletions) for a single agent session?

Rules for the script once I answer:
- Fail immediately on the first non-zero exit code using strict bash error handling.
- Enforce the diff budget using git diff to prevent hallucinated refactors.
- Provide clear standard error messages pointing directly to the failed verification step.
- Return an overall exit code 0 only when lint, tests, and diff boundaries all pass.

Output format:
- Script File: Complete bash script in a single code block.
- Agent Instruction: A two-line system directive instructing the agent how to run and interpret this script.
- Risk Note: One sentence identifying what this loop cannot catch.

Example output

Example for: a TypeScript service using pnpm, eslint, vitest, and a 200-line diff cap.

Script File
#!/usr/bin/env bash
set -euo pipefail

MAX_DIFF=200

echo "[1/3] Running linter..."
pnpm run lint || {
  echo "ERROR: Linter check failed." >&2
  exit 1
}

echo "[2/3] Running scoped unit tests..."
pnpm run test:unit --run || {
  echo "ERROR: Unit tests failed." >&2
  exit 2
}

echo "[3/3] Checking diff budget against HEAD..."
CHANGED_LINES=$(git diff --shortstat HEAD | awk '{print ($4 + $6)}')
CHANGED_LINES=${CHANGED_LINES:-0}

if [ "$CHANGED_LINES" -gt "$MAX_DIFF" ]; then
  echo "ERROR: Diff budget exceeded. Limit is $MAX_DIFF lines, detected $CHANGED_LINES lines changed." >&2
  exit 3
fi

echo "SUCCESS: All verification checks passed (Diff size: $CHANGED_LINES lines)."
exit 0
Agent Instruction

Run ./scripts/verify.sh before finishing any task. If the script exits with a non-zero code, read standard error, fix the exact regression reported, and re-run until you receive exit code 0.

Risk Note

This script checks syntax, unit assertions, and scope size, but it cannot verify runtime database state or cross-service integration contracts.

Written by AI from this prompt. Your results will vary.

Tips and common edits

Why this works

  • Uses strict bash error settings (set -euo pipefail) to block cascading silent failures.
  • Calculates total diff changes through git to stop agents from rewriting unrelated codebase files.
  • Provides exit codes mapped to specific failures so the agent knows whether to fix linting or scope.

Use this prompt in Claude Code, Cursor, or Codex when setting up guardrails for autonomous background runs. Have your build commands and diff limits ready.

Common edits

  • Change the diff check to compare against origin/main instead of HEAD for multi-commit branches.
  • Add a typecheck step like tsc --noEmit or pyright before running unit tests.

Reuse it: Use in a workflowAdapt in the builder

Prompt details

By
Prompts-GPT editors
Published
How prompts are written and checked

Did this prompt work?

AI Coding AgentsClaude Code

Audit AI Code Diffs for Performance Regressions

This prompt scans code changes for silent performance killers like N+1 queries, unindexed filters, and memory leaks before you merge them.

AI Coding AgentsClaude Code

Convert User Stories into Strict Acceptance Test Assertions

This prompt transforms vague business requirements into precise Given-When-Then test assertions with exact HTTP status codes and JSON payload structures for AI coding agents.

AI Coding AgentsClaude Code

Create Automated Verification Loops for Long-Running Coding Agents

Generate a deterministic shell pipeline that combines linting, isolated unit testing, and diff-budget monitoring to validate AI agent code changes.

AI Coding AgentsClaude Code

Design a Sandbox Security Policy for Autonomous Coding Agents

Generate a rigorous security policy for autonomous agents to define allowed shell commands, file access boundaries, and network restrictions.

AI Coding AgentsClaude Code

Generate Reproducible Bug Fix Specs for Coding Agents

Get a standalone reproduction test script and a precise technical plan to fix a bug, ensuring your AI agent stays focused and avoids unnecessary file changes.