Can Claude Code work offline?
No. Claude Code is a thin client: every turn needs a reachable model endpoint, and none of that is optional. We pointed CLI 2.1.170 at an unreachable endpoint on Windows 11 — it retried for roughly three minutes, then exited with API Error: Unable to connect to API (ConnectionRefused). The binary itself still launches offline; only prompts fail. For a genuine air gap, use Aider or Cline with a locally hosted model.
--offline flag — the CLI rejects it as an unknown option ✗ Gateways don't help — Bedrock, Vertex and ANTHROPIC_BASE_URL all still need a reachable server ✓ The binary starts offline — claude --version answered in 247 ms with the API unreachable ✓ An offline path exists, just not this tool — Aider or Cline against a local model Cut the CLI off from its model endpoint — it hung for three minutes, then failed.
We simulated loss of connectivity by pointing the CLI at an endpoint with nothing listening — ANTHROPIC_BASE_URL=http://127.0.0.1:9 — rather than switching off the network adapter. This isolates the variable we care about: the model endpoint. A true air-gapped box would also lose DNS and every other host in Anthropic's documented allowlist, so the real-world failure is at least as hard as what we measured.
The control run, against the normal endpoint, answered a one-word prompt in 6.3 seconds. With the endpoint unreachable, the same prompt hung and retried before exiting with status 1 and a single line: API Error: Unable to connect to API (ConnectionRefused). Three consecutive runs took 172.5 s, 187.2 s and 185.4 s — so budget roughly three minutes before the CLI gives up, not the instant failure you might expect.
One nuance worth keeping: the binary is not dead offline. With the same unreachable endpoint, claude --version returned in 247 ms. Local commands that need no model still run. It is the prompt — the thing you actually opened the tool for — that fails.
The technical reason it can't.
Claude Code splits into two halves. The agent half — reading files, proposing diffs, running your commands — executes on your machine. The reasoning half does not. Deciding what to do next, writing the code, interpreting what it just read: each of those is a request to a model served over the network.
Anthropic's own network configuration page lists api.anthropic.com as required for Claude API requests, and enterprises are told to allowlist it in firewalls and containers. There is no entry in that table for a local fallback, because there isn't one.
Three things people reasonably hope for, none of which exist:
- A bundled local model. Nothing ships with the CLI that can answer a prompt on its own.
- An offline switch.
claude --offlinereturnserror: unknown option '--offline'on 2.1.170. We ran it. - A replay cache. Anthropic's prompt caching is an API-side feature — it cuts the price of repeated context on the server, and leaves nothing on your disk to answer from when the server is unreachable.
The usual counter-suggestion is to route Claude Code somewhere else: an LLM gateway via ANTHROPIC_BASE_URL, Amazon Bedrock, Google Cloud's Agent Platform, Microsoft Foundry. All of those work, and all of them move the traffic rather than remove it — you are now calling a different server that still has to be reachable.
There is a sharp edge worth knowing even on those routes: per the same docs, the WebFetch tool still calls api.anthropic.com for its domain safety check unless you set skipWebFetchPreflight: true. A gateway alone doesn't take you off Anthropic's network entirely.
The failure mode matters more than the verdict. Claude Code does not tell you immediately that it can't reach the model — it retried for around three minutes in all three of our runs before printing one line and exiting. On a flaky hotel connection or a train, that is three minutes of a blinking cursor per attempt.
Where this actually bites: flights without usable wifi, air-gapped and classified environments, sites where an outbound allowlist hasn't been updated, and regions with unreliable connectivity. If any of those describe your week, the alternatives below matter more than the workarounds.
If air gap is the requirement.
Both options below are open-source agents that can point at a model running on your own hardware, so the whole loop stays local. We have not benchmarked either against Claude Code — treat the swap as a capability trade you should test on your own repo, not an equal substitute.
Frequently asked.
Quick follow-ups people search after this question.
Q · 01 Does the CLI start at all without a connection? +
claude --version returned in 247 ms on our box. Local commands that need no model still work — installation, version checks, help output. Only the prompt fails, which is admittedly the reason you opened it.Q · 02 Why does it hang for minutes instead of failing immediately? +
172.5 s, 187.2 s and 185.4 s across three consecutive runs against an unreachable endpoint, each ending in exit status 1. If you are on a connection that drops, expect a long pause rather than a fast error.Q · 03 Is there an --offline flag? +
2.1.170, claude --offline returns error: unknown option '--offline'. There is also no queue-and-send-later mode — nothing to capture prompts while disconnected and replay them when you reconnect.Q · 04 Does Bedrock, Vertex or an LLM gateway make it work offline? +
api.anthropic.com for its domain safety check unless you set skipWebFetchPreflight: true, so even a gateway route isn't fully off Anthropic's network by default.