Create a Stop Hook Script
Create a project-local hook script and read Claude’s stop-hook input from standard input. Track the session, current directory, changed files, and retry count without writing secrets to logs.
Use an agent stop hook to run project-specific checks when files change, feed actionable failures back into the same session, and finish only when the bounded validation loop passes.

John configures a Claude Code stop hook that detects changed files, runs a Bun type check, sends structured error output back to Claude, and commits only after the checks pass.
A bounded post-task loop that catches relevant defects, returns clean diagnostics to the agent, and records a validated change without touching unrelated work.
Claude for coding tasks
Step by step
Follow the sequence once, then adapt the prompts, checks, and handoffs to your own setup.
5 steps
Create a project-local hook script and read Claude’s stop-hook input from standard input. Track the session, current directory, changed files, and retry count without writing secrets to logs.
If no relevant files changed, exit cleanly. Otherwise map the changed paths to focused commands such as typecheck, lint, tests, formatting, dependency checks, or document validation.
When a check fails, emit one valid JSON response that names the command, exit status, affected files, and concise diagnostic output. Reserve standard output for that response.
Fix the reported validation failures without changing unrelated files. Rerun the failing command, explain any remaining error, and stop after [maximum attempts] rather than repeating the same edit.
When checks pass, inspect the exact task diff and sensitive-file rules. If automatic commits are allowed, stage only the task-owned files and generate a conventional commit message; otherwise leave the validated diff uncommitted with a summary.
Role: You are an expert programmer who writes git commit messages in the conventional commit format. Task: Generate a git commit message for the following code changes. Diff: [paste git diff] Output only the commit message.
Register the script as a project stop hook in Claude settings, test no-change, failing, repaired, retry-limit, and success paths, and keep the full CI suite as an independent gate.
{"hooks":{"Stop":[{"hooks":[{"type":"command","command":"bun run claude-hooks/index.ts"}]}]}}Turn an idea into a PRD, user stories, and a plan.
After the steps
How to recover when the loop fails and where human judgment helps.
Recover
Keep building

Create context-aware guardrails for your enterprise AI agent using a 'Project' governance layer. As a project owner, define rules, scope tools, and require human-in-the-loop approval for sensitive actions, ensuring safe and effective AI use.

Transform a successful AI chat session into a reusable skill that anyone in your company can use. Package prompts, tools, and code into a standardized workflow, making it easy to share and scale automation across your organization.

Use a natural language AI agent to instantly generate and iterate on custom data dashboards. This workflow queries your company's data securely, allowing non-technical users to perform their own 'last mile' data analysis without filing tickets.
Join 100,000+ product managers who use ChatPRD to write better docs, align teams faster, and build products users love.