AST-Driven Agent Refactoring: How Claude Code Pipelines Verify Their Own Output Before Human Review A developer describes a Claude Code pipeline that wraps refactoring agents in stop hooks, blocking the agent from declaring completion until external checks like tsc --noEmit, eslint, and vitest return zero. Failed checks are fed back into the agent's message history with the exact error output, and the agent retries until all hooks pass or a retry limit is hit. The approach also applies TypeScript Compiler API transforms to the AST rather than raw strings, surfacing type errors at generation time. Manual refactoring across dozens of files burns time. You search for patterns, rename exports, update imports, verify linters pass, check types, run tests, and repeat. The latency stacks with every file. Claude Code closes this loop by running the transform, checking the result, fixing errors autonomously, and presenting verified output. The difference: instead of dictating edits line by line, engineers give Claude a verifiable criterion tests pass, types check, lint succeeds and let the agent retry until the check returns green. The manual search-replace-verify cycle becomes a single prompt with machine-confirmed correctness. Traditional coding agents generate diffs and stop. Claude Code pipelines add a verification layer that runs before human review. The agent executes the refactor, invokes static analysis tools, reads the output, and either completes or retries with error context. Core pipeline stages: The orchestration boundary sits between the agent's reasoning loop and the external tooling that enforces correctness. The agent doesn't guess whether code is valid; it runs tsc --noEmit and reads the exit code. Stop hooks block agent completion until a condition passes. Instead of letting Claude declare success after generating code, the pipeline injects a verification step that must return zero before the agent can finish. Stop hook implementation pattern: js interface StopHook { name: string; check: = Promise<{ passed: boolean; output: string } ; maxRetries: number; } async function runWithStopHooks agent: ClaudeAgent, hooks: StopHook : Promise