On this page#
What changes when an agent does this#
With claude code rust, the bottleneck moves from writing code to specifying invariants and rejecting plausible-looking mistakes. Claude Code can inspect a repository, edit files, and run development workflows, but successful execution is not proof of correctness. The engineer’s job becomes controlling scope, defining evidence, and reviewing semantic change before acceptance.
Claude Code is an agentic coding tool: it can reason over a codebase and take actions rather than merely suggest snippets. Rust makes that useful because the compiler catches many structural mistakes. It also makes overconfidence dangerous because compilation cannot validate business rules, concurrency assumptions, protocol behavior, or compatibility.
The practical workflow is:
- State the invariant.
- Ask for analysis without edits.
- Approve a narrow plan.
- Let the agent implement and verify.
- Stop for human review.
- Accept or roll back the entire change.
The agent accelerates traversal and implementation. It does not own the acceptance decision.
Photo by Christina Morillo on Pexels.
The prompt chain#
Do not give Claude Code one large prompt that combines diagnosis, implementation, testing, and cleanup. That collapses several decisions into one autonomous run. Use a prompt chain in which each phase produces evidence for the next, and do not advance when the output is vague, incomplete, or broader than the requested change.
Phase 1: establish the invariant#
Start by making the agent explain what must remain true. This prevents it from treating the ticket wording as the complete specification and exposes whether it has located the real boundaries: public APIs, error behavior, state transitions, ownership assumptions, feature flags, and downstream callers.
Analyze this repository without modifying files.
Goal:
[describe the required change]
Invariant:
[state what must remain true]
Identify:
- the execution path involved
- callers and downstream effects
- existing tests that encode the behavior
- assumptions the type system cannot prove
- the smallest plausible change surface
Return file paths and a proposed verification plan.
Do not implement anything.“Without modifying files” matters because planning and editing should not share a phase. The official Claude Code documentation explains the tool’s capabilities; it does not remove your responsibility to define repository-specific invariants.
Phase 2: force a bounded plan#
The next prompt converts repository analysis into an auditable contract. Reject plans containing phrases such as “update related code” or “refactor as needed.” Those phrases authorize scope expansion without identifying which behavior is being changed.
Produce an implementation plan only.
For each proposed edit, list:
- file and symbol
- behavioral reason
- invariant protected
- test or check that will detect failure
Constraints:
- no unrelated refactoring
- no dependency changes
- no public API changes unless explicitly required
- preserve existing error semantics
List unresolved questions separately.This prompt makes omissions visible before they become diffs. If the plan cannot connect every edit to an invariant and a verification step, implementation should not start.
For a broader reusable review sequence, PairFoundry’s Review and Repair workflow applies the same principle: separate finding, judging, repairing, and verifying instead of asking an agent to “fix everything.”
Phase 3: implement exactly the plan#
Implementation should be deliberately boring. The agent may discover that the approved plan is wrong, but it must stop and report that discovery rather than silently inventing a larger solution.
Implement only the approved plan.
Requirements:
- keep the diff minimal
- preserve public behavior outside the stated goal
- add or update tests for the invariant
- do not suppress warnings
- do not weaken assertions
- do not change dependencies
If implementation requires work outside the plan, stop and explain why.
Then run the repository's existing formatting, build, lint, and test checks.
Report commands and results exactly.Use the repository’s existing commands, not a generic checklist imposed from outside. A Rust project may encode important behavior in workspace configuration, features, integration tests, examples, or custom automation. The Claude Code overview describes repository-level operation, but your repository remains the authority on what constitutes a valid check.
The gate#
The gate is a mandatory human review between “checks passed” and “change accepted.” Inspect the diff, not the agent’s summary, and verify semantic intent rather than style. This is where you catch a technically valid Rust implementation that preserves types while changing ordering, error propagation, resource lifetime, or externally observable behavior.
Review in this order:
- Scope: Does every changed line serve the approved plan?
- Invariant: Which test would fail if the required behavior were broken?
- Negative paths: Are errors, cancellation, empty inputs, retries, and partial state handled?
- API surface: Did visibility, trait behavior, serialization, or error shape change?
- Verification integrity: Were assertions weakened, warnings suppressed, or tests narrowed?
A passing test suite is evidence, not approval. If the diff is too large to review confidently, the workflow has already failed. Split or reject it.
Teams adopting this process can use the free Foundations track before standardizing a paid workflow. The important shared rule is simple: the agent cannot waive the gate that evaluates its own work.
Photo by Al Nahian on Pexels.
What it gets wrong#
Claude Code most often fails by producing a coherent local solution to an incomplete global model. Rust eliminates many invalid states, but it cannot tell the agent that a valid state violates product semantics. Look for mismatches between the approved invariant, the edited execution path, and the evidence supplied by tests.
| Failure mode | How to recognize it | |---|---| | Local fix, global regression | The edited function passes while another caller relies on the old behavior. | | Accidental API drift | Public types, trait bounds, visibility, error variants, or serialized output change. | | Happy-path proof | New tests cover success but not failure, cancellation, or partial progress. | | Refactor camouflage | Renames and structural cleanup make the behavioral change hard to isolate. | | Verification theater | Commands passed, but the relevant feature, workspace member, or integration path was not exercised. | | Assertion weakening | The test passes because exact behavior was replaced with a broader condition. |
Another common mistake is accepting the agent’s explanation as a substitute for inspecting the patch. Summaries compress away precisely the details that deserve review.
If the problem is broader than one repair workflow, compare PairFoundry’s three packs or browse the workflow library. Choose a process based on the failure boundary, not on how much autonomy sounds attractive.
Rollback#
Rollback should restore the last known-good repository state without preserving fragments of an untrusted solution. Before implementation, record the baseline and keep unrelated work outside the agent’s scope. After failure, save any useful diagnostic evidence separately, discard the proposed change as one unit, and restart from a corrected invariant or smaller plan.
Use this sequence:
- Stop the agent; do not ask it to repair an unreviewed repair indefinitely.
- Capture the failing command, error, and minimal reproduction.
- Identify every file changed by the attempted task.
- Separate pre-existing human work from agent-created changes.
- Revert the agent’s complete change set using your normal version-control workflow.
- Confirm the baseline checks still pass.
- Rewrite the prompt with the missing constraint exposed by the failure.
Do not roll back only the line that triggered the visible error. The same mistaken assumption may have shaped tests, types, and callers. A clean rollback is safer than accumulating corrective prompts on top of an invalid plan.
Photo by Jakub Zerdzicki on Pexels.
Related reading#
- GitHub Copilot API keys: making the output reviewable, not just correct
- Spec-driven development with Claude Code — the workflow, the gate, and the rollback
FAQ#
When should I not use this workflow?#
Do not use it when you cannot state the invariant, cannot run meaningful verification, or cannot review the resulting diff. It is also a poor fit for emergency changes made against an unknown baseline. Agent speed compounds uncertainty; it does not compensate for missing ownership or missing acceptance criteria.
How is this different from following the official Claude Code documentation?#
The official documentation explains how Claude Code works and how to operate it. This workflow defines a repository-level control system around that capability: staged prompts, explicit invariants, a human acceptance gate, failure recognition, and clean rollback. Those are engineering-policy decisions, not tool features.
What usually goes wrong when a team adopts it?#
Teams often standardize prompts but not decision rights. One engineer treats passing checks as approval while another expects manual semantic review. Define who approves scope, who owns the gate, which repository checks are authoritative, and how agent-created changes are isolated before making the workflow a team convention.
What is the safest way to recover from a bad agent change?#
Return to the known-good baseline, confirm that baseline independently, and retain only diagnostic evidence—not pieces of the proposed implementation. Then restart with a narrower invariant and plan. Repeatedly asking the agent to repair its own expanding diff makes provenance unclear and review progressively less reliable.