Skip to navigation

Claude Code Test Selection: Map Changed Code to Checks

In short: Build a changed-file-to-test map, run the smallest relevant checks first, then record what remains unverified.

Published 23 min read
On this page

Direct answer

Map the paths you changed to the test areas that own them, run the smallest relevant check first, and write down what you did not run. Claude Code works best when you hand it a check that returns pass or fail, so it can close a work loop instead of guessing whether the edit is finished. The changed-path list comes from Git, and the mapping from path to test area is a table your team maintains.

The order that works in practice is fast and narrow first, broad and slow only when something justifies it. A failure, a change at a configuration or public boundary, or a path with no mapped check are all reasons to widen the run. The output you keep is two lists: the checks you executed with their results, and the scope you skipped with the reason.

Treat the result as a scoped observation. Selecting tests does not prove the change is correct, and it does not replace the checks your repository already requires. It shrinks the feedback loop and makes the remaining uncertainty visible instead of hidden inside a green summary.

Why test selection is a time and safety problem

A full suite on every small edit costs minutes of local waiting and, in a shared pipeline, measurable compute. The pressure that creates is familiar: run everything and the change takes an hour to validate, or run nothing and ship on review alone. Both extremes lose. The first wastes the day on checks unrelated to the edit, and the second hides an untested path behind a confident summary.

Selection reduces that cost, but it introduces a different risk. A selected run can look complete. A developer who sees five passing checks may stop thinking about the six files the change also touched. The unit of progress is not “the suite passed”, it is “these checks passed, and here is the list of behaviors I did not exercise”. That distinction is what keeps a fast loop from turning into a false one.

There is also an economic angle. The Claude Code cost per verified change guide argues that generated output and verified work are different units. Selection fits that frame: every check you add to the set is a cost you accept in exchange for a specific reduction in uncertainty. Adding a slow end-to-end suite to a one-line copy change buys almost nothing. Adding it to a change that alters a shared request contract may be the cheapest option available.

Evidence map linking changed files to a maintained test map, a risk rating, and a scoped check decision.
Editorial evidence map based on F001, F002, and F003. A targeted run is a scoped observation, not a completeness claim, and the map is maintained by people rather than generated by the agent.

Evidence and its limits

Official, F001: Claude Code best practices recommends giving the agent a check that returns pass or fail so it can close the work loop. That supports building a selected check set and asking the agent to run it. It does not say the selected set is complete, and it does not turn a passing run into proof of correctness.

Official, F002: Git show prints the content and metadata of a specific commit, and Git log lists history for the paths you name. Together they supply the changed-path list and the recent history behind a file. The mapping from those paths to test areas is a human-maintained workflow, not a built-in Claude Code impact-analysis feature.

Derived, F003: Start with the checks relevant to the change and broaden the run when failures, boundary changes, or missing evidence raise uncertainty. This ordering is a heuristic adapted to your repository, not a rule with a measured defect-reduction effect.

No claim in this post depends on a specific CI provider, package manager, or language. The test commands are illustrative shapes, and the framework documentation listed in the sources is linked as further reading rather than quoted as repository fact.

What changed and what could it affect

Selection starts with an accurate changed-path list. Guessing from memory misses renamed files, moved modules, and the generated files that some tooling edits alongside source. Two Git commands cover most cases:

git show --name-only --format="" HEAD
git log --oneline -5 -- src/billing/discount.ts

The first prints the paths touched by the current commit. The second shows the recent history of one file, which is useful when you need to know whether the area changes often or has been quiet for months. A path with a long history of fixes is a stronger candidate for a broader run than a path nobody has touched since it was written.

A changed path by itself does not tell you what to run. You need the second half of the map: which test areas own which production paths. Ownership is a team decision, and the useful version is small enough that an engineer can hold it in their head.

Changed path Candidate test area Smallest useful check Owner
src/billing/discount.ts Unit tests for the pricing module Module test file for pricing Billing team
src/billing/discount.ts consumers Tests for components that call pricing One test per calling surface Billing plus UI team
src/api/routes/orders.ts Request-level checks for the orders route Orders route test file Orders team
migrations/0042_add_index.sql Schema or data checks, plus a staged migration rehearsal Migration rehearsal on a copy Data platform
config/feature-flags.json Flag-dependent behavior in every consumer Flagged-path checks, then a broader run Platform team

The map does not need to be exhaustive. It needs to cover the paths that change often and the paths whose failure would be expensive. When a changed path has no owner in the map, that gap is itself a finding worth recording.

