AI Coding Agent Hit Its Limit Mid-Task: What Now
An AI coding agent usage limit stops work in three different ways. Tell them apart from the error, then recover the half-finished branch safely.
When an AI coding agent usage limit stops you mid-task, the first thing to establish is which limit you hit, because three different failures produce the same symptom and need opposite responses. One clears in seconds. One clears on the first of the month. One is a setting you can change right now. Guessing wastes an afternoon, and the error body tells you which you are looking at.
Three AI coding agent usage limit failures that look identical
Taking Anthropic's API as the worked example, the rate limits documentation describes two separate systems, spend limits and rate limits, and they fail differently. Add your own self-imposed cap and there are three cases:
What you hit | HTTP status | Tell | Recovery |
|---|---|---|---|
Rate limit (requests or tokens per minute) | 429 |
| Wait the stated seconds |
Tier spend cap | 429 | No | Blocked until 00:00 UTC on the 1st, or raise the tier |
A spend limit you set yourself | 400 | Type | Raise or remove your own limit |
The second row is the one that ruins days. It returns 429, the same status as an ordinary rate limit, so every retry layer you own treats it as transient and backs off politely forever. The docs are explicit that no retry-after is sent and that automatic SDK retries will keep failing until access resumes. If your agent appears to hang rather than error, this is the first thing to check.
Worth knowing before you panic about the calendar: the documented tier spend caps are 500 USD on Start, 1,000 USD on Build and 200,000 USD on Scale, and moving up a tier restores access immediately. A solo developer who hit a cap mid-sprint is usually one tier change away from working again, not three weeks.
Read the headers instead of guessing
Every response carries the state of your limits, so you never have to infer it. The names are specific and worth putting in your logs:
retry-after, seconds to wait, and earlier retries will failanthropic-ratelimit-requests-remainingandanthropic-ratelimit-requests-resetanthropic-ratelimit-input-tokens-remainingand the matching-reset, in RFC 3339anthropic-ratelimit-output-tokens-remainingand the matching-reset
The remaining-token counts are rounded to the nearest thousand, and the anthropic-ratelimit-tokens-* family reports whichever limit is currently most restrictive. Log all of them on the failing request. Ten seconds of grep then replaces a long argument about whether the problem is you or the provider.
Recovering the branch, which is the part people get wrong
The limit is an inconvenience. The half-written branch is the actual risk. An agent interrupted partway through a multi-file change leaves a working tree that compiles in some places and not others, with no record of what it intended to do next.
Stop and commit what exists, on a scratch branch. Not to keep, to freeze.
git switch -c wip/agent-interrupted && git add -A && git commit -m "wip: interrupted"costs nothing and means the next step cannot lose work.Write down the intent before you lose it. Scroll back and copy the agent's plan or last summary into the commit body or a scratch file. This is the piece that never survives, and without it you restart from the prompt rather than from the state.
Diff against the base branch and classify. Which files are finished, which are half-done, which were only touched incidentally? Three lists. A careful read of the diff at this point is faster than asking a fresh agent session to work out what its predecessor was thinking.
Land the finished files, revert the half-done ones. Resist the temptation to resume from a partial state. A clean slice plus a clear remaining task beats a muddled tree that a new session has to reverse-engineer.
Re-run the remaining work as a smaller task. You now know roughly what it costs, so split it to fit inside the budget you have left.
Make the next interruption cheap
Interruption is a normal operating condition, not an exception, so build for it. Three habits cover most of it.
Commit at every green test. If the agent can commit whenever the suite passes, an interruption costs you the work since the last green state rather than the whole task. This is the single highest-value change and it needs nothing more than a line in your instructions.
Cap spend deliberately rather than discovering the cap. Setting your own limit below the tier cap converts a confusing 429 into an explicit 400 with a message naming your own setting, which is far easier to diagnose; the mechanics are covered in setting a budget cap on an AI coding agent.
Use caching, because on most models cached input tokens do not count toward the input-tokens-per-minute limit at all. The documentation works an example: at a 2,000,000 token limit and an 80 percent cache hit rate, you can process around 10,000,000 total input tokens a minute. For an agent that re-reads the same large files all day, that is the difference between hitting the ceiling hourly and never seeing it.
Running low on budget and running low on context are different problems with similar symptoms, and it is worth being able to tell a context exhaustion apart from a billing wall. Over a month, both show up in the same place, which is why a forecast of next month's AI bill is worth half an hour.
Working out what a task actually costs you
Most people hit limits because they have never measured a single task. The arithmetic is not hard and it changes how you plan work.
Take a medium feature on a real repository: the agent reads perhaps fifteen files, writes four, and runs the test suite three times. Each test run means re-reading the files it changed plus the failure output. Without caching, the same fifteen files are re-sent on every turn, so a task with twenty turns can re-send the same context twenty times. With caching, the fifteen files are written to cache once and read thereafter, and reads do not count toward the input-token limit on most models.
That is the whole reason interruption feels random. Two tasks of apparently similar size differ by an order of magnitude in token cost depending on how many turns they take and whether the stable context is cached. Measuring three real tasks gives you a budget per task, and a budget per task converts "we ran out" into "this feature needs two sessions", which is a plan rather than a surprise.
The practical consequence: prefer fewer, longer sessions over many short ones on the same files, because a fresh session pays the cache-write cost again.
A note on coding-agent plans specifically
Subscription coding tools are not the same as raw API access, and the differences between the products are worth knowing before you pick one, which is the subject of our guide to AI coding tools. The Anthropic docs note that the Claude Code workspace is checked separately, and that over-limit Claude Code requests can return a 429 that does carry retry-after, unlike the organisation spend cap. In other words: do not assume behaviour you learned from the API applies unchanged to the coding tool, or the reverse. Check the error.
Frequently asked questions
Why does my retry loop never recover?
Almost certainly because you are retrying a spend-cap 429, which carries no retry-after and will not succeed until the next billing month or a tier change. Branch on error.details.error_code rather than on the status code alone.
Does a higher max_tokens make me hit limits sooner?
No. The output-token limit is evaluated against tokens actually produced, and the documentation states that max_tokens does not factor into the calculation. Setting it generously costs you nothing in rate limit terms.
Can I use a second model to keep working?
Often, yes, because limits are applied per model, so you can run up to each model's limit at the same time. Note that some families share a combined bucket, so check whether your fallback is genuinely a separate pool before relying on it.
Should I just pre-emptively buy a higher tier?
Only once you have a month of header data. The console charts and the logged remaining-token values tell you whether you are near a ceiling or hitting short bursts, and bursts are a batching problem rather than a tier problem.
How did this land?
About the author

Developer Advocate
Steve builds something with Swarmz every week and writes up what worked, what broke, and what he'd do differently. Tutorials and hands-on guides are his lane.


