Claude Code “Connection Lost Mid-Response” Error: What It Means and What to Do

Claude Code “Connection Lost Mid-Response” Error: What It Means and What to Do

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

QuestionShort 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 wordingConnection closed mid-response (before v2.1.227)
Diagram of what Claude Code does when a connection drops before, during and after a reply, including the Connection lost mid-response notice
What happens after a dropped connection depends on how much of the reply had finished.

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.

Terminal showing Claude Code print mode output ending with API Error: Connection lost mid-response. The response above may be incomplete.
The message in print mode on Claude Code v2.1.322. With JSON output, the same text is reported in the 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.

Claude Code interactive session showing two finished tips followed by the yellow Connection lost mid-response notice
In a session, tips 1 and 2 were complete and stayed on screen. The third tip was cut off and is not shown.

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.

Official Claude Code error reference section The response above may be incomplete with the six message variants and the Connection lost mid-response entry highlighted
The official entry lists six variants of this notice. The connection one is highlighted.

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 withWhat happened
Connection lost mid-responseThe connection dropped, or a proxy or gateway ended the response body before it was finished
Your computer went to sleep mid-responseThe computer slept while the reply was streaming
The response stopped arrivingThe connection stayed open but no more data came, so Claude Code aborted it
Server error mid-responseAn overloaded or 5xx server error arrived in the middle of the stream
Part of the response never arrivedA piece of the stream was dropped between the API and Claude Code
The response stream was malformedA 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.
Official Claude Code Automatic retries section with the Dropped connections rule highlighted
The official rule for dropped connections. Early drops are retried; the entry below it covers drops caused by sleep.

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.

Claude Code session showing Connection dropped ECONNRESET with Retrying in 4s and attempt 4 of 10
An early drop in our test: Claude Code retried by itself and showed attempt 4 of 10.

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

Flow diagram of four steps after a Claude Code connection lost mid-response error: read the reply, type continue, check network, check proxy
The four steps in order. Steps 3 and 4 matter only when the message repeats.

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.

Claude Code session where the user replies continue after the Connection lost mid-response notice and the answer resumes at tip 3
After the notice we typed 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.

Official Claude Code error reference What to do list with the instruction to reply with continue highlighted
The official fix: read what remains, then reply with 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
Terminal showing curl reaching api.anthropic.com with an HTTP/2 reply and empty ANTHROPIC_BASE_URL and HTTPS_PROXY values
Our check on macOS. The status number does not matter here; an HTTP reply shows the host is reachable.

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
Official Claude Code network configuration page showing the proxy environment variables HTTPS_PROXY, HTTP_PROXY and NO_PROXY
The official network page lists the proxy variables Claude Code respects.

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

ItemAfter the notice
Your promptKept in the conversation
Blocks of text Claude finishedKept and shown
Tool calls Claude finishedKept; Claude Code runs them and continues from their results
The block that was mid-streamDiscarded when the turn ends
File edits already madeStay on disk
The sessionStill 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 json or stream-json, the message is in the result field. In our run, is_error was 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.

  1. Keep the computer awake during long turns. The sleep variant exists because this happens often. On a Mac, the built-in caffeinate -i command keeps the system awake while another command runs.
  2. Use a stable connection for long tasks. Wired or strong Wi-Fi beats a phone hotspot.
  3. 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.
  4. 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.
  5. 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.

VariableDefaultWhat it does
CLAUDE_CODE_MAX_RETRIES10Number of automatic retry attempts for failures Claude Code retries
API_TIMEOUT_MS600000Time each attempt has to receive its response headers. It does not limit how long a streaming response runs after that
Official Claude Code Tune retry behavior table with the CLAUDE_CODE_MAX_RETRIES row highlighted
The official retry settings table. These control the early retries, not the mid-response notice.

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.

MessageWhat it meansWhere to go
Connection lost before a response was producedThe connection kept dropping after thinking, before any text or tool callSend the message again
Unable to connect to APIThe connection never openedThe Unable to Connect guide linked above
API Error: 500A failure inside the APIOur 400 and 500 guide
Repeated 529 Overloaded errorsThe API is at capacityOur 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_MS to 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_error in the JSON output and resume with continue instead 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 /feedback so Anthropic can look at the request details.
  • General setup problems are covered on the official troubleshooting page, which suggests /doctor for a setup checkup.

Cheat Sheet

Cheat sheet of quick fixes for the Claude Code connection lost mid-response error
Cheat sheet: how to get the rest of the reply on the left, connection checks on the right.

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.

Newsletter

New AI tools in your inbox

The best new tools and the AI news that matters, in one short email. Unsubscribe any time.

Free · No spam · Unsubscribe any time

✓ Looks like you’re subscribed

Loading Google’s sign-up form…

Looks like you’re already subscribed

Thanks for reading! New AI tools and the AI news that matters will land in your inbox.

Not subscribed yet? Refresh the page to load the sign-up form.

The sign-up form couldn’t load. If you use an ad or content blocker, allow news.google.com and reload the page.

Free instant check before you pay. Takes a few seconds.

Scroll to Top