Skip to main content

Feature request and design proposal / check against official specification · Source language: English

Connecting AI edits to the tests that relate to the change

A request to run, together after Claude Code edits, the tests related to the changes. We organize the commands you can try now with Vitest, the steps to connect via hooks, and the changes that get missed.

Who:
Requester NaserCambium / technical proposals equinoxaifinance-rgb, Ben-Home
Scope:
One Claude Code user's request and a reply's design proposal. For deciding adoption in a repository that already uses Vitest.
Source published:
2026-10-11
Period observed:
Request and replies: October 11–12, 2026 / check against official specification: November 1, 2026
Editorial check:
2026-11-01

Only the source ID is saved in this browser. Nothing syncs across devices.

For developers who already have tests such as Vitest and want to connect Claude Code's edits and verification.

The primary source is a feature request. Before pasting afterEdits into settings, check whether your existing runner can select related tests.

Try it yourself first

  1. 1. Check your existing tests once

    Confirm that your usual test command runs and that the sources you will change are imported by the tests. The example below is for a repository that already has Vitest.

  2. 2. Run once, specifying the changed sources

    Replace src/cart.ts and src/price.ts in the example with your actual changed files. Add --run to avoid watch mode so the command exits.

  3. 3. See whether it catches the failures you need

    Try a change that includes a known failure and check the selected test names and failure reasons. If zero targets are found, do not assume success; check paths, import relationships and configuration.

./node_modules/.bin/vitest related --run src/cart.ts src/price.ts

The paths are examples for illustration. This is not a command to run as-is in a repository that has not adopted it. The hooks and performance in this example have not been measured.

Connecting it to automation

  1. 1. Record the set of changes

    In the proposal using PostToolUse Edit/Write, edited paths are collected. Changes made through Bash, code generation or external processes do not pass through this route, so prepare another way to capture them.

  2. 2. Decide when to run

    With Stop, tests can run all at once when Claude finishes responding. Even if there are several edits in a long turn, it does not detect the end of each one. Decide based on whether you need immediate feedback.

  3. 3. Hand off safely to a single run

    Design it to merge identical paths and pass file names to the runner as an array of arguments, not by string concatenation. Do not mix other sessions or simultaneous edits, and leave changes that grow during a run for the next set. This is a design matter to decide before adoption.

  4. 4. Return the result and separate the next actions

    On failure, return the test names and failure reasons to Claude and recheck after the fix. Treat only a passing set as complete, and separate a missing runner or a timeout from test failures. Set a limit so the same failure does not repeat forever.

How to read the result

Passed
The selected tests passed.
Check for tests that were not selected, and for the full CI that is still needed separately.
Failed
A test related to the change failed.
Return the failure reason and recheck the same target after the fix.
Zero targets
It cannot distinguish between no target existing and a selection that missed it.
Check the source paths, import relationships and runner configuration.
Could not run
Possible causes include a missing command, an environment problem or a timeout.
Treat it as an environment problem and avoid retrying the same run forever.

What to check before adopting

  • If changes through Bash or generation are also needed, consider using FileChanged or before-and-after diffs in the current official documentation, and check support in the version you use.
  • Separate a person's existing uncommitted changes from the changes made by the AI this time.
  • For tests that depend on dynamic imports, configuration files, or external data and integrations, check whether related selection alone is enough.
  • Decide the execution time limit, the retry limit for the same failure, and how to handle changes that grow during a run.
  • Do not skip existing required tests, CI or review because of this workaround.

On November 1, 2026, we edited this by matching the original request and replies against the official specifications of Anthropic and Vitest. It is not an article reporting a hook adopted in a real environment, nor one verifying shorter test times.

What was confirmed

  • The afterEdits setting is posted as a feature request. At the November 1, 2026 check, the Issue was Open, and we cannot confirm that the setting described there is a finished feature you can use.
  • A reply includes a workaround that collects changed paths in PostToolUse and runs related tests once at Stop. Stop marks the end of a turn and does not match the boundary of each group of edits in the middle.
  • Vitest's official CLI has related. It selects tests from static import relationships of the sources, so misses, such as with dynamic imports through string variables, need checking.

Limits of this source

  • A feature request and a design proposal. It is not a case in which a user adopted it and confirmed the effect.
  • The test counts and seconds in the primary source are assumed examples. HAKOMIRO has not run an adoption trial of the hook or measured speed.
  • Even if related tests pass, overall safety including shared settings, generated processing and external integrations is not confirmed. Existing CI and required tests are kept.

Read the primary source

Links use the original title or a HAKOMIRO source description. Japanese originals retain their published wording.

  1. [FEATURE] Run only the tests affected by Claude's edits after each batch of edits (opens in new tab) ↗

    NaserCambium and equinoxaifinance-rgb / anthropics/claude-code /

    Re-checked the Issue body and the technical replies of October 11 and 12. We separated the feature request, workaround and assumed examples from measured results.

  2. Reply proposing to record changed paths and run related tests at Stop (opens in new tab) ↗

    equinoxaifinance-rgb /

    We matched the primary source text on November 1, 2026. Matching the published content is distinguished from adoption in a real environment and effect verification.

  3. Reply distinguishing the end of a turn from a batch of edits (opens in new tab) ↗

    Ben-Home /

    We matched the primary source text on November 1, 2026. Matching the published content is distinguished from adoption in a real environment and effect verification.

  4. Official Claude Code documentation: hook events, inputs and stop controls (opens in new tab) ↗

    Anthropic / Continuously updated official documentation

    We matched the primary source text on November 1, 2026. Matching the published content is distinguished from adoption in a real environment and effect verification.

  5. Official Vitest documentation: CLI for selecting related tests (opens in new tab) ↗

    Vitest / Continuously updated official documentation

    We matched the primary source text on November 1, 2026. Matching the published content is distinguished from adoption in a real environment and effect verification.