Source: https://frameworkrecipes.dev/workflows/keep-agent-fixes/

# Keep a coding agent from undoing a fix

Save the behavior restored by the fix as a named requirement. Give the agent the exact command to check that requirement after its next edit, repair any finding, and run the same command again before committing. Keep the application regression test with the rule.

## Save the behavior the fix restored

In this React example, an older search request must not replace the current results. The captured broken edit removes the obsolete-request guard from the fulfilled-response branch:

```
setState({items,error:null});
```

The corrected branch keeps that guard:

```
if (!obsolete) setState({items,error:null});
```

[Full React implementation and integration prerequisites](https://frameworkrecipes.dev/react/stale-request-cleanup/) · [Exact broken and corrected source](https://frameworkrecipes.dev/react/stale-request-cleanup/source.json).

Existing captured source checks; these are individual examples

| Implementation | Saved requirement | Broken source | Corrected source | Capture date |
| --- | --- | --- | --- | --- |
| [Keep old React search responses from replacing the current query](https://frameworkrecipes.dev/react/stale-request-cleanup/) | obsolete-search-does-not-update | Rule finding | No rule finding | [2026-10-14](https://frameworkrecipes.dev/react/stale-request-cleanup/capture.json) |

## Make the requirement independent of the conversation

The saved rule names the behavior the agent must preserve on `src/useOrderSearch.js`. Its captured check covers the fulfilled-response branch; keep the separate error-path regression test too.

```
- name: obsolete-search-does-not-update
  where: "src/useOrderSearch.js"
  ensure: >-
    The fulfilled search response must check obsolete before setting items, so a response for a previous query cannot replace the current result.
```

## Make the agent check the requirement after its edit

Keep your existing perch.yaml. The [scoped rule pack](https://reporules.fyi/react/stale-request-cleanup/) installs the saved requirement under .perch/rules/. Review its file selector and use the implementation’s integration prerequisites before adapting it to your application.

### Install Perch and configure your agent

```
npm install -g @lakeday/perch
perch login
# Choose the setup command for your agent:
perch setup claude-code
# Or: perch setup codex
# Or: perch setup cursor
```

### Check the edit and recheck the repair

```
curl -fL 'https://reporules.fyi/react/stale-request-cleanup/rule-pack.zip' -o requirement.zip
unzip -n requirement.zip
perch check src/useOrderSearch.js --rules obsolete-search-does-not-update --json
# Read the finding, repair the implementation, then repeat:
perch check src/useOrderSearch.js --rules obsolete-search-does-not-update --json
```

Run the same check on the repaired working file before committing. Keep the application regression tests alongside it. Fresh model judgments can vary; an unchanged request can reuse its cached answer. A passing check does not prove application correctness.

## Ask Claude Code to verify the requirement before committing

Use `perch setup claude-code` to install Perch’s agent skill. For Codex or Cursor, choose that agent’s setup command instead. Give the task a file, a named rule and a completion condition:

```
After editing src/useOrderSearch.js, run:
perch check src/useOrderSearch.js --rules obsolete-search-does-not-update --json
Read the finding and fix the implementation. Repeat the identical check.
Run the application regression test and report the results before committing.
```

[Download the existing agent repair task](https://reporules.fyi/react/stale-request-cleanup/agent-task.txt) · [Perch agent setup documentation](https://github.com/lakeday-org/perch/blob/main/docs/skill.md).

## Check the code that will actually be committed

`perch check` reads the working file. If the staged version differs, inspect both diffs, stage the intended repair and check that implementation again. An agent instruction is a workflow; a required CI check is the separate repository gate.

```
git diff -- src/useOrderSearch.js
git diff --cached -- src/useOrderSearch.js
```

[Working-file check reference](https://github.com/lakeday-org/perch/blob/main/docs/check.md) · [Run Perch in CI](https://github.com/lakeday-org/perch/blob/main/docs/ci.md) · [Claude Code hook behavior](https://code.claude.com/docs/en/hooks).

## Choose the next requirement by its failure

[Find authorization, transaction, concurrency, retry and cleanup rules](https://frameworkrecipes.dev/problems/) or [inspect the React source and captured checks](https://frameworkrecipes.dev/react/). Adapt the selected example and tests to your application; the recorded source check remains evidence for its linked example.

**Framework Recipes**

Implementation, failure path, check.

Published by Perch · © 2026 Verglas LLC. Framework Recipes is a Perch publication.

Perch’s MIT license covers the CLI; hosted model analysis is a paid service. Relevant source is sent to the configured model service.

[Perch CLI MIT license](https://github.com/lakeday-org/perch/blob/main/LICENSE) · [Article text](https://frameworkrecipes.dev/workflows/keep-agent-fixes/index.md) · [Resource index](https://frameworkrecipes.dev/llms.txt)

[Privacy](https://frameworkrecipes.dev/privacy/) ·
