Name the owning block, quote a unique textual anchor, state the replacement contract, and identify the surrounding text that must survive. Read the current contents before asking for the edit. A file name alone describes a container, not a target, and a line number can move. When several blocks match, narrow the anchor with neighboring symbols or text instead of guessing. Afterward, inspect the edited region in context. Precise targeting reduces ambiguity, but it does not guarantee an exact change.
Why broad edit requests drift
“Clean up this file” gives the editor too many possible targets. One interpretation fixes naming. Another removes duplication. A third reformats imports or changes error handling. Each interpretation can produce a plausible diff while missing the requested outcome.
The drift is not only about extra work. A broad request can hide the actual requirement. If the goal is to correct one validation branch, unrelated cleanup makes the change harder to review and harder to reverse. The reviewer must separate intended behavior from incidental restructuring.
Official Claude Code best practices supports precise prompts that include file names and symptoms, recorded as F079. That guidance points toward evidence and location. It does not say that naming a file makes every later choice unambiguous. A precise pointer can still match more than one block, so the current text must be inspected.
Use an observable requirement to define the result, then an exact target to locate it. The requirement answers what should change. The target answers where. Keeping those questions separate prevents a location hint from becoming a vague implementation brief.
Edit quality is the subject here, not a testing campaign, permission setup, or large-diff policy. For broader scope control, the negative-requirements guide explains how to protect behavior that must stay unchanged.
What the evidence supports
Official, F079: Claude Code best practices recommends precise prompts with file names and symptoms. The caveat matters for this article: a pointer can match multiple blocks, so current contents still need inspection.
Official, F080: The official prompting best practices recommends clear, explicit instructions and specific output formats. A replacement contract uses that clarity to describe the intended result. It does not guarantee an exact edit.
Independent, F081: The refactoring chapter says developers must verify preconditions when using automated refactoring operations. That is an analogy for checking the target before replacement, not a specification of Claude Code’s Edit tool.
The Claude Code tools reference is included because it is the official companion for tool behavior. The supplied register records it as a canonical link only, so this article does not assert unseen matching mechanics. The memory documentation is fetched, but its instruction guidance does not prove deterministic edit targeting.
No verified benchmark in the packet measures how exact anchors affect edit accuracy. No community issue is used as evidence. The method below is a review practice built from specificity, explicit output intent, and precondition checking.
Select the owning block
Start with the smallest block that owns the behavior you want to change. A function body may be too broad when one branch is wrong. A single expression may be too narrow when the surrounding guard determines its meaning.
Use neighboring symbols to establish ownership. If several handlers format the same message, identify the handler by its name and role. If one configuration block repeats a key, identify the section that contains it.
| Candidate target | Why it may be wrong or right | Better evidence |
|---|---|---|
| Entire file | May include unrelated behavior | Name the function or block that owns the symptom |
| Function signature | May be correct for a contract change but wrong for a body fix | Quote the body anchor and protected signature |
| Repeated error string | May match multiple handlers | Include the enclosing handler name |
| Single line | May omit the condition that gives it meaning | Include the guard or adjacent statement |
The table is a decision aid, not a universal rule about block size. Choose a target that contains enough context to express the change without absorbing unrelated work.
Read the target before writing the prompt. Confirm that the quoted text still exists and that the symptom belongs to it. The precondition check applies the independent lesson in F081 without claiming that Claude Code uses the textbook’s transformation rules.
If the current contents contradict the request, stop and revise the target. Replacing text from an outdated prompt risks applying a change to the wrong location. An exact edit anchor should come from observed text, not memory.
Write a unique textual anchor
A unique anchor combines stable text with local context. A function name, a nearby condition, or the beginning and end of a block can distinguish repeated phrases. Prefer semantic text over formatting details that may change.
For example, showError( may occur in several components. The surrounding statement if (!invoice) { plus the message text can identify one branch. If two branches still match, include the enclosing component or function name in the prompt.
| Search phrase | Unique edit anchor | Reason |
|---|---|---|
return null |
The guard followed by return null inside findInvoice |
Connects the expression to its owning function |
Invalid request |
The validation branch containing Invalid request in submitOrder |
Separates the message from other handlers |
status: 'active' |
The filter object passed by listOpenInvoices |
Identifies the operation, not just the value |
catch (error) |
The catch block inside saveInvoice |
Distinguishes one error path from others |
These examples are illustrative snippets, not claims about repository files or built-in tools. They show how context turns a search phrase into an edit target.
Avoid using a line number as the only anchor. Earlier edits can shift lines, and a copied prompt may outlive the layout. A line number can help a human orient themselves, but stable text should carry the identification burden.
When the anchor is long, quote only enough text to be unique. Pasting a large file into the prompt adds noise and increases the chance of quoting stale content. The file-reference guide explains how targeted references can provide evidence without attaching the whole repository.
Anchor quality also depends on timing. A prompt written before exploration may quote text that later changes. Re-read the target immediately before the edit when the session has performed intervening work. The cost is a small inspection step, and a precise-looking pointer is prevented from resting on stale evidence.
Prefer text that expresses ownership over text that merely looks unusual. A distinctive comment can disappear, while a function name and adjacent call usually explain why the block matters. If both kinds of context are available, use the semantic context first.
Review the target prompt before sending it
Read the prompt without the file open. If the target becomes unclear, the anchor or contract needs more context. A fresh-reader check is a heuristic, not proof that the edit will succeed.
Check that every quoted fragment comes from current contents. Check that the replacement contract names an observable result. Check that protected surroundings are specific enough to find. These questions catch prompts that sound precise but depend on hidden knowledge.
Remove instructions that do not guide the edit. A long warning about being careful adds less than one clear boundary. The prompt-structure guide separates goals, rules, and examples so each part can be reviewed on its own.
State the replacement contract
The replacement contract describes the intended result without prescribing unnecessary implementation steps. Name the behavior, the allowed structural change, and the interface that must remain stable.
For a validation branch, the contract might say: “Replace the guard inside submitOrder so an empty trimmed value returns the existing invalid-order result. Keep the handler name, return shape, and surrounding save call unchanged.” That wording connects a target with an observable outcome.
A weaker contract says “fix validation.” It leaves open whether the change affects trimming, error text, return shape, or another caller. A more specific contract makes review possible because the expected result has a boundary.
Official prompting guidance supports clear instructions and specific formats under F080. The caveat remains: clarity does not guarantee an exact edit. Inspect the result rather than treating the prompt as proof.
For a structural change, add a behavior-preservation statement. The refactoring-scope guide explains how to separate maintainability work from feature work. Exact targeting and behavior preservation solve different problems. A change can hit the right block and still violate the contract.
Preserve the surrounding text
Name what must survive. Protected context can include imports, function signatures, adjacent branches, comments that carry design intent, or call sites outside the target.
A practical prompt structure is:
Target file: <path read in the current session>
Owning block: <function or section name>
Unique anchor: <quoted current text>
Replacement contract: <observable result and allowed change>
Protected surroundings: <text or behavior that must remain unchanged>
Inspection request: <region or relation to inspect after the edit>
This is an editorial prompt pattern, not a built-in command or guaranteed syntax. Replace the placeholders only with inspected facts. If a path or anchor has not been read, do not present it as current evidence.
Protected surroundings make review narrower. A reviewer can compare the intended region without treating every changed line as part of the request. They also give the editor an explicit boundary when adjacent cleanup looks attractive.
Do not turn protection into a brittle transcription exercise. If surrounding text must change for the requirement, name that adjacent edit separately. The exact-block runbook keeps dependent changes visible instead of hiding them inside one broad replacement.
Protection works best when it names relationships as well as text. “Keep the save call after validation” describes an ordering relationship. “Keep everything else” sounds strict but gives the reviewer no way to distinguish an incidental rename from a required dependency change.
A reviewer should be able to point to each protected item in current code. If a protected item exists only in the request, verify it before editing. Precise language cannot make an assumed precondition true.
Resolve multiple possible matches
When an anchor matches several blocks, do not ask the editor to choose silently. Inspect the matches and add the context that distinguishes the intended one.
A useful resolution sequence is:
- Search for the quoted phrase.
- Read each matching block with its enclosing symbol.
- Identify the one that owns the reported symptom.
- Add a stable neighboring statement or symbol to the anchor.
- State the replacement contract and protected context.
The sequence is an editorial method, not a claim about a specific search command. It applies the precondition principle from F081 to the actual text.
If all matches appear equally plausible, the request may be underspecified. Ask a product or code-owner question before editing. The clarification-before-choosing guide separates discoverable code facts from decisions that require a human answer.
Do not use stronger emphasis as a substitute for uniqueness. Repeating “exact” or “only” does not distinguish two identical branches. Better context resolves the ambiguity; emphasis merely decorates it.
A worked exact-block prompt
Consider this illustrative excerpt. It contains two handlers with similar messages, so the message alone is not unique.
function submitOrder(order: Order) {
if (!order.customer) {
return { ok: false, message: 'Invalid request' };
}
return saveOrder(order);
}
function submitInvoice(invoice: Invoice) {
if (!invoice.customer) {
return { ok: false, message: 'Invalid request' };
}
return saveInvoice(invoice);
}
Suppose the agreed requirement is to reject an empty trimmed customer name in submitOrder while preserving the return shape and leaving submitInvoice unchanged. A targeted prompt could read:
In the current contents of the order module, edit only the customer guard
inside submitOrder. Use the adjacent return saveOrder(order) statement to
distinguish this branch from submitInvoice.
Replace the guard so an empty trimmed customer name returns the existing
{ ok: false, message: 'Invalid request' } result. Preserve the handler name,
return shape, message, surrounding statements, and submitInvoice. Read the
edited region in context after the change.
The prompt names the target, anchor, contract, and protected surroundings. It does not rely on a line number. It also leaves implementation choices open beyond the agreed guard behavior.
A reviewer should inspect whether the edited guard handles whitespace as agreed and whether the neighboring save call remains in place. That inspection is part of edit quality. No test suite is prescribed, and the example does not prove all input behavior.
Inspect the edited region in context
Read more than the changed expression. Confirm that the enclosing condition, adjacent statements, and return path still make sense together. A locally correct expression can become wrong when a neighboring branch changes.
Ask focused questions:
- Does the edited block still own the intended behavior?
- Did the replacement preserve the required interface?
- Are protected surroundings unchanged?
- Did a neighboring match receive an unintended edit?
- Does the current text support the next action?
Project verification is not replaced by the review. It checks the edit target itself, which is the subject of this article. For broader completion evidence, use the verification guide without treating its prior coverage as a substitute for inspecting this region.
If the edit landed in the wrong block, stop. Re-establish the anchor from current contents before making another change. Repeated speculative edits make the final diff harder to interpret and increase the chance of touching both matches.
Record the inspected region when work will continue. An inspectable checkpoint can name the edited block, the protected surroundings checked, and any remaining adjacent action. The checkpoint records evidence; it does not certify correctness.
Handle adjacent necessary edits separately
Some requirements genuinely need more than one block. A signature change may require call-site updates. A renamed local value may appear in a neighboring branch. Making those changes visible matters more than expanding the original target without explanation.
| Primary target | Adjacent necessary edit | Why it should be named separately |
|---|---|---|
| One function signature | Direct callers that must match the signature | The interface change crosses block boundaries |
| One local variable declaration | Uses inside the same function | The dependency is local but still inspectable |
| One shared type definition | Consumers that cannot accept the new shape | Scope may need a new decision |
| One error result | A caller that branches on its shape | Behavior can change outside the edited block |
The table does not claim that every caller must change. Inspect the dependency first. If a consumer can remain unchanged, protect it explicitly.
When an adjacent edit changes the agreed direction, pause for a new decision. The plan-revision guide explains how to name evidence that invalidates a plan. Do not hide a broader structural change inside a supposedly exact replacement.
Dependency evidence should answer a narrow question: does this second block consume or expose the changed contract? If not, leave it protected. If yes, name the expected adaptation and inspect its current contents before proposing a replacement.
This distinction keeps an exact edit from becoming a repository-wide cleanup. It also gives an inspectable checkpoint a clear next action: inspect the dependent caller, rather than continue changing nearby code.
Keep the review proportional
An exact target does not require a large planning document. For a small edit, a short prompt with a current anchor and protected surroundings may be enough. Add detail only when a dependency, ambiguous match, or contract question requires it.
Proportional review keeps the method usable. If every tiny edit needs the full runbook, the process becomes its own source of delay. Use the checklist to expose a real uncertainty, not to perform ceremony.
After the edit, spend review attention where the change carries meaning. A local guard deserves contextual inspection. A shared signature also needs its direct consumers checked. The boundary determines the evidence, not the length of the prompt.
For each adjacent edit, repeat the same discipline: current text, unique anchor, replacement contract, protected surroundings, and contextual inspection. This keeps the change set legible without requiring one enormous prompt.
A practical exact-target runbook
Use this checklist before and after a targeted edit.
| Stage | Check | Stop signal |
|---|---|---|
| Read | Current target contents were inspected | Anchor comes from memory or an old prompt |
| Ownership | Enclosing symbol owns the symptom | Several blocks appear equally plausible |
| Uniqueness | Anchor identifies one intended region | Search still returns competing matches |
| Contract | Desired result and allowed change are explicit | Wording only says clean up or fix |
| Protection | Surrounding text and behavior are named | Scope is the whole file without justification |
| Adjacency | Required dependent edits are listed | A hidden cross-file change appears |
| Inspection | Edited region was read in context | Only the changed line was reviewed |
This runbook is an editorial control, not deterministic enforcement. Its purpose is to expose missing evidence before replacement and to make the resulting edit reviewable.
Style belongs in the review too. If the replacement introduces a new abstraction or naming pattern, compare it with local conventions through the style-preserving edit guide. Exact targeting does not excuse an unnecessary structural departure.
Concrete win, loss, and implication
Win: A developer distinguishes two identical error-message branches by quoting the enclosing handler and adjacent save call. The requested guard changes in one handler while the other remains protected. The win is a reviewable edit target, not a measured accuracy score.
Loss: A precise anchor can still be stale. If the file changed after the prompt was written, the quoted text may no longer identify the intended block. Precision cannot replace reading current contents and inspecting the result.
Implication: Treat target selection as a precondition. Name the owning block, use stable text, state the replacement contract, and protect the surroundings. When multiple matches remain, clarify instead of guessing. Name adjacent necessary edits explicitly and finish at the agreed stop boundary.
Data gap and future update
The packet contains no verified benchmark comparing broad prompts with exact anchors. It also contains no verified issue outcome for Claude Code edit matching. The official tools reference was not fully fetched, so no hidden matching algorithm is described.
A future update should add reproducible edit examples with current text, target selection, observed diff, and review criteria on a named surface. That evidence could support a measured comparison. Until then, the article offers a method, not a success rate.
Documentation is live and should be rechecked before publication. The independent refactoring source supports the precondition analogy, not Claude Code internals. No community report is treated as a universal defect.
One AI option for OpenAI-format agents
One AI also serves separate OpenAI-format agents through https://api.oneaiapikey.com/v1, with one key and 46 live free IDs. Review the free model list or use the OpenAI-format quickstart. This option is not a Claude Code model source. The packet records the Claude IDs as unavailable on 2026-11-27, and the free IDs must not be presented as working inside Claude Code.
FAQ
Why not use line numbers as the edit target?
Line numbers can shift after earlier edits and do not explain ownership. Use them as orientation if helpful, but identify the block with stable text and its enclosing symbol.
What makes an anchor unique?
An anchor identifies one intended region in the current contents. Add a neighboring condition, statement, or enclosing function when a phrase appears in several places.
Does a replacement contract guarantee the edit?
No. F080 supports explicit instructions and specific formats, but it does not promise an exact result. Read the edited region in context and compare it with the contract.
Should adjacent edits stay in the same request?
Name them separately when they are necessary. That makes dependencies and scope visible. If an adjacent edit changes the agreed direction, pause for a new decision.
Connect exact targets to the batch
Define the change through observable requirements, goals, rules, and examples, and negative requirements. Clarify intended behavior with acceptance examples, clarification before choosing, and prompt specificity.
Before editing, compare structured agent briefs, plan-mode approval, bounded exploration plans, and task exit conditions. Keep read-before-edit dependencies explicit, and use new-evidence replanning when the target changes direction.
For tool evidence, read unambiguous tool schemas, investigation before answering, independent parallel reads, and evidence-bearing tool results. Use on-demand tool definitions only within its documented API boundary.
For execution quality, continue with inspectable task checkpoints, local style patterns, behavior-preserving refactor scope, and agreed stopping boundaries.
More Claude Code troubleshooting
- Claude Code Reversible Planning: Sequence Small Changes First
- Claude Code CLAUDE.md: Keep Only Instructions Every Task Needs
- Claude Code Progressive Disclosure: Scope Rules to Relevant Files
- Claude Code Context Relevance: Read the Smallest Useful Evidence Set
- Claude Code Conflicting Instructions: Write a Clear Precedence Rule
- Claude Code Image Prompts: Pair Visual Evidence With Written Constraints
- Claude Code Context Audit: Inspect Loaded Files Before Adding More
Sources
- Claude Code best practices, official. Supports F079 and the current-text inspection caveat.
- Claude Code tools reference, official. Canonical link only in the supplied register; no unseen mechanics inferred.
- Claude prompting best practices, official. Supports F080 without an exact-edit guarantee.
- How Claude remembers your project, official. Fetched companion source; not used to claim deterministic targeting.
- Refactoring chapter, independent. Supports F081 as an analogy about transformation preconditions.