Skip to main content

The question

Our agent can search and read repository files, but it can only suggest a fix. What capabilities does it need to apply the change and check whether it works?

The answer

Repository access lets the agent explain a problem and suggest a change. Completing the task requires two more capabilities: editing the actual files and executing checks against the result. Even then, a successful file write only proves that bytes changed. It does not establish that the change fixes the reported behavior. The harness must return execution results to the model so it can decide whether to investigate, revise, or finish.
The interfaces and example below are a proposed design for this guide. They illustrate how a coding harness could work; they are not a description of a particular product’s internals.

The solution: close the feedback loop

Read → Edit → Run → Observe describes a decision cycle, not a script that must rewrite code on every pass. Sometimes observation leads to another read, an environment repair, or a question for the user. Repeat only when the evidence calls for another step.

1. Read: establish the intended behavior

  • Read the code, its callers, and its tests. Use bounded ranges and search, as described in Reading large files.
  • Define the acceptance condition before editing. What observable behavior should change, and what should stay the same?
  • Reproduce the bug when practical. A test that fails before the change and passes after it is strong evidence. Note any tests that were already failing, so they aren’t blamed on the new edit.

2. Edit: change the workspace, then confirm the write

  • Use a targeted patch. An edit tool such as apply_patch changes specific lines instead of rewriting the whole file.
  • Reject stale edits. If the file changed since the agent read it, the harness refuses the patch, and the agent rereads the file and tries again.
  • Confirm the write. The agent checks that the patch applied and reviews the diff (the before-and-after view) before moving on.

3. Run: choose a check that can detect the problem

  • Use the project’s real commands. Find them in its scripts or contributor docs instead of guessing from the language.
  • Start close to the change, then widen. Run a focused test first, then broader checks if the affected area needs them. A docs edit and a shared auth change need different depth.

4. Observe: turn results into the next decision

  • Read the failure, not just the exit code. A nonzero exit code might mean wrong code, a missing dependency, a bad command, or a test that was already failing.
  • Don’t trust a zero exit code blindly. It can also mean no tests ran. Check the runner’s summary.
  • Decide the next step from the evidence. Reread and revise, fix the environment, or finish.

Essential tools

The full coding-agent tool set, and how Claude Code and Grok Build implement it.

Edit & run tools in detail

Tool contracts for patching, running commands, and reading results.

Worked example: expiration at the boundary

Illustrative requirement: a session is expired when the current time is equal to or later than its expiration time. Both inputs are timestamps in milliseconds. The current function is:
Reading shows a possible boundary error, but the agent should connect that observation to a reproducible case. These illustrative assertions capture the intended behavior:
Before the edit, the equality case fails. The agent changes > to >=, confirms the patch applied, and runs the focused tests using the repository’s test runner. If those pass, it checks relevant session tests and reviews the diff for unintended changes. The useful conclusion is specific: the boundary regression is covered and the checks actually run passed. It should not claim that every authentication path is correct. If the test runner could not start, the result is an applied change with incomplete verification, and the final response should say so.

When should the loop stop?

  • Finish when the requested behavior works, the relevant checks pass, and the diff contains only the intended change.
  • Stop and report when the agent needs something it doesn’t have: missing requirements, credentials, infrastructure, or permission. The harness should also cap tool calls and time so the loop can’t run forever.
  • Change approach when the same failure keeps repeating. Running the same edit again won’t help. Gather new evidence or explain the blocker. Never weaken a test just to make it pass.
Design decision: Add targeted editing and controlled execution, then feed their results back into the agent’s next decision. Read → Edit → Run → Observe → reassess.

Source and further reading

Anthropic’s Building effective agents describes agents using environmental feedback, including execution results, and explicit stopping conditions. The contracts, failure-handling choices, and boundary example above are this guide’s proposed design.

Continue the walkthrough

Each iteration adds observations to the conversation. Even a useful loop can accumulate more context than the model can use effectively. The next topic examines that pressure.

Context rot

Continue to topic 3 of 14.