
The Claude Code connection lost mid-response error shows up as one yellow line under a reply that stops short. It means the network connection carrying Claude’s answer broke after part of the answer had already arrived. Claude Code kept the finished part and stopped there instead of starting over.
API Error: Connection lost mid-response. The response above may be incomplete.The fix is usually one word. Read what is on screen, then reply with continue, and Claude picks up from its last completed block. Nothing you already have is thrown away, and files Claude finished editing stay edited.
If the message keeps coming back, the cause is on the path between your computer and the API: shaky Wi-Fi, a VPN, a proxy or gateway that cuts long responses, or a laptop that went to sleep. The rest of this guide shows the error in a real session, what Claude Code keeps, and how to stop repeats.
This guide is part of our help series. Browse all our Claude Code tutorials for more fixes and how-tos.
Tested with Claude Code v2.1.322 on macOS on November 15, 2026. We reproduced the message by pointing Claude Code at a small test server on our own Mac that starts a streaming reply and then drops the connection, inside a throwaway folder. The list of causes, the sleep and proxy variants, and the retry settings come from Anthropic’s official error reference, and each section says which is which.
Claude Code Connection Lost Mid-Response: Quick Summary
| Question | Short answer |
|---|---|
| What does it mean? | The connection dropped while a reply was streaming, after at least one block of text or one tool call was done |
| Is my work lost? | No. Finished text and finished tool calls are kept. Only the block that was cut off is discarded |
| What do I type? | continue |
| Did Claude Code retry? | Not at this point. Re-sending could run the same tool calls twice |
| Whose side is it on? | Usually the network path: Wi-Fi, VPN, proxy, gateway or sleep |
| Old wording | Connection closed mid-response (before v2.1.227) |

What the Error Looks Like
We ran one short prompt in print mode against our test server. The server sent the start of an answer, finished one block of text, began a second one and then closed the connection. Claude Code printed the part it had, followed by the notice.

result field and is_error is true.Inside an interactive session it looks the same, only in color. The finished text stays above, and the notice is added below it as a yellow line.

Notice what is missing. Our server had started sending tip 3 when it dropped the line, and that half-sentence does not appear. This matches the official wording: Claude Code keeps every block Claude completed, but discards an interrupted final block when the turn ends.
The notice means the reply was cut off, not that it was lost. What you can see is safe to use.
What “Connection Lost Mid-Response” Means
Claude Code receives answers as a stream. Text and tool calls arrive piece by piece over one open connection, which can stay open for minutes on a long turn. If that connection breaks partway, Claude Code has to decide what to do with the pieces it already holds.
The official error reference explains the choice. Once Claude has completed a block of text or a tool call, sending the same request again could run the same tool calls twice. So Claude Code keeps the completed output, runs any tool calls that did finish, and adds this notice instead of discarding the turn.

The six variants of the notice
The first half of the message names the cause. The second half, “The response above may be incomplete,” is the same in all of them. This table follows the official reference.
| Message starts with | What happened |
|---|---|
Connection lost mid-response | The connection dropped, or a proxy or gateway ended the response body before it was finished |
Your computer went to sleep mid-response | The computer slept while the reply was streaming |
The response stopped arriving | The connection stayed open but no more data came, so Claude Code aborted it |
Server error mid-response | An overloaded or 5xx server error arrived in the middle of the stream |
Part of the response never arrived | A piece of the stream was dropped between the API and Claude Code |
The response stream was malformed | A piece of the stream arrived damaged or out of order |
We triggered the first variant in our test. The other five are listed from the docs, and the same recovery steps apply to all of them.
Older wording you may still see
Before v2.1.227, this message read Connection closed mid-response, and “The response stopped arriving” read Response stalled mid-stream. If you see the old text, you are on an older version. Our guide on updating Claude Code covers how to move to the current one.
Why Claude Code Did Not Just Retry
Claude Code does retry dropped connections, just not at every point in a reply. The official reference describes three stages, and the diagram near the top shows them side by side.
- Before any part of the reply is complete: Claude Code sends the request again with a growing wait between attempts, and the turn continues.
- After a block of text or a tool call is complete, but before the reply ends: no re-send. You get the mid-response notice.
- After the reply is finished: nothing is missing, so the turn ends normally with no notice.

