Last updated:

Codex CLI, Claude Code and Gemini CLI in China

The browser works and the terminal does not: that is the usual story for AI coding tools in China. The reason is the same for all three, and so is the fix.

Why the browser works and the terminal does not

A desktop VPN app normally works by setting a system proxy. Browsers and most desktop apps follow it. Programs started in a terminal, which is where Codex CLI, Claude Code and Gemini CLI run, generally ignore it and try to connect directly.

From mainland China that direct connection goes nowhere, so the tool hangs, times out or reports a network error, while chatgpt.com, claude.ai and gemini.google.com open fine in the browser next to it.

Two fixes in the DopeVpn desktop app

  • —Turn on Enhanced mode under Connection mode. It routes every program on the computer through the VPN, terminals and editors included, so you do not have to think about it again. It needs administrator rights on Windows and your password once on a Mac (Mac app 0.5.33 or later)
  • —Or connect, click Copy terminal proxy command and paste it into the terminal before starting the tool. It applies to programs started from that window only, so paste it again in each new terminal

Enhanced mode is the one to use if you also run these tools from an editor's built-in terminal, a script or a scheduled job, because those do not inherit a command you pasted somewhere else.

The region check still applies

Getting through the firewall is not the whole job. OpenAI, Anthropic and Google check where a request comes from, and mainland China and Hong Kong are both refused, so a tool whose traffic leaves through Hong Kong fails with a region error instead of a network one.

ChatGPT, Claude, Gemini, Cursor and other AI traffic is routed automatically through dedicated AI exits in Japan (Tokyo / Osaka), and each account keeps the same exit — nothing to set up, including on the free trial.

That covers the endpoints these tools use: openai.com and chatgpt.com for Codex, anthropic.com, claude.ai and claude.com for Claude Code, and the Gemini API and the Gemini CLI / Code Assist backend for Gemini CLI. With Enhanced mode on they take that route even from the terminal.

Signing in

All three sign in through your browser and then work from the terminal. The browser half works as soon as the VPN is connected. If the browser says you are signed in and the tool still cannot connect, the terminal half is the problem: turn on Enhanced mode or paste the proxy command, then run the sign-in command again.

If you use an API key instead of signing in, nothing changes: the key is sent from the terminal, so the same two fixes apply.

Per tool

Claude Code. Anthropic's region rules, and why Hong Kong exits fail, are covered in using Claude and Claude Code in China.

Codex CLI. It signs in with your ChatGPT account, so the verification loops in using ChatGPT in China apply to its browser step.

Gemini CLI. It signs in with Google, which is blocked in China on its own; see using Gemini in China.

Cursor and other editors. Editors have their own version of the region problem, covered in using Cursor in China. Setup for the app itself is in the Mac and Windows guides.

Quick answers

Why does Codex CLI (or Claude Code, or Gemini CLI) time out in China when my VPN is on? Desktop VPN apps set a system proxy, and programs started in a terminal do not read it, so the tool is connecting directly and hitting the firewall. Turn on Enhanced mode in the DopeVpn desktop app, or paste its terminal proxy command into the terminal.

The browser sign-in finished but the CLI still says it cannot connect. Why? The sign-in page opens in your browser, which uses the VPN; the tool then makes its own requests from the terminal, which does not. Fix the terminal side with Enhanced mode or the proxy command and run the command again.

Do I need a VPN in a specific country for these tools? Yes. OpenAI, Anthropic and Google all refuse requests from mainland China and from Hong Kong. DopeVpn sends their traffic through its AI exits in Japan whichever server you have selected.

AI routing is on by default

Including on the 3-day free trial. Nothing to configure.

Create a free account

Want the numbers first? See plans and prices