Flint

AI Agent Stuck in Loop: How to Fix It in Flint

When Flint shows the same tool line repeating, you are looking at an AI agent stuck in loop, not a frozen one. The model is still making step choices. It keeps landing on the same tool because it cannot find a better path in what it can see.

Short answer: Flint loops when the model's step choices keep landing on the same tool or command, usually because the task is ambiguous, an earlier step failed without a clear signal to the model, or the active context has grown large enough to obscure earlier results. A cost limit per message and a step limit per turn bound every turn by default, so no turn runs or spends without end. Press Esc to stop the turn, read the scrollback to find where it went in circles, and reword the request before you try again.

How a loop starts

Flint sends your request to a language model together with a set of tools. The model decides which tools to call, Flint runs them, and the cycle repeats until the task is done. A loop is that decision repeating: nothing in the context the model can see points to a different action, so it reaches for the same tool again.

The terminal shows you this as it happens. Each tool call leaves one line as it runs, so the same line appearing again is how a person watches the agent go in circles. You do not have to infer it from the cost.

A long context makes the problem harder to escape. Every call to a model sends the conversation again, so long sessions grow expensive. Context swap, which is on by default, moves big and old tool results and old turns to the session folder on disk and leaves one line in their place; nothing is lost, and the agent reads them back when it needs them. Swap keeps the active context workable, but it cannot make an ambiguous request clearer.

What keeps a loop finite is the limits. A cost limit per message and a step limit per turn are both on by default, and you can change them. They are separate from the spend switch, /spend, which sets how early context management starts. Left alone, a runaway turn stops on its own at whichever limit it reaches first. The footer shows the model, the cost, the context size, the care level and the spend level throughout, so you can watch the cost climbing while the loop runs.

Warning: Raising the step limit does not fix a loop. It lets the same bad choices repeat more times before stopping, and every repeat is another call to the model provider.

What it looks like in practice

Say you ask Flint to find and replace a string across a project. Flint calls the file search tool, finds the matches, calls the edit tool on the first file, then calls file search again with the same query. Search, edit, search, edit.

On screen the scrollback holds two lines alternating, each identical to the one before it: the search call and the edit call. After a few pairs the pattern is unmistakable, and the footer cost ticks up with every step. That alternating pair is the visual signature of a loop.

Press Esc and the turn stops. The receipt then prints once, at the end of the turn: tools used, files changed, tokens in and out, time and cost. It lists the files changed, not the files read, so the receipt is a short list of what the loop actually touched. That list is what you check before you run anything else.

How to break out

  1. Press Esc to stop the running turn.
  2. Read the scrollback and find the first line that starts repeating. That is the step where the model lost its way.
  3. Read the receipt that prints when the turn ends. It names the tools used, the files changed, the tokens and the cost, which tells you what the loop did before you stopped it.
  4. If the loop wrote to files, run /rewind to undo the file changes of this session.
  5. Reword the request before you run it again. Name a specific stopping condition, break the task into a smaller first step, or say what to do when a particular step fails. A task with a clear success state loops less often.
  6. Check the context size in the footer. If the session is long, /new starts a fresh one, /resume picks a recent saved session, and flint --last continues the last one.
  7. If the same task loops again on the same model, switch with /model or /provider. The provider and the model can be changed in the middle of a conversation, and the quality of the work depends on the model: a stronger one recovers from an ambiguous request more reliably.

What makes it worse

  • Wait for the built-in limits to end it, instead of pressing Esc. The turn does stop, but the context size and the cost grow with every step, and Esc is faster and cheaper.
  • Type a new message while the loop is still running. It waits and is read between steps, so the loop carries on to its limit before your new instruction is seen.
  • Resend the same prompt after stopping. The model gets the same context and the same description of the task, and it makes the same choices.
  • Run the task again without reading the receipt. Files touched during the loop may hold partial or repeated edits, and the receipt names which files to inspect.
  • Raise the step limit as a workaround for a stubborn task. That buys more bad steps, not better ones.

Frequently asked questions

Will Flint run forever if the agent is looping?

No. Every turn is bounded by default, with a cost limit per message and a step limit per turn, and a turn stops at whichever it reaches first. You can stop it sooner with Esc, which is faster and cheaper than waiting.

Why does the same line keep appearing in my terminal?

Because the model keeps choosing the same tool. Each tool call leaves one line as it runs, so a repeating line means the model is asking for the same action again. Flint is running what it was asked to run; the step decisions are landing on the same option.

How do I know if the loop changed any of my files?

Read the receipt printed when the turn ends. It lists the tools used, the files changed, tokens in and out, time and cost, and it names only the files that were written, not the ones that were read. If any of those changes need to go, /rewind undoes the file changes of a session.

Can I switch models mid-session to get out of a loop?

Yes. /model changes the model and /provider changes the provider in the middle of a conversation. A model with stronger reasoning tends to recover from an ambiguous request, which is the usual reason the same task loops on one model and not another.

Does /auto also protect against loops?

/auto <task> has its own limits of steps and cost, so an autonomous run ends rather than spinning forever. Those limits do not stop the model from making poor choices in the steps it does take, so read the plan and the receipt as you would for any other turn. /continue resumes unfinished work.

Next step

Run one small task with an obvious success state, watch the tool lines come and go, and you will know what a healthy turn looks like the next time one goes wrong. Set up Flint.