What an early drop looks like
We checked the first stage too, with a second test server that dropped the connection right after the stream opened, before any text. Claude Code did not show an error at first. It showed a countdown and tried again by itself.

In a third run, the server cut the very first block of text halfway. Claude Code kept retrying for about three and a half minutes, and our server counted 12 streaming attempts. The mid-response notice never appeared in that run, because no block had finished yet.
So when you do see “Connection lost mid-response,” the automatic retries were not skipped by mistake. Claude Code had already passed the point where a silent retry is safe. If your error mentions ECONNRESET or a refused connection instead, see our guide to the Unable to Connect error.
What to Do: Four Steps

Step 1: Read what is left on screen
Scroll up and read the reply before you type anything. The last sentences or the last tool call may be missing, so check where it stops. If Claude was editing files, look at which edits are shown as done.
Step 2: Reply with continue
Type continue and press Enter. This is the fix the official reference gives for an interactive session: Claude picks up from its last completed block.

continue and the answer resumed at tip 3. Our test server sent a canned reply here, so this shows the flow, not a real model answer.You do not need to paste your prompt again. Your original message and the partial reply are both still in the conversation.

continue.Step 3: Check your network
One notice on a long turn is normal life on the internet. Several in an hour point at your connection. Run a quick reach test from the same terminal, as the official reference suggests.
curl -I https://api.anthropic.com
Also look at the plain things. Move closer to the router or switch to a cable, pause a flaky VPN, and keep the lid open while a long turn runs. If Anthropic has an incident, our status check guide shows where to look.
Step 4: Check your proxy or gateway
The docs name one more cause for this exact variant: a proxy or gateway that ends the response body before the response has finished. Many corporate proxies and gateways close connections that stay open longer than a set time, and long Claude turns can pass that limit.
Check whether one is in the path. If either line below prints a value, your requests go through it.
echo $ANTHROPIC_BASE_URL
echo $HTTPS_PROXY
If a proxy is set, ask whoever runs it whether it limits long-lived or streaming connections. The network configuration page covers proxy and certificate setup. A leftover ANTHROPIC_BASE_URL that points at a gateway you no longer use should be removed from your shell profile or settings.
What Is Kept and What Is Lost
| Item | After the notice |
|---|---|
| Your prompt | Kept in the conversation |
| Blocks of text Claude finished | Kept and shown |
| Tool calls Claude finished | Kept; Claude Code runs them and continues from their results |
| The block that was mid-stream | Discarded when the turn ends |
| File edits already made | Stay on disk |
| The session | Still open, and can be resumed later |
The first four rows come from the official reference, and the first, second and fourth also match what we saw. Because finished tool calls still run, a cut-off turn can leave a task half done: two files edited, a third not started. That is why step 1 matters.
If the half-done state is not what you want, you can step back. /rewind restores files and conversation to an earlier point, as shown in our checkpoints guide. In most cases continue is the better choice, since it finishes the job instead of undoing it.
If It Happens in Scripts and Print Mode
In non-interactive runs, such as claude -p, Claude Code tries to help itself first. According to the docs, when the cut-off response contains text but no tool calls, Claude Code prompts Claude to continue from where it stopped, up to three times in a row. You see the notice only after those continuations are used up.
Our test matched that. The print-mode run in the first screenshot took about 8 seconds, and our server counted four requests: the original and three continuations, each cut off the same way. The same rule applies to subagents in any session.
For scripts, three details from the official reference are worth knowing.
- With the default text output, Claude Code prints the last completed block of text, then the message.
- With
--output-format jsonorstream-json, the message is in theresultfield. In our run,is_errorwas true, so a script can test for it. - To finish the work once the connection is stable, resume the session and send
continue.
Resuming is one command. Our guide to resuming sessions covers the options, and the headless mode guide covers print mode in scripts.
claude --continue -p "continue"How to Stop It From Coming Back
You cannot prevent every dropped connection, but you can remove the common causes.
- Keep the computer awake during long turns. The sleep variant exists because this happens often. On a Mac, the built-in
caffeinate -icommand keeps the system awake while another command runs. - Use a stable connection for long tasks. Wired or strong Wi-Fi beats a phone hotspot.
- Take the VPN or proxy out of the path for a test, if your workplace allows it. If the notices stop, you have found the cause.
- Update Claude Code. Several fixes in this area arrived in recent versions, including the new wording in v2.1.227 and the automatic continuation in print mode in v2.1.246.
- Break very long turns into smaller requests. Shorter replies spend less time on one open connection.
The first item is from our own Mac; the version notes are from the official reference. Items 2, 3 and 5 are general advice that follows from the causes the docs list.
Retry settings: what they do and do not change
The official reference has a table of retry settings. Two matter here, and it helps to know their limits.
| Variable | Default | What it does |
|---|---|---|
CLAUDE_CODE_MAX_RETRIES | 10 | Number of automatic retry attempts for failures Claude Code retries |
API_TIMEOUT_MS | 600000 | Time each attempt has to receive its response headers. It does not limit how long a streaming response runs after that |

