OpenAI Codex Tutorial for China: From Payment and Installation to Hands-On CLI Usage

10/31/2025 Codex CLIinstallation-tutorialchinese-setupGPT-5-CodexWSLAI-programmingproxy-tools

# 1. Before We Begin: Why Now Is the Best Time to Return to Codex?

Recently, OpenAI's coding powerhouse Codex has once again set the tech world abuzz. Although account and network issues are still a small hurdle for users in China, this upgrade is so compelling that it's hard to resist giving it a try.

Six months ago, my primary AI coding tool was Cursor; three months ago, I switched to Claude Code. However, the recent "intelligence downgrade" controversy and unstable service led me to look for a more reliable alternative.

As it happens, last month OpenAI dropped a major piece of news: ChatGPT Plus users can log in and use Codex CLI directly without configuring an API Key!

This change dramatically lowered the barrier to entry. Combined with the fact that the whole internet is praising the new Codex for "a qualitative leap in code generation ability," I reinstalled Codex CLI with a "let's see what it's about" attitude. The result: once I used it, there was no going back.

This tutorial is my "record of pitfalls and hands-on experience" prepared for you, hoping to help everyone who is new to Codex get up to speed quickly.

Friendly reminder: Codex is currently a paid service. If you are still a free-tier user, you can consider using this one-click upgrade tool, which is very convenient: Domestic ChatGPT upgrade service: gptplus.org.cn (opens new window)

If you don't have an account yet, you can register directly with any email address.

# 2. Which Users Can Use Codex Directly?

Currently, access to Codex has been opened to all paid members, including ChatGPT Plus, Pro, and Business. As long as you are one of them, you can use Codex seamlessly in any of the following three ways:

  • Codex web version
  • IDE extensions (VSCode, Cursor, etc.)
  • Codex CLI (terminal command-line tool)

The new-generation GPT-5-Codex model is deeply optimized specifically for CLI, IDE plugins, and cloud environments, designed to deliver the ultimate coding experience.

# 3. Codex CLI Quick Installation Guide

# 3.1. Install Codex CLI via NPM

If your computer already has a Node.js environment set up, installing Codex CLI only takes a few commands.

Steps:

# 1. Make sure your Node.js version is no lower than 22
node -v
# Example output: v22.21.10

# 2. Use NPM to install Codex CLI globally
npm i -g @openai/codex

# 3. Verify the installation was successful
codex --version
# Example output: 0.42.0

Network acceleration for China:

If you find the NPM installation speed too slow, you can use a domestic mirror registry to speed it up:

npm i -g @openai/codex --registry=https://registry.npmmirror.com

# 3.2. Install the Codex Plugin in Your IDE

If you're not used to the command line, you can install the plugin version of Codex directly from your IDE's extension store. It provides a more user-friendly graphical user interface (GUI). Currently, mainstream IDEs such as VSCode and Cursor are all supported.

After installation, you can describe your needs directly in the input box, such as "refactor this file" or "add a new feature." At the same time, you can conveniently switch models. My personal recommendation is to always use the most powerful GPT-5-Codex (high).

For beginners, the IDE plugin is undoubtedly the simplest and most intuitive way to experience Codex.

# 4. One-Click Login: Start Your Codex Journey

After installation, enter the following command in the terminal to start:

codex

On first run, it will automatically open a browser and guide you through authorization.

Select the first option, Sign in with ChatGPT, and log in and authorize using your paid ChatGPT account. After success, the page will automatically write the authorization credential (Token) to the local ~/.codex/token file. The whole process requires no manual copy-pasting of any KEY, which is very convenient!

What if the login callback fails?

If you encounter a callback failure or network error after authorization, this is usually a proxy issue. Please enable the global mode (TUN Mode) of your proxy tool to ensure terminal traffic can access OpenAI normally.

After enabling it, return to the terminal and re-run the codex command to authorize again.

# 5. Core Codex CLI Commands and Practical Tips

# 5.1. How to Make Codex Reply in Chinese?

