AI agent testing workflow for real codebases
Use AI agents to choose, run and interpret tests without turning every change into a full CI run. Keep the loop focused on behavior, risk and evidence.

Put it into practice
What you will produce
A regression test that fails before the fix, passes after it and covers the boundary or error case most likely to recur.
- 01
State behavior before code
Describe the regression as an observable input, expected outcome and boundary case; use a bug report or product rule rather than the current implementation as the oracle.
Expected result: An independent test expectation that could fail against the broken behavior.
- 02
Locate the narrow test seam
Inspect existing test conventions and choose the smallest unit, integration or user-flow layer that can observe the behavior without duplicating implementation details.
Expected result: A test location and setup consistent with the project and proportionate to the failure.
- 03
Prove red then green
Add or update the test, run it against the unfixed behavior to confirm a meaningful failure, apply the fix, then rerun the same test and relevant regression suite.
Expected result: Recorded failure before and success after the fix, with the assertion tied to user-visible behavior.
- 04
Challenge the assertion
Temporarily reason through or simulate the regression returning; verify the test would fail again and that it also covers the likely invalid or boundary input.
Expected result: A regression test that detects the original defect rather than merely agreeing with the patch.
Acceptance checks
- The expected behavior is sourced independently from the implementation.
- The test fails on the regression before the fix and passes after it.
- Assertions observe behavior rather than private implementation structure alone.
- A meaningful boundary or error case is covered and would fail if the regression returned.
Limits and trade-offs
A passing generated test may merely mirror the implementation. Review its assertions and exercise a meaningful failure case.
Official sources
Map the test loop
Related guides
Claude Code Plan Mode: A Practical Guide
Claude Code Plan Mode lets you review and steer a task plan before any file is touched. Full guide: shortcut (Shift+Tab), activation, when to use it, and how to execute the plan.
Most people use Claude Code like a chat: describe the task, watch it execute. That works for small changes. For anything touching more than two files, there's a better path. If you are looking for the shortcut, press Shift+Tab to toggle Plan Mode. To turn it off, press Shift+Tab again or use /plan only for the prompt that needs planning. The dedicated Plan Mode troubleshooting guide covers the common terminal and version issues. Plan Mode. What Plan Mode does When you activate Plan Mode, Claude reads your codebase and produces a step by step execution plan but makes no changes. You see exactly what it intends to do before a single file is written. This gives you a checkpoint: approve the plan, redirect it, or catch a wrong assumption before it cascades into 15 wrong edits. How to activate Plan Mode the shortcut Two ways: Keyboard shortcut : press Shift+Tab…
Read the guide5 Claude Code Hooks I Use Daily
Claude Code hooks run shell commands on session start, file writes, and tool calls. Here are the 5 I use daily and how to configure them.
Most people discover Claude Code for the AI. They miss the hooks. Hooks are shell commands that execute automatically when something happens in your Claude Code session: a session starts, a tool runs, Claude stops. You define them in .claude/settings.json . They run silently in the background. Here are the 5 I use every day. What hooks look like The available events: SessionStart , UserPromptSubmit , PreToolUse , PostToolUse , Stop . Hook 1 Auto inject date on every prompt Event : UserPromptSubmit Claude doesn't have real time awareness. Every prompt gets the current date injected automatically. Useful for anything time sensitive: changelogs, deadlines, scheduling logic. Hook 2 Push notification when Claude stops Event : Stop Long tasks (refactors, test runs, analysis) can take 2–5 minutes. Without a notification I'd either stare at the screen or miss the result. This fires whenever Claude finishes a task, whether it succeeded or…
Read the guideClaude Code Subagents: Parallel Agents
Learn when Claude Code subagents help, how to split parallel work, and how to configure a focused custom subagent without creating conflicts.
Subagents are useful when a task can be split cleanly: one agent searches the authentication code, another traces the database path, and the main conversation compares what they found. They add little to "read this file" or to work where every step depends on the same context. Short version: delegate independent research or a separate review when the results are worth the extra context and usage. Give each agent a narrow scope, the files or area to inspect, and a specific report format. Keep dependent work in the main conversation. Claude Code agents vs subagents Claude Code's documentation calls delegated workers subagents and uses Agent for the tool that starts them. When people search for Claude Code agents in this context, they usually mean subagents: workers that handle a delegated task in their own context and return a result to the main conversation. Claude Code's subagent documentation uses this terminology.…
Read the guide