Claude Code Slow? Find Where the Latency Comes From and Fix It

Blog / Troubleshooting

Claude Code Slow? Find Where the Latency Comes From and Fix It

When Claude Code is slow, the cause almost always falls into one of four buckets: a slow network path, server-side queueing or an ongoing incident, the model thinking for a long time, or a session context that has grown too long. Each needs a different fix, so before you switch proxies or reinstall anything, spend two or three minutes working out which layer is slow. The order below is: check external factors first, then the network, then your local session.

If you are getting outright errors or connection timeouts rather than "works but slowly," start with Claude Code connection timeouts and errors: a four-layer network checklist. That article covers the can't-connect case.

Where does the time in a request go?

Each round of a Claude Code request spends its waiting time roughly across these stages:

StageWhat it includesWhat it looks like when slow
Connection setupDNS resolution, TCP handshake, TLS handshake, proxy negotiationThe first request of a new session, or after a long idle period, is especially slow
Network round tripEvery back-and-forth of uploading the request and returning the responseEvery request is a bit slow, and streaming output stutters
Server-side queueingRequests wait to be scheduled when platform load is highEveryone is slow at the same time, and the status page may show an incident
Processing before the first tokenReading the whole context, model thinkingA long wait before the first character appears, more obvious as context grows
Output generationToken-by-token outputLong replies and large blocks of code are written slowly

Claude Code is also an agent, so one task usually runs many rounds: read a file, run a command, send the result back. For example, if each round costs 1 extra second, a 30-round task costs half a minute more. "It feels slow" is often a fixed per-round overhead multiplied by many rounds.

For details on connection setup, gateway round trip and time to first token (TTFT), see AI API latency breakdown: connection setup, gateway round trip and time to first token.

Step 1: Is Claude's server side having problems?

