HomeClaude Code › QA automation
OverviewInstallCLI referencePricing & limitsAgent SDKSkills & pluginsGitHubWeb, desktop & IDEModelsErrorsOpen source?TutorialFor studentsQA automation中文指南
Last updated: September 22, 2026

How to use Claude Code for QA automation

Claude Code is unusually good at QA work because QA is a loop it can close on its own: write the test, run it, read the failure, fix either the test or the code, run again. This guide is the practical setup — from a first generated test file to a headless run on every pull request.

TLDR

  • Give it the runner command in CLAUDE.md and it will write, run and repair tests without being told how.
  • Best inputs: a spec, a bug report with reproduction steps, or an existing test file to mirror.
  • Headless: claude -p with --allowedTools in CI; the GitHub Action does the same on pull requests.
  • End-to-end: a Playwright MCP server lets it drive a real browser; keep those sessions short.

What Claude Code can do in a QA workflow

What it cannot do is decide what matters. It will happily reach 100% line coverage with tests that assert nothing useful. The quality of the output tracks the quality of the instruction, which is why the setup below starts with the memory file rather than the prompt.

Setup: tell it how tests run

# CLAUDE.md
## Testing
- Unit tests: `npm test` (vitest). Files live next to the source as `*.test.ts`.
- E2E: `npx playwright test`, specs in `e2e/`. Needs the dev server: `npm run dev`.
- Always run the relevant test file after editing it. Do not mark a test `.skip` to make the suite pass.
- Prefer table-driven tests; one behaviour per `it()`; no snapshot tests for logic.

That block is the difference between an agent that guesses and one that behaves like a colleague who has read the contributing guide. Add the assertion style you want and the things you never want (mocking the database, skipping tests, editing fixtures to match wrong output).

Generate tests from a spec or a bug report

> Read src/billing/prorate.ts. Write vitest tests covering the documented behaviour in
  docs/billing.md, including month boundaries, leap years and a zero-day period.
  Run them; if any fail, tell me whether the code or the doc is wrong before changing code.
> Bug #412: uploading a 0-byte file returns 500 instead of 400. Write a failing test that
  reproduces it, then fix the handler so the test passes. Do not touch other tests.

The last sentence of each prompt matters. "Tell me whether the code or the doc is wrong" stops it from silently changing behaviour to match a test it just invented; "do not touch other tests" stops the classic failure mode where it edits an unrelated assertion to get green.

The run–fix loop

Ask it to run the test after writing it. It reads the failure output, adjusts, and re-runs — usually two or three iterations. Watch the permission prompts: allow Bash(npm test*) and Bash(npx playwright test*) once with /permissions so the loop is not interrupted, and keep destructive commands on ask. If it loops more than four or five times on one test, stop it; the test is probably asserting the wrong thing and a human should look.

Headless in CI

# generate regression tests for whatever changed, non-interactively
git diff --name-only origin/main...HEAD | grep -E 'src/.*\.ts$' > changed.txt
claude -p "For each file in changed.txt, add or extend tests for the changed behaviour. Run them." \
  --allowedTools "Read,Edit,Write,Bash(npm test*),Bash(git diff*)" \
  --max-turns 25 --output-format json > claude-qa.json

Print mode never asks a question, so everything it may do has to be pre-approved with --allowedTools, and --max-turns caps the loop. Set ANTHROPIC_BASE_URL=https://aiprimetech.io and a gateway key as CI secrets and the run bills against your gateway balance or unlimited plan. Commit the result to a branch and let a human review it — do not auto-merge generated tests.

On every pull request: the GitHub Action

The Claude Code GitHub Action runs the same loop when someone comments @claude on a pull request, or automatically on open. A QA-flavoured instruction in the workflow — "review this PR for untested branches and add tests for them" — gives every PR a first pass before a reviewer looks. The GitHub guide covers the App install, the workflow file and the costs.

End-to-end tests with Playwright

Two levels. Without a browser, it writes Playwright specs from the page structure and your description and you run them. With a Playwright MCP server connected (/mcp), it can open the app, click through the flow, read the DOM and write a test that matches what it saw — much more reliable selectors, at the cost of a longer session. Keep browser sessions to one flow each and /clear between them; screenshots and DOM dumps are large and are resent on every turn.

Keeping QA runs cheap

PlanDurationPrice
Unlimited 1 Hour1 hour$1
Unlimited 24 Hours24 hours$10
Unlimited 1 Week1 week$49
Unlimited 15 Days15 days$89

All unlimited plans →

Frequently asked questions

Can Claude Code write unit tests?

Yes — in the project's existing framework and style if CLAUDE.md says what that is. Ask it to run them afterwards so it fixes its own mistakes.

Can Claude Code run Playwright tests?

Yes. It can write specs on its own, and with a Playwright MCP server it can drive a real browser to build and verify them.

Is Claude Code good for QA automation?

For generating tests, closing the write-run-fix loop and triaging CI failures, very. It does not replace deciding what needs testing, and generated tests still need human review before merge.

How do I run Claude Code in CI for tests?

claude -p with --allowedTools and --max-turns, gateway or Anthropic credentials as secrets, and commit the output to a branch for review. The GitHub Action wraps the same thing for pull requests.

Run Claude Code on the gateway

Same models, two environment variables, credits at 7.69× face value — or a flat-rate unlimited plan.

Get an API key See unlimited plans

AI Prime Tech is an independent API gateway and is not affiliated with, endorsed by, or sponsored by Anthropic. “Claude” and “Claude Code” are trademarks of Anthropic. Claude Code features described here follow Anthropic’s public documentation at the time of writing and change frequently; prices and model lists on this page are read from this gateway’s live settings.

More Claude Code guides

Claude Code: the complete guideHow to install Claude CodeClaude Code CLI documentation: commands and flagsClaude Code pricing and limits, explainedThe Claude Code SDK, now the Claude Agent SDKClaude Code skills and pluginsClaude Code in GitHub: the App, the Action and @claudeDoes Claude Code have a web interface? Web, desktop and IDE explainedWhich model Claude Code uses, and how to change itClaude Code errors and how to fix themIs Claude Code open source?Claude Code tutorial: your first real sessionClaude Code for studentsClaude Code 怎么用:从安装到日常使用