Ask Claude Code to inspect the surrounding code and match its naming, structure, and error-handling conventions before proposing a new pattern. Name the specific convention that matters. Follow local patterns when they support the requirement, but surface conflicts instead of copying a bug or inconsistency. Prefer the smallest conventional change, and ask before adding an abstraction. After editing, inspect the region in context and record any deliberate deviation. Consistency is useful evidence, not proof of correctness or maintainability.
Why style drift creates review work
A correct change can still feel foreign in a codebase. Different naming habits, result shapes, guard order, or error paths force the reviewer to learn a new local dialect. That cost appears even when the new approach is defensible.
Style drift also hides the actual change. If a small behavior fix introduces a helper hierarchy and a new error type, the diff contains several decisions. Reviewers must separate the required correction from incidental design. That makes feedback slower and rollback harder to reason about.
Local patterns provide a practical baseline. Existing code shows how neighboring operations name values, return failures, and organize control flow. Those patterns are discoverable evidence, so they do not all belong in always-loaded project instructions. Official best practices supports keeping project instructions focused on non-discoverable information such as team decisions, recorded as F082.
Consistency still has a limit. Copying a broken guard because nearby code uses it spreads the defect. Treat local style as a default that must serve the requirement, not as an authority that overrides correctness. The observable-requirements guide keeps the requested behavior visible while the negative-requirements guide protects behavior that must not change.
What the evidence supports
Official, F082: Claude Code best practices recommends keeping project instructions focused on non-discoverable information such as team decisions. Discoverable code patterns can be inspected directly. They do not all need to be copied into CLAUDE.md.
Independent, F083: The refactoring chapter describes refactoring as improving maintainability without changing behavior. Maintainability and stylistic consistency are related, but they are not identical. Matching nearby syntax alone does not establish a maintainability improvement.
Official, F084: Claude Code best practices advises against unnecessary abstraction layers during review. A new pattern may still be necessary when local patterns conflict with the requirement, so the guidance is not a ban on deviation.
The memory documentation is a fetched official companion source. It does not make every local convention mandatory. The tools reference appears as a canonical link only in the supplied register, so no unseen edit behavior is inferred from it. The independent requirements guide is search-index evidence only and supports documenting constraints, not Claude Code behavior.
No verified benchmark in the packet compares style-preserving edits with novel patterns. No community report is presented as evidence. A review method is what this article offers, not a claim that imitation guarantees quality.
Identify the surrounding pattern
Begin with the code that will surround the edit. Read neighboring functions with similar responsibilities, not just the target block. Look for repeated choices that appear intentional and useful.
Relevant evidence can include:
- Names for identifiers, result values, and failure cases.
- Guard order and early-return structure.
- Result objects, thrown errors, or returned tuples.
- Dependency access and helper placement.
- Comments that explain a non-obvious local decision.
Record the pattern in plain language. “Nearby loaders return a result object with data and error” is more useful than “match the style.” The named pattern gives the editor something concrete to follow and gives the reviewer something concrete to inspect.
Use targeted file references instead of attaching a large sample. The file-reference guide explains how to add evidence without repository noise. A small set of relevant examples is easier to compare than an entire directory.
Disagreeing patterns should not be resolved by silent selection. Note the conflict and determine whether it reflects separate responsibilities, legacy accumulation, or a missing team decision. The conflicting-instructions guide addresses instructions, but the review habit applies: more emphatic prose does not resolve contradictory evidence.
Name the convention that must be preserved
A useful style request names a convention and its purpose. For example: “Follow the neighboring handlers’ result-object pattern so callers keep the same error path.” That statement explains both the pattern and why it matters.
Avoid a long list of superficial preferences. Import order may matter to the project’s formatter, but this article is not a formatter configuration guide. Focus on conventions that affect readability, interface expectations, or control flow.
| Local pattern | Evidence to inspect | Preserve or revise |
|---|---|---|
Result object with data and error |
Neighboring handlers and their callers | Preserve when callers depend on that shape |
| Early return for invalid identifiers | Nearby validation branches | Preserve when it keeps the same control flow |
| Snake-case field names in stored records | Existing record definitions and serializers | Preserve at the storage boundary unless the contract changes |
| Helper function for repeated normalization | Multiple callers with the same operation | Preserve or reuse when it avoids new abstraction |
| Silent catch block | Nearby error path and caller expectations | Revise when it hides a failure relevant to the requirement |
Each row requires project-specific judgment. The table does not declare one pattern universally correct. It shows what evidence should drive the decision.
Protected conventions can be paired with protected behavior. A behavior-preserving refactor brief names observable contracts. A style brief names the local expression of those contracts. Both should point to current code rather than memory.
Separate consistency from correctness
Consistency answers how a change fits. Correctness answers whether the change satisfies the requirement. Those questions can point in different directions.
Suppose neighboring handlers catch an error and return null. A new handler could copy that pattern for visual consistency. If the requirement says callers must distinguish a missing record from a failed read, copying null would erase a required distinction. The local pattern then conflicts with the contract.
In that situation, surface the conflict before editing. Ask whether the new result shape should remain local or whether neighboring handlers need a separate change. Do not expand the current task silently. The clarification-before-choosing guide helps separate code facts from product decisions.
| Consistency choice | Correctness requirement | Appropriate response |
|---|---|---|
| Use the existing result object | Callers need the same fields | Follow the local shape |
| Use the existing silent catch | Caller must distinguish failure from absence | Surface the conflict and request a decision |
| Reuse a nearby helper | Helper changes protected ordering | Keep the interface but inspect the helper before reuse |
| Introduce a new error type | Existing callers cannot handle it | Prefer a compatible local pattern or name the migration |
| Keep existing naming | Name would misstate new behavior | Choose an accurate name and document the deviation |
The practical rule is simple: style may guide the implementation, but it cannot waive a requirement. F083 supports behavior-preserving change as a refactoring goal, not proof that a stylistic match preserved behavior.
Ask before introducing a new abstraction
A local pattern may be imperfect without justifying a new hierarchy. Adding a base class, wrapper, or generic helper creates another concept for reviewers and callers to understand. Official best practices advises against unnecessary abstraction layers under F084.
Before proposing a new abstraction, ask:
- Does an existing local helper already serve the requirement?
- Would a direct change in the owning block be clear enough?
- Does the new abstraction remove meaningful duplication or enforce a needed boundary?
- Can the requirement be met without changing neighboring interfaces?
- Is the deviation small enough to explain in the review?
An abstraction can be necessary. The point is to make its purpose visible rather than letting it emerge as unrequested polish. If the requirement needs a new boundary, name that boundary in the brief.
Use a specific edit target for a small conventional change. Exact targeting keeps a style adjustment inside the owning block. It does not authorize an unrelated redesign.
When the abstraction is genuinely required, record the reason. A deliberate deviation should explain the requirement that local patterns could not satisfy, not merely state that the new approach is cleaner.
Surface conflicting local patterns
Codebases often contain more than one plausible convention. Older modules may use exceptions while newer modules return result objects. Naming may change across directories. These conflicts are evidence, not noise to erase during a small edit.
Start by checking whether the conflict follows a boundary. A storage adapter may legitimately use different naming from an HTTP handler. A legacy module may be intentionally excluded from a migration. Scope the style choice to the relevant neighborhood.
An unclear boundary calls for a focused question. “Should this handler follow the result-object pattern used by its two callers, or the exception pattern used elsewhere in the module?” is more useful than “which style should I use?”
The progressive-disclosure guide explains how path-scoped instructions can keep narrow conventions near relevant files. This article does not prescribe configuration. The general lesson is that a rule should apply where its evidence applies.
Record the conflict in an inspectable checkpoint when it blocks the edit. Name the competing patterns, the inspected examples, and the decision owner. That keeps the next action clear without turning the style question into an unlimited review.
Prefer the smallest conventional change
Once the pattern and requirement are clear, choose the smallest edit that follows both. Avoid reorganizing neighboring code merely to make the new block look uniform.
A small change has several practical advantages. Reviewers can compare it with the cited local example. The intended behavior is easier to separate from incidental restructuring. If the convention later changes, fewer unrelated decisions need to be revisited.
Small does not mean automatically safe. The reversible-planning guide treats reversibility as a property to assess, not a synonym for size. Inspect the edited region and its behavior-relevant relationships.
A conventional change may still need a new local value name. Choose a name that fits surrounding terminology while accurately describing the behavior. Avoid copying a misleading name merely because it appears nearby.
When several conventional options exist, state the choice briefly. “Use the existing result shape and keep the early return” gives the editor a clear path without prescribing every line.
Durable team decisions deserve a different treatment from discoverable syntax. If reviewers repeatedly debate a naming boundary or error contract, record the decision where future tasks can find it. F082 supports that kind of non-discoverable context. A rule that merely repeats an obvious nearby pattern adds maintenance work without adding much guidance.
Before recording a convention, ask whether it still serves the requirement. Old decisions can conflict with a new caller contract. Surface that conflict instead of treating the written rule as automatic enforcement. The essential CLAUDE.md guide explains how to keep always-loaded instructions focused.
Separate formatting from design
Formatting choices and design conventions deserve different review attention. A formatter may settle spacing or import order. Naming, result shapes, and error flow carry semantic meaning and need judgment.
Do not turn a style-preserving request into a formatter configuration guide. If the project already formats code, preserve its output rather than manually imitating incidental whitespace. If it does not, avoid expanding a behavior edit into a formatting pass.
A useful brief names semantic conventions and leaves mechanical formatting to the existing toolchain. That keeps the editor focused on choices a reader must understand. It also prevents unrelated formatting changes from obscuring the requested edit.
When formatting conflicts with the requested region, record the conflict without silently reformatting neighboring code. An exact edit target keeps the change inside the owning block until a separate formatting decision is made.
A worked local-pattern edit
Consider this illustrative handler. It returns a result object and uses an early return for an invalid identifier.
function loadInvoice(id: string) {
if (!id) {
return { data: null, error: 'invoice_id_required' };
}
return fetchInvoice(id);
}
The new requirement is to reject whitespace-only identifiers while preserving the result shape and error code. A style-preserving request could read:
Inspect loadInvoice and the neighboring invoice handlers. Follow the existing
early-return and result-object pattern. Change only the identifier guard so
whitespace-only input returns the current invoice_id_required result. Preserve
the function name, result shape, error code, and fetchInvoice call. Do not add
a helper or error type. If neighboring handlers conflict with this contract,
surface the conflict before editing.
The prompt names a local convention, a correctness boundary, and an abstraction limit. It also leaves room to report a conflict rather than copying a pattern blindly.
After the edit, inspect the guard, return object, and fetch call together. Confirm that the change stayed inside the owning block. This is contextual edit inspection, not a claim that one example establishes complete input behavior.
A less suitable request would say “modernize invoice loading.” That wording permits new return types, helper layers, and caller changes. Those decisions would obscure the required guard correction.
Inspect the edited region in context
Review the new code beside the local examples named in the brief. Compare the choices that matter: naming, control flow, result shape, and error handling. Do not stop at whether the file still parses.
Useful review questions include:
- Does the edit follow the named local pattern?
- Is the pattern still appropriate for the requirement?
- Did the change introduce an unrequested abstraction?
- Did neighboring code receive incidental edits?
- Does any deliberate deviation have a written reason?
The exact-target guide covers contextual inspection in more detail. Here, the additional question is whether the edited region now speaks the same local language without losing accuracy.
If the new code conflicts with surrounding callers, inspect those relationships before expanding the change. A style choice that breaks an interface is not merely cosmetic. Name the conflict and decide whether the caller or the implementation should adapt.
Document a deliberate deviation
A deviation should be small, specific, and tied to the requirement. Explain which local pattern was not followed and why. This gives future reviewers a decision record instead of an apparent inconsistency.
| Deliberate deviation | Rationale to record | Boundary |
|---|---|---|
Return a distinct error instead of null |
Caller must distinguish failure from absence | Keep the change local until caller migration is approved |
| Use a more accurate name than neighboring code | Existing name misstates the new behavior | Preserve the public interface if it is protected |
| Add a small helper | Duplication would otherwise cross a required boundary | Avoid a broader hierarchy |
| Keep a legacy pattern temporarily | A separate migration owns the convention change | Record the follow-up without performing it |
The table provides illustrative rationale, not a rule that every deviation needs a new document. A concise comment or task record may be enough. The important part is traceability.
Deferred cleanup belongs outside the active edit. Use the stop-condition guide to name what is enough and what remains for later. Do not turn a local style adjustment into an unrequested modernization project.
A practical style-review runbook
Use this sequence when an edit needs to fit local conventions.
| Stage | Question | Evidence |
|---|---|---|
| Observe | Which nearby pattern is relevant? | Neighboring code with similar responsibility |
| Name | What exactly should be preserved? | Naming, control flow, result shape, or error path |
| Check | Does the pattern serve the requirement? | Observable behavior and caller expectations |
| Compare | Do local examples conflict? | Competing patterns and their boundaries |
| Decide | Is a deviation necessary? | A requirement the local pattern cannot satisfy |
| Edit | What is the smallest conventional change? | Exact target and protected surroundings |
| Inspect | Does the region fit without losing correctness? | Edited code beside its local examples |
This runbook is an editorial control. It does not replace project checks or guarantee maintainability. It makes the style decision explicit enough to review.
Project instructions should capture durable team decisions, not every discoverable pattern. F082 supports that distinction. If a convention changes often, inspect current code instead of hard-coding a stale imitation rule.
Review consistency at the right scope
A pattern can be consistent within one function and inconsistent across a module. Decide which scope matters before asking for imitation. Matching the immediate neighbors usually protects readability. Matching an entire legacy area may preserve historical accidents.
Scope also affects deviation. A local naming choice may be harmless, while a new error shape can affect distant callers. Spend review effort on conventions that cross boundaries.
The context-relevance guide supports selecting evidence that can change the decision. Apply that principle to style evidence: inspect enough neighboring code to identify the convention, then stop. More examples do not automatically produce better consistency.
Concrete win, loss, and implication
Win: A new invoice handler follows the existing result-object shape and early-return guard. Callers keep their familiar error path, and the diff stays focused on whitespace validation. The win is a smaller conceptual review surface, not a measured maintainability score.
Loss: Nearby code may contain a buggy or outdated pattern. Copying it can make the new code consistent and wrong at the same time. The loss is correctness hidden beneath visual familiarity. A deliberate, documented deviation is sometimes required.
Implication: Cite local evidence, name the convention, and check it against the requirement. Ask before adding an abstraction. Surface conflicts, prefer the smallest conventional edit, and document deviations. Finish at the agreed boundary rather than modernizing adjacent code.
Data gap and future update
The packet contains no verified benchmark showing that local imitation improves maintainability or review time. The refactoring source defines a goal, not a measured result for generated edits. No community report is used as evidence.
A future update should compare concrete before-and-after regions, name the local convention, and record review criteria on a specific integration surface. Measured claims would need reproducible tasks and observed outcomes. Until then, this article remains a practical review method.
The independent requirements guide is snippet-only in the supplied register. A future editorial pass can replace it with an accessible primary source if verified. Documentation is live and should be rechecked before publication.
One AI option for OpenAI-format agents
For separate OpenAI-format agents, One AI provides one key and 46 live free IDs at https://api.oneaiapikey.com/v1. Inspect the free model list or follow the OpenAI-format quickstart. This 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 described as working inside Claude Code.
FAQ
Should every local convention go into CLAUDE.md?
No. F082 favors non-discoverable information such as team decisions. Code patterns can be inspected directly, and copying all of them into project instructions adds stale context.
What if the surrounding pattern is wrong?
Surface the conflict. Follow the requirement, choose the smallest compatible change, and document a deliberate deviation when needed. Consistency does not override correctness.
Does matching local style prove maintainability?
No. F083 describes behavior-preserving maintainability improvement as a refactoring goal. Stylistic consistency is related but not identical, and structure alone does not prove the goal was met.
When is a new abstraction justified?
When a named requirement needs a boundary or removes meaningful duplication that existing local patterns cannot handle. F084 warns against unnecessary layers, not against every necessary abstraction.
Connect local patterns to the batch
Define intent with observable requirements, goals, rules, and examples, and negative requirements. Use acceptance examples, clarification before choosing, and prompt specificity.
Plan the change through 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 a pattern conflict changes direction.
For tool evidence, compare unambiguous tool schemas, investigation before answering, independent parallel reads, and evidence-bearing tool results. Keep deferred tool definitions within the documented API boundary.
For edit quality, read inspectable task checkpoints, exact block targets, behavior-preserving refactor scope, and agreed stopping boundaries.
More Claude Code troubleshooting
- 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 F082 and F084 with their discoverability and abstraction caveats.
- How Claude remembers your project, official. Fetched companion source; not used to make local style mandatory.
- Claude Code tools reference, official. Canonical link only in the supplied register; no unseen mechanics inferred.
- Refactoring chapter, independent. Supports F083 and the distinction between consistency and behavior preservation.
- Software requirements specification guide, independent. Search-index evidence only.