Build the changed-path test map

A usable map has four columns: the production path or path pattern, the test area that covers it, the smallest check that would notice a regression, and the team that owns the decision. Keep the patterns coarse. A rule that maps src/billing/** to the pricing tests is easier to maintain than twenty exact file pairs.

Two properties make a map trustworthy. First, it is versioned with the code, so a new module arrives with a row rather than a guess. Second, it records gaps deliberately. A row that says “no automated check, verified by manual review” is more useful than an absent row, because it tells the next engineer that this path is unverified by selection alone.

Keeping the map small enough to use

The common failure of a test map is not a missing row. It is a map that grew until nobody reads it. A file with several hundred path patterns, many of them overlapping, produces arguments about which rule wins rather than a decision about which check to run. The fix is to keep the map at the granularity where a person can resolve a conflict in a few seconds.

Three habits keep the size down. Collapse sibling paths into a directory pattern when every file in that directory maps to the same test area. Delete rows for code that no longer exists during the same change that removes the code, so the map cannot accumulate entries for deleted modules. Treat an owner column as a team, not a person, because a person’s name goes stale the week they change roles.

A small map also makes the gaps visible. When most rows are filled and a few are deliberately blank, the blanks stand out as known gaps. When half the rows are blank because nobody maintained the file, the blanks carry no information. Keeping the map short is what gives the record in the next section its meaning.

The map is also where you decide what a boundary is. A shared helper used by three surfaces has three consumers, and a change to it may need a check per consumer. A private function used in one file may need only its own test. That judgment is behavioral, and it is the part an agent cannot supply from the diff.

Claude Code can help you draft the map from the repository, and the resulting table still needs review. The generated tests oracle bias guide describes the trap of letting generated artifacts define their own standard of correctness. A generated map that points every path at a generated test inherits the same weakness.

For the boundary decisions around a shared interface, the duplication guide covers the complementary question of whether similar code should be consolidated or left independent. Two copies with different owners often need their own checks, and merging them into one helper changes how wide the selection has to be.

Choose fast checks before broad suites

Order the selected checks by two factors: how directly they exercise the changed behavior, and how long they take. Fast and direct checks come first. Slow and indirect checks wait for a reason.

A practical order looks like this. Start with the unit-level check for the changed module, because it runs in seconds and fails close to the edit. Next, run checks for the direct consumers of the changed interface, since those catch contract breaks the module test cannot see. Only after those pass, and only if the change crosses a configuration, schema, or public boundary, add the slower integration or end-to-end checks that the repository already maintains.

Selection is also not a substitute for assertions that can tell a failure from a pass. The mutation testing guide describes how a surviving mutant exposes a check that could not fail even when it ran. A fast check with weak assertions is a fast way to learn nothing.

The framework documentation in the source list describes how to scope a run in each ecosystem. Jest CLI options and Vitest configuration cover path filters and project selection for JavaScript repositories, and the Pytest plugin list is the entry point for the plugins a Python repository may already use. Treat those pages as references for the flags your repository supports, not as evidence about your project’s runtime.

Signal Why it justifies a broader run What to add
A selected check fails A failure proves the selected scope is insufficient Fix or narrow, then rerun the same set before widening
A config or flag file changed Flag values alter behavior across consumers Checks for each flagged path, then the consumers
A public interface changed Consumers outside the repository may depend on it Contract or interface checks, plus a compatibility review
A changed path has no mapped check Selection has nothing to say about that path Manual review, or a new check before merge
The change spans more than one owner’s area Ownership boundaries hide cross-team effects Checks from each owning area
Workflow from changed files through a test map, a risk decision, and an ordered set of selected checks.
Editorial workflow based on F001, F002, and F003. The sequence describes a reviewable routine; it is not an official Claude Code command or a measured time saving.

Handle boundary and configuration changes

Boundary changes are the ones that make targeted selection dangerous. A change to a public function signature, a request or response shape, a database schema, or a feature-flag default can affect code that never appears in the diff. The changed file is the center of the effect, not the whole of it.

Three boundaries deserve explicit treatment. A public API boundary means consumers outside the changed repository may break, and the compatibility question is a review decision rather than a test result. A persistence boundary means a schema or migration change affects existing data, and a check against a fresh fixture says little about production data. A configuration boundary means the same code behaves differently across flag values, so a run with one flag setting does not cover another.

The snapshot review guide covers one narrow version of this: a stored expectation can hide a boundary change if nobody reads the diff. The same caution applies to any check that compares against a recorded artifact rather than a stated behavior.

For a public interface change, pair the selected checks with a compatibility decision. The contract tests guide shows how to record the interactions a consumer relies on and verify the provider against that record. The SemVer decision guide covers how to choose a version increment from consumer impact rather than diff size.

Worked example: a pricing helper change

Suppose a commit changes src/billing/discount.ts, a helper that three surfaces call: a cart summary, an invoice renderer, and an order export. The helper has its own test file, and each consumer has a test file that exercises one call path.

The changed-path list from git show --name-only contains one file. The map turns that into four candidate checks: the pricing module test, the cart test, the invoice test, and the export test. The module test runs first because it is fast and directly exercises the changed logic. The three consumer checks follow, because they are the surfaces that would notice a contract break.

A useful record after the run looks like this:

Executed check Result Skipped scope Remaining uncertainty
When the remaining uncertainty is a class of inputs rather than a missing check, property tests are the narrower fix. The property tests guide covers stating an invariant and letting bounded generation search for the input that breaks it, which turns “cases the test does not express” into a concrete counterexample.

| Pricing module unit tests | Pass | None for the helper’s stated cases | Cases the test does not express | | Cart summary consumer tests | Pass | Rounding across a full cart total | Multi-item totals with mixed discounts | | Invoice renderer consumer tests | Pass | Locale-specific currency formatting | Formats not covered by fixtures | | Order export consumer tests | Not run | Export path, scheduled job context | Whether the job supplies different inputs |

The fourth row is the honest part of the record. The export path was not run because its test requires a scheduled-job fixture that the local loop does not set up. Record the decision, do not hide it. If the export job supplies inputs the other consumers never do, the gap is material and the change should wait for a broader run.

The concrete win in this example is early signal: the module test fails in seconds when the discount logic is wrong, without waiting for a full pipeline. The concrete loss is the fourth row, which a green first row could easily have obscured.

Tradeoff between a fast narrow check set and the unverified scope that remains outside it.
Editorial tradeoff diagram based on F001 through F003. Faster feedback narrows the evidence; the unverified scope does not disappear, it becomes a recorded gap.

Record skipped tests and their reasons

A selection run produces two artifacts of equal value. The first is the result of each executed check. The second is the list of checks you considered and did not run, with the reason. Without the second list, a targeted run is indistinguishable from an incomplete one.

The record format overlaps with the evidence ledger in the debug log guide, which separates observed facts from predictions. A selection run is a small version of that ledger: the command, the observation, and the decision.

A useful record has one row per check and one row per deliberate skip. Reasons that hold up in review are specific: the check needs an external service unavailable locally, the check covers a path the change does not touch, the check takes longer than the decision it informs. Reasons that do not hold up are vague: “not needed”, “should be fine”, “CI will catch it”.

The skip record also feeds the escalation decision. If three skips in a row point at the same missing area, the map has a gap, and the fix is a new check or a new mapped row rather than a longer prompt. The deterministic tests guide covers the related case where a check exists but cannot run reliably because of uncontrolled time or randomness. A skip caused by fixture leakage belongs in the fixtures isolation guide, which treats shared state as the thing to fix rather than a reason to retry.

Recording skips is also how a team avoids the failure mode the false-success discussion describes: a passing subset read as though it were the whole system. The record keeps the boundary of the evidence in view for the person reviewing the change.

Escalate from targeted to broader runs

Escalation is a decision, and it should have stated triggers rather than mood. Write the triggers next to the map so the person running the checks does not have to invent a threshold under pressure.

A short escalation runbook:

  1. Run the smallest mapped check for each changed production path.
  2. On a failure, stop widening. Fix the cause or narrow the change, then rerun the same set.
  3. If the change touches a configuration, flag, schema, or public interface, add the consumer checks named in the map.
  4. If any changed path has no mapped check, add a manual review step to the change record, or add a check before merge.
  5. If two or more selected checks fail in unrelated areas, widen to the area-level suite rather than chasing individual failures.
  6. Stop when the remaining uncertainty is recorded and accepted, not when the run happens to be green.
Executed check Result Skipped scope Remaining uncertainty
Module unit tests for changed paths Pass Edge cases outside stated inputs Inputs not expressed by the test
Direct consumer checks Pass Scheduled or background callers Inputs supplied only by those callers
Flagged-path checks Conditional Flag combinations not in the map Behavior under unmapped combinations
Area-level suite On trigger Cross-area interactions Integration effects outside the area

Two escalation cases have their own guides. A check that fails only under some interleavings points at a concurrency assumption, and the async races guide covers making the ordering explicit before widening the run. A failure that moves between tests when order changes points at state leakage, and the fixtures isolation guide covers giving each case a fresh boundary.

The trigger table is deliberately conservative. Widening a run is cheap relative to the cost of a missed regression, but it is not free, and a trigger that fires on every change is a trigger nobody reads.

Runtime budget as part of the selection decision

Selection has a time budget whether or not a team writes it down. A local loop that exceeds a few minutes gets skipped under deadline pressure, and a skipped loop is worse than a narrow one because the skip is invisible. Putting the budget in the map, next to each check, turns an implicit constraint into something the next engineer can plan around.

Record two numbers per check when you know them: the typical wall-clock time and the last time someone confirmed it still runs green. The first prevents the common mistake of adding a slow check to a fast set and calling the result fast. The second distinguishes a check that is maintained from one that has quietly rotted and now fails for unrelated reasons. A rotted check in the selected set is a tax on every future run, because the person running it has to decide each time whether the failure matters.

The budget also settles arguments about ordering. A check that takes four times longer than the rest of the set combined does not belong in the default loop, even when it is relevant. It belongs behind an escalation trigger, where the extra wait is justified by a specific signal. The complexity guide covers the same discipline from the other direction: a hotspot that makes every change expensive is worth refactoring so the check set can stay narrow.

For the cost side of a shared pipeline, the usage tracking guide and the cost per verified change guide give the economic frame. Every check in the default set is a recurring cost paid on every change, and a recurring cost should earn its place repeatedly rather than once.

Review the evidence with Claude Code

Once the check set is defined, hand it to the agent as a pass-or-fail loop. The official guidance behind F001 supports exactly this shape: a named check, a clear result, and a bounded task of making that check pass without breaking the others. Give the agent the commands and the paths, and ask it to report results rather than summarize intent.

Ask for three things in the report. The commands it ran and their exit status. The files it changed. The checks it could not run and why. A report that omits the third item has not finished the selection task, because the reviewer cannot tell scoped evidence from a partial run.

Claude Code does not maintain your test map and does not perform impact analysis across the repository on its own. The boundary behind F002 is this: Git supplies the changed paths, and the mapping is the team’s. Reviewing the agent’s proposed check set against the map is the reviewer’s job, and it is the step that catches a set built only from the files in the diff.

The verification guide develops the review questions in detail: what changed, what proves it, and what was not checked.

Control checklist covering changed-path evidence, test map coverage, ordered checks, and a recorded skip list.
Editorial control checklist derived from F001 through F003. Passing the checklist shows the selection was recorded honestly; it does not prove the change is correct.

Stop conditions and follow-up

Stop the selection loop under three conditions. The first is a mapped check that fails and cannot be fixed inside the change’s scope, which means the change is not ready. The second is a changed path with no mapped check and no acceptable manual review, which means the map needs a row before the change merges. The third is a run where the remaining uncertainty is written down and the owner accepts it.

Follow-up work comes in two forms. If the run exposed a missing check, the follow-up is a new mapped row or a new test, filed while the context is fresh. If the run exposed a flaky check, the follow-up is a triage task rather than a retry, and the flaky tests triage guide covers how to investigate before enabling reruns. If the slowness of a broader suite is what pushed the team toward selection in the first place, the complexity refactor guide and the static analysis baseline guide cover adjacent quality work that keeps the selected set meaningful.

Check Pass condition If it fails
Changed-path list Derived from Git, not memory Rerun git show --name-only
Map coverage Every changed production path has a row or a recorded gap Add the row or the review step
Check order Fast direct checks ran before broad ones Reorder before the next change
Skip record Every skip has a specific reason Rewrite vague reasons
Escalation Triggers were applied as written Apply the missed trigger now
Acceptance Remaining uncertainty is recorded and owned Do not merge on a green subset alone

The practical implication is that selection is a recording discipline as much as a speed technique. The speed comes from running less. The safety comes from writing down what you did not run, so the reviewer can price the gap instead of assuming it away.

Verdict that a mapped, ordered, recorded check set improves feedback speed while leaving a stated unverified scope.
Editorial verdict based on F001 through F003. Selection improves the feedback loop and makes gaps visible; it never converts a targeted run into a completeness claim.

Selection sits between the edit and the merge, and the surrounding steps have their own guides. Before proposing a check set, shrink the failure to a minimal repro so the check is exercising the actual defect. After the checks run, write atomic commits so each unit can be verified and reverted on its own, and encode the change intent in the commit message so a reviewer knows what the check set was meant to cover.

At merge time, choose a branch policy and define what a merge check requires. The selected checks are the local loop; required checks are the enforced one, and the two should agree about which behaviors matter. If the pipeline uses a queue, the merge queue recovery guide covers what to do when a grouped run fails for reasons the local selection could not see.

For release-adjacent verification, tag the exact reviewed commit, record the backport scope when a fix moves to a release branch, and plan a revert before release so the inverse change is not invented during an incident. Keep a release checklist that connects the tag, the checks that ran, and the rollback unit.

Data gap and future update

The research register contains no measured effect for changed-path test selection in this cluster. No reduction in pipeline minutes, escaped defects, or review time is claimed, and none of the cited documentation provides one. The workflow is derived from Git’s documented ability to report changed content and from Claude Code’s documented support for pass-or-fail checks.

There is also no repository-specific data here: no CI provider, package manager, language version, or test runner configuration was inspected. The framework pages in the source list were checked for reachability, and some were not fully content-reviewed, so treat them as entry points rather than quoted specifications.

A future update should add three things if they become available. A measured comparison of selected versus full runs on a real repository. A documented pattern for maintaining the map as modules move. A note on how individual CI providers expose changed-path detection, since that varies by provider and plan.

One AI API Key option for OpenAI-format agents

Claude Code uses an Anthropic-format route, so the One AI free model IDs are not a Claude Code model source. The packet records Claude IDs as unavailable on 2026-11-27.

For a separate OpenAI-format agent, One AI API Key offers https://api.oneaiapikey.com/v1, one key, and 46 live free IDs. That is a different client and request format, not a workaround for Claude Code authentication. Check the free model list and eligibility notes before choosing an agent route.

FAQ

Does running a selected subset prove my change is correct?

No. The selected checks are evidence about the behaviors they express. F001 supports using a pass-or-fail check to close a work loop, and F003 supports ordering checks by relevance. Neither turns a subset into a completeness claim. Record the unverified scope alongside the results.

How do I find the tests that cover a changed file?

Start with the changed-path list from git show --name-only, then look up each path in a maintained map of production path to test area. Git history from git log helps you judge how often the area changes. A repository search for the changed symbol can suggest consumers, but a search result is a lead to review, not a complete caller list.

Should I just run the full suite instead?

Run the full suite when the change justifies it: a public interface change, a schema change, or a change spanning several owning areas. Selection is for the common case where a small change touches a known area and the full suite would spend most of its time on unrelated behavior. The skip record is what makes a narrow run acceptable.

What if the agent says all checks pass but skips some quietly?

Ask for the command list with exit statuses and the list of checks it could not run. If a skip has no specific reason, treat the run as incomplete. The mapping from paths to checks is yours to review, and an agent report is one input to that review rather than a substitute for it.

Can Claude Code build the test map for me?

It can propose a draft by reading the repository, and the draft needs review before it becomes the team’s map. A map generated only from the current diff tends to point every path at the tests nearest to it, which is the same oracle weakness described in the generated-tests guide. Keep map ownership with the team.

More Claude Code troubleshooting

Sources

  • Official: Claude Code best practices, supporting pass-or-fail checks that close a work loop (F001) and broadening a run as uncertainty grows (F003).
  • Official: Git show, supporting changed content and metadata for a single revision (F002).
  • Official: Git log, supporting path-scoped history for a changed file (F002).
  • Official: Jest CLI options, reference for scoping a JavaScript test run.
  • Official: Vitest configuration, reference for project and path configuration.
  • Official: Pytest plugin list, reference for Python test tooling plugins.
More in Blog

Try it

One API key for GPT, Grok, DeepSeek, Kimi, GLM, MiniMax, Qwen, Step, Beam, Nemotron, ERNIE, Hunyuan, Gemma, Laguna, LFM, LongCat, Llama, Solar, Jais, Mistral, K2 and Roleplay.

One AI API Key speaks the OpenAI and Anthropic formats, so you change the base URL and the key, not your code. Credit packs start at $10, and every model has a published per-token rate.

New accounts$10 credit on sign-up
  • 100requests
    per day
  • 3Mtokens
    per day
  • 47free
    models
  • $0per
    token
  • No card
  • No end date
Claim $10 credit →