Ruling out external causes saves the most time.

  1. Open cdnping's Claude API status page (/status/anthropic). It probes api.anthropic.com from Cloudflare's edge every 5 minutes and syncs Anthropic's official status page every 15 minutes.
  2. Open Is Claude Code down? (/down/claude-code). This page puts the official status page, API probes and one-click user reports (can't connect, slow, got dumber, rate-limited, and so on) in one place. If "slow" reports jump noticeably in a short window, it isn't just you.
  3. Compare with Anthropic's official status page, https://status.anthropic.com, to see whether there is an ongoing incident and which component is affected.

For how to read incident levels, and what "partial component degradation" means in practice, see How to read the OpenAI and Claude status pages.

Some background: in the official status page records that cdnping syncs, from 2026-09-17 to 2026-10-17 there were 8 Claude-related incidents, of which 6 had impact level major, 1 minor and 1 none. So checking server status first is not wasted effort. For the incident details in that period, see AI service incidents roundup: September-October 2026.

Also, server overload does not always show up as an incident on the status page. If the status page is green but "slow" reports on /down/claude-code cluster in the same time window, you can still treat it as a server-side cause: wait a bit, or run long, non-urgent tasks at a different time.

Step 2: Is your network path slow?

If the server side is fine, look at the network. This step answers two questions: is the connection from your machine to api.anthropic.com slow, and does your traffic take the path you think it does?

Test once in the browser

Open cdnping online speed test (/) and look at two numbers on the Claude row:

  • First connect: includes DNS and TLS handshakes, and reflects connection setup cost.
  • Round trip: the median of 3 requests after the connection is reused, reflecting per-round latency in steady state.

Compare against other services on the same page. If all overseas APIs are slow, the problem is your outbound path; if only Claude is slow, combine this with the status pages from Step 1.

For reference, in the window that cdnping had just started collecting, 2026-10-17 16:40-18:05 (Beijing time), probes of api.anthropic.com from the Cloudflare Denver (DEN) node showed a median of 73 ms and a p95 of 84 ms, with every probe in the window succeeding. That figure was measured from a US data center. It only shows that the API entry point itself was responding normally at the time, and says nothing about latency from mainland China networks. For why latency to overseas AI APIs varies so much from China, see AI API latency from China.

Test the real path in your terminal with the command line

The proxy your browser uses is often different from the one your terminal uses. Claude Code runs in the terminal, so test in the same terminal:

# First check whether proxy variables are set in the terminal
env | grep -i -E 'https?_proxy|all_proxy|no_proxy'

# Time each phase, 5 runs in a row
for i in 1 2 3 4 5; do
  curl -s -o /dev/null \
    -w 'dns=%{time_namelookup}s tcp=%{time_connect}s tls=%{time_appconnect}s first_byte=%{time_starttransfer}s total=%{time_total}s\n' \
    https://api.anthropic.com/v1/messages
done

This request carries no key and will quickly return an error status code, but the timings are valid, since they measure only the network portion. How to read the results:

  • dns is clearly large (several hundred milliseconds or more): DNS is slow, or resolution is unstable. See the DNS over HTTPS setup guide.
  • A large gap between tcp and tls: the TLS handshake is slow, commonly because the proxy path takes a detour or the node is heavily loaded.
  • first_byte varies a lot between runs: path jitter. When an agent runs many rounds, jitter hurts the perceived experience more than average latency does.
  • One or two of the 5 runs are very slow or fail: packet loss or an unstable proxy node, which shows up as Claude Code occasionally hanging for a long time.

Confirm which path your traffic takes

Open IP and environment check (/ip) and focus on two items:

  • Exit IP and multi-exit detection: confirm where the exit actually used for Claude is. If it differs from what you expected, your routing rules are not taking effect.
  • Latency characteristics: comparing the browser round trip with the exit's TCP round trip shows whether there is an extra relay somewhere along the path.

If you run a dual-stack network, also watch for mismatched IPv4 and IPv6 exits; see IPv6 proxy not taking effect. For the full network self-check sequence, walk through the developer network self-check checklist (2026 edition).

When using Claude and other overseas AI services, comply with their terms of service and local laws and regulations. Anthropic publishes official information on supported regions; the official documentation is authoritative.

Step 3: Is the model just "thinking"?

If the network and server side are both fine but it is still slow, check whether the time is being spent by the model itself.

To tell, observe which stage is slow.

  • A long wait before the first character, then smooth output: usually context reading and thinking time. With extended thinking enabled, or for tasks that need multi-step reasoning, this stage gets noticeably longer. That is normal, not a fault.
  • The output itself is slow: either path jitter (go back to Step 2) or this round is writing a lot of content, such as rewriting a whole file.

What you can adjust:

  • Simple tasks (renaming a variable, formatting, looking up a function) don't need the strongest model tier. Use /model to switch to a lighter tier, and responses will be much faster.
  • For tasks that don't need deep reasoning, don't ask it in the prompt to "think carefully" or "reason step by step"; such prompts add thinking time.
  • Have it change a part rather than rewrite the whole file. Say "only change this function" or "give me a diff"; less output means shorter generation time.

Step 4: Is the context too long?

This category is easy to overlook. Claude Code puts the conversation history, files it has read and command output all into the context. The longer a session stays open, the more content each round has to send and process, and the time to first token grows with it.

How to tell

  • Start a new session and ask the same question. If the new session is clearly faster, it is almost certainly a context problem.
  • Use /context to see current context usage (available in newer versions), and /cost to see this session's token consumption.
  • Think back on whether this session had it read large files or run commands with long output (such as full test logs, build logs, or git log).

How to handle it

SituationWhat to do
One task is done and you're starting an unrelated oneClear the session with /clear
You need to continue the same task but the history is too longCompress the history with /compact, keeping the key points
You repeat the same project background every timePut the background in the project's CLAUDE.md and keep it short
Command output is very longHave it use head, tail or grep to take only what's needed
It read many irrelevant filesGive file paths directly in your question to cut down its own search rounds

A long context is not only slow but also more expensive. If you call the API directly, prompt caching can lower cost and processing time for repeated long prefixes; see How to use Claude API prompt caching to save money.

A five-minute checklist

When Claude Code is slow, go through this order:

  1. Open /down/claude-code and /status/anthropic. An incident, or clustered "slow" reports, means a server-side cause: wait or avoid peak times.
  2. Open the cdnping speed test and look at Claude's first connect and round trip. If they're clearly high and other overseas APIs are the same, it's an outbound path problem.
  3. Run the curl timing command above in the terminal where Claude Code runs. If the terminal result is much worse than the browser's, the terminal isn't using the proxy you think it is; check variables such as HTTPS_PROXY.
  4. Open /ip to confirm the exit and routing match your expectations.
  5. Start a new session and ask the same question. If it's clearly faster, the context is too long; use /compact or /clear.
  6. If everything above is normal and the slowness is before the first token, it is model thinking time: consider a lighter tier or splitting the task into smaller ones.

It helps to write down your results: the time, the speed test numbers, and whether there was an incident. Slowness is often intermittent, and with a few records it is easier to see whether it happens at fixed times (server load) or at random (path jitter).

Using a custom endpoint: what else to check

If you point Claude Code at another gateway through ANTHROPIC_BASE_URL, the request path gains a segment: your machine, then the gateway, then the upstream. The "slow" may then come from the gateway itself, so test the pieces separately:

  • Run the curl timing above against the gateway address and compare with the result from connecting directly to the official API.
  • Check whether the gateway publishes availability data, and how it defines the metric.

For configuration, see Configuring custom API endpoints for Claude Code, Codex and OpenCode. For which metrics to look at when choosing a gateway, see How to choose an AI API relay: 8 checks.

Here is an example you can check directly. AGI Plan is a commercial partner of cdnping. AGI Plan publishes hourly request success and failure counts per capability group at https://agiplan.dev/api/status/requests?month=YYYY-MM, with no login required, and cdnping's /status/agiplan mirrors it. Whichever gateway you use, having raw data like this gives you a basis for deciding whether the gateway is the problem.

Related articles

Keep reading