When it breaks

It stops mid-task and tells me I have hit a limit

Also asked as hit the rate limit in the middle of a task · usage limit reached claude code · ran out of quota halfway · shipping wall · agent stopped rate limited · burned my quota in an hour

Cause documented by a vendor or a published paper Not tested by benchr First logged Last checked

What is actually happening

One instruction to an agent is not one request. It is a loop, and the loop is what meets the limit — usually with the task half done and the context that made it coherent about to be lost.

Why

  • A single agent command expands into many model calls: read, plan, edit, run tests, read the failure, edit again. The limit counts the calls, not your instruction.
  • Each call in a long session carries the accumulated context, so token use per call grows as the session goes on rather than staying flat.
  • Rate limits and quota exhaustion look identical from the outside and need opposite responses: one wants a wait, the other wants a plan change. The error code is what separates them.

The quick fix

Read the error before retrying. A 429 with a retry hint wants a wait; a quota error wants a smaller job, because no amount of backoff refills a balance.

The real fix

Make the work resumable so a limit costs you a pause instead of a session. Have the agent write a plan to a file, work one unit at a time, and commit after each. Then a limit is somewhere to restart from rather than somewhere to start over.

Step by step

  1. Check which error it is: rate limit, quota exhausted, or context length. Three different problems that all read as 'it stopped'.
  2. Have the agent write its plan and progress to a file in the repository, not into the conversation.
  3. Work one unit per run and commit between units, so an interruption costs one unit.
  4. Cache the stable prefix — the system prompt and any long unchanging reference — so each call in the loop costs less.
  5. Put a hard iteration cap on any loop that can retry itself, and a spend limit that stops the run rather than emailing you afterwards.

If you are seeing an API error

Grounded in

Where this leads