Neither setting makes Claude Code re-send a reply that was cut off mid-response. They help with the early failures shown in the countdown screenshot. Our environment variables guide shows where to set them.
Related Errors
A few messages look similar but mean something different. This table points to the right guide.
| Message | What it means | Where to go |
|---|---|---|
Connection lost before a response was produced | The connection kept dropping after thinking, before any text or tool call | Send the message again |
Unable to connect to API | The connection never opened | The Unable to Connect guide linked above |
API Error: 500 | A failure inside the API | Our 400 and 500 guide |
Repeated 529 Overloaded errors | The API is at capacity | Our 529 guide |
For a wider list, see our roundup of common errors in Claude Code. The first row is from the official reference; we did not trigger that message in our tests.
Try It Yourself
You do not need to break your network to practice the recovery. Next time a long reply is cut off, or right now in any session after pressing Esc partway through an answer, send this prompt. Interrupting with Esc is not the same error, but the recovery prompt works the same way.
continue from where you stopped. First list in one line what you already finished, then do the rest.Asking for a one-line recap first is a simple way to confirm that Claude and you agree on what is already done before it carries on.
Common Mistakes
- Pasting the whole prompt again. The original is still in the conversation, so this repeats finished work and can redo edits.
- Assuming the reply is complete. The notice says it may not be, and the cut-off block is not shown.
- Closing the session. The session is fine; closing it only adds a resume step.
- Raising
API_TIMEOUT_MSto fix it. That setting covers the wait for response headers, not a stream that breaks later. - Blaming your plan or usage limit. This notice is about the connection, not your quota.
Pro Tips
- If the notice appears at about the same number of minutes into every long turn, suspect a proxy or gateway time limit rather than random drops.
- For long unattended jobs, check
is_errorin the JSON output and resume withcontinueinstead of starting the job over. - Commit your work before big tasks. A cut-off turn is then easy to compare against a clean starting point.
- If it repeats with a healthy network and no proxy, run
/feedbackso Anthropic can look at the request details. - General setup problems are covered on the official troubleshooting page, which suggests
/doctorfor a setup checkup.
Cheat Sheet

Frequently Asked Questions
What does “Connection lost mid-response” mean in Claude Code?
The connection to the API dropped while a reply was streaming, after Claude had finished at least one block of text or one tool call. Claude Code kept the finished part and added the notice instead of re-sending the request.
Did I lose my work?
No. Finished text, finished tool calls and file edits already made are kept. Only the block that was being streamed when the connection broke is discarded.
How do I get the rest of the answer?
Reply with continue. In an interactive session Claude picks up from its last completed block. In scripts, resume the session and send continue.
Why does this keep happening to me?
Repeated notices usually point at the network path: unstable Wi-Fi, a VPN, a proxy or gateway that ends long responses, or a computer that sleeps during long turns. Test without the VPN or proxy if you can, and keep the computer awake.
Is this the same as “Unable to connect to API”?
No. “Unable to connect” means the connection never opened. “Connection lost mid-response” means it opened, part of the reply arrived, and then it broke.
Conclusion
The Claude Code connection lost mid-response error sounds worse than it is. It tells you a reply was cut off partway, that everything Claude finished is kept, and that Claude Code chose not to re-send the request so no tool call runs twice. In our tests on v2.1.322, replying with continue picked the answer up where it stopped, and early drops were retried automatically with a visible countdown. If the notice keeps returning, check Wi-Fi, VPN, sleep and any proxy or gateway in the path, and you can keep working with Claude without losing the thread.


