1. brindle
  2. Guides
  3. Rewind an agent

Rewinding a coding agent to an earlier turn

An agent that went wrong on turn six didn't go wrong on turn one. brindle snapshots a worker's worktree after every turn that changed files, so you can go back to the good state and continue from there.

Type
Guide
Updated
Related
Parallel agents
Rule packs
Codex reviews Claude Code

Long sessions drift. Early turns fix the problem, then a later one rewrites something that was fine. Asking the agent to undo it usually adds more changes on top. Restore the files exactly and start a fresh session that knows what went wrong.

See the turns

List a worker's snapshots:

brindle ls
brindle agent turns d2010b34

brindle ls gives the agent id. brindle agent turns lists the snapshotted turns, numbered from 1. A snapshot records changed files or a changed branch commit; turns that change neither aren't snapshotted. Supervisors can use the agent_turns tool when a worker's branch goes sideways.

Rewind to turn N

Pick the last turn worth keeping:

brindle agent rewind d2010b34 --to 3 --note "Keep the retry in the client; do not touch the session code"

brindle restores the worktree to how it was after turn 3 and starts a fresh session there. The session is briefed on the task, summaries of turns 1 through 3 and your note. It doesn't see the conversation that led to the bad turns. Use the note for what you learned: the approach that failed, the file to leave alone, the test that now defines done.

--profile restarts the worker on another profile, such as a heavy one for a hard task. Rewind works for any provider, Codex included, so you can switch a Claude worker to Codex or back. Supervisors have a matching rewind_agent tool and can recover a worker without asking you.

Check brindle diff <workspace> (the workspace id brindle ls shows) to inspect the branch. Rewind starts the new session immediately.

When to rewind and when to message

Rewind is the heavy tool. If the agent is on track and needs a small fix, use brindle send and keep its context. Rewind when:

  • you'd rather not review its changes at all, and asking it to revert would add more diff;
  • it's looping on fixes that make a failing check worse;
  • an early wrong assumption shaped everything after it;
  • you want a different profile or provider from the same starting point.

Parallel branches and conflicts

The other common trouble in parallel work is two branches changing the same file. The files a task says it will touch are a guess; what a branch changed is the truth. At the end of each worker turn, brindle compares the files running and reported-but-unmerged branches have changed, committed or not. When two overlap, it tells the supervisor once per pair, and again if more files join the overlap, in time to make one wait or rewind one.

When several approved branches are ready, brindle first merges the one whose changed hunks overlap the others' least. It then merges the base into each remaining branch, which keeps its approval if the sync is clean, and merges it in turn. A conflict belongs to one branch, so the rest of the queue keeps moving. That branch goes back to its worker with the conflicting files, or to a light worker in its worktree if the original has finished. Its next report starts a fresh review, and checks re-run on the resolved commit. Automatic resolution never skips review or checks.

Keep some conflicts for yourself

Some files shouldn't be resolved by an agent in a hurry: migrations, lockfiles, generated code. List them in .brindle/config.json:

{"protected_paths": ["migrations/", "*.lock"]}

A conflict in a protected path never goes to a worker. The branch waits and the supervisor asks you. With brindle Team, an organization can set protected paths in policy for every repository. Those are stricter: a branch that changes one at all fails its checks, whoever made the change.

Where to go next

Practice with brindle demo, and run brindle agent turns on a worker while it runs. The autopilot docs cover the review-and-merge pipeline, the parallel agents guide explains why each worker has its own branch, and the command reference lists the commands.