This is a very practical configuration. With just a single command, you can make Codex communicate with you in simplified Chinese by default.

Run the following command in your terminal (Mac/Linux):

mkdir -p ~/.codex && printf 'Always respond in Chinese-simplified\n' > ~/.codex/AGENTS.md

This command creates an AGENTS.md file in the ~/.codex/ directory and writes the content "Always respond in Chinese-simplified" into it, making the setting permanent.

# 5.2. Common Commands and Scenario Examples

Scenario Example Command Experience
1. Generate code directly codex "write a Python script to download a file" Produces high-quality, runnable code in about 3 seconds, with no unnecessary explanations.
2. Interactive conversation codex enters interactive mode, then >> change the script above to run concurrently Supports Tab completion and Ctrl-R history search, with an experience comparable to zsh.
3. Read images to debug codex -i error.png "analyze and fix the error shown in the image" Can directly read error screenshots from your terminal or IDE, eliminating the need to manually copy and paste error messages.
4. Refactor an entire project codex "add context passing to the entire Go project" Automatically analyzes the project -> generates a refactoring plan -> produces Diff code in chunks for your review -> applies it with one click after confirmation.
5. Automated testing codex exec "make the current project's pytest pass" Automatically installs missing dependencies -> runs the tests -> if they fail, can automatically roll back to the last successful commit.

# 6. Codex vs. Claude Code: An In-Depth Comparison

Dimension Codex (GPT-5) Claude Code (Opus 4.1)
Login barrier Very low: ChatGPT Plus/Business users log in with one click, no API Key needed. Fairly high: Requires an account from a specific region + phone verification, and is demanding about the network environment.
Response speed Fast: average first token in 1.2 seconds, nearly instantaneous, with crisp and clean code generation. Medium: about 2.5 seconds, tends to analyze and summarize before giving code, feeling a bit slow.
Context capability Strong: stable handling of 200k+ tokens in testing, accurately understanding medium-to-large codebases. High in theory: supports up to 1M, but easily loses focus in complex multi-file projects.
Engineering capability Excellent: strictly generates files according to directory structure, clear Diff approval workflow, strong engineering awareness. Decent: occasionally "over-optimizes" by merging multiple files into one output, breaking the original structure.
Ecosystem & experience Professional: built-in task panel, mature Hooks community ecosystem, clean UI, focused on functionality. Complex: a larger command system, with a certain learning curve for beginners.
Pricing strategy Great value: tied to Plus/Business membership with ample quota (about 40 deep interactions every 3 hours). Tiered pricing: ranges from $20 to $200, with some risk of instability.
Privacy model Cloud sandbox: code runs in a secure cloud sandbox, with no history retained. Local execution: more private, but heavily dependent on local machine performance and environment configuration.

Money-saving tip: Currently, opening a Business membership is a great value-for-money option. I opened one using the self-service tool below for just a few dozen yuan. Business has exactly the same Codex quota as Plus, but at a much lower price.

Domestic self-service ChatGPT upgrade tool: gptplus.org.cn (opens new window)

# 7. Common Codex Errors and Solutions

# 7.1. Error: 401 Unauthorized

This error means your authorization has expired or your membership has lapsed.

Solution: In Codex interactive mode, enter the /logout command to log out, then re-run the codex command and authorize via the web again.

# 7.2. Error: 502 stream error or Connection Failure

These problems are almost always network-related.

Solution:

  1. First choice: enable the global routing mode (TUN Mode) of your proxy tool.
  2. Alternative: if your proxy tool supports it, enable "system proxy" and manually specify the proxy server in the terminal:
    export HTTPS_PROXY=http://127.0.0.1:7890
    export HTTP_PROXY=http://127.0.0.1:7890
    export ALL_PROXY=socks5://127.0.0.1:7890
    
    (Replace port 7890 with the actual port of your proxy tool)

Finally, happy Vibe coding! Enjoy the rhythm of coding rather than being weighed down by it.