OpenAI Codex CLI Complete Tutorial
Installation, Configuration and Usage Guide - Support for Direct API Connection in China📖 Contents Covered:This article provides detailed instructions on how to install and configure OpenAI Codex CLI, combined with GPT Proto Aggregation API, which can be used directly in China without configuring a proxy. Supports Windows/Linux/Mac multi-platform, and can be configured with third-party IDEs such as VS Code.
1. Codex CLI Introduction and System Requirements
What is OpenAI Codex?
OpenAI Codex is an open-source command-line tool (CLI) that serves as a lightweight coding agent, capable of reading, modifying, and running code in the terminal. Codex is based on GPT models and is specifically optimized for code generation and understanding.System Requirements
| Item | Requirement |
|---|---|
| Officially Supported Systems | macOS and Linux (Recommended) |
| Windows Users | Strongly recommend using Windows Subsystem for Linux (WSL) |
| Node.js Version | Node.js 18+ (Required) |
| npm Version | npm 10.x.x or higher |
2. Codex CLI Installation Tutorial
Installation Steps (Using Ubuntu as Example)
Step 1: Update System Packages🎉 Congratulations! Codex CLI installation is complete!
macOS Installation Method
macOS users are recommended to use Homebrew for installation: 1. Install Homebrew (if not installed)Windows (WSL) Installation Method
Windows users need to install WSL first, then follow the Ubuntu installation steps. 1. Install WSL Open PowerShell as administrator and run:3. Codex CLI Configuration Tutorial
Configure API Key
1. Get API KeyRecommended: Use GPT Proto Aggregation API (Direct Connection in China)Visit https://gptproto.com to get API Key
- ✅ Direct connection in China, no proxy needed
- ✅ Supports multiple OpenAI models
- ✅ Affordable pricing, pay-as-you-go
Configure config.toml
Default configuration file path:~/.codex/config.toml
Official configuration documentation: Codex Configuration Documentation
Basic Configuration Example
Configuration Explanation:
model: Model name to use (e.g., gpt-4, gpt-3.5-turbo, etc.)model_provider: Model provider configurationbase_url: API base address (using GPT Proto Aggregation API)env_key: Environment variable namewire_api: API type (chat or completions)
4. IDE Integration Configuration
VS Code Integration
For third-party IDEs (such as VS Code), you need to install the corresponding Codex plugin. Installation Steps- Search for “OpenAI Codex” in VS Code extension store
- Install the official extension
- Configure Codex CLI path in settings
- Configure API Key (using the environment variable above)
Other IDE Support
| IDE | Support Status | Description |
|---|---|---|
| VS Code | Official Support | Full plugin support |
| JetBrains Series | Community Support | Integrated through terminal |
| Vim/Neovim | Community Support | Supported through plugins |
5. Getting Started with Codex CLI
Initialize Project
Common Command Examples
1. Basic PromptCommon Interactive Commands
| Command | Function Description |
|---|---|
/help | Display help information |
/exit or Ctrl+C | Exit Codex |
/clear | Clear conversation history |
/config | View current configuration |
/model <name> | Switch model |
/tokens | View token usage |
Usage Scenario Examples
Scenario 1: Code Generation6. Troubleshooting and Common Issues
Common Issue Solutions
1. Permission Issues 2. Node Version Issues 3. Network Connection Issues 4. Invalid API KeyVerify Configuration
Debug Mode
Enable verbose log output to help diagnose issues:7. Advanced Usage Tips
1. Custom Prompt Templates
Create commonly used prompt templates to improve efficiency:2. Batch Processing
3. Git Integration
4. Configure Aliases
Add aliases in~/.bashrc or ~/.zshrc:
8. Best Practice Recommendations
| Recommendation | Description |
|---|---|
| Clear Prompts | Provide clear, specific instructions, explaining expected output format and requirements |
| Context Information | Provide sufficient context, such as project tech stack, coding standards, etc. |
| Iterative Optimization | Gradually improve code through multiple rounds of dialogue, rather than expecting perfection in one go |
| Code Review | Always review AI-generated code to ensure it meets project standards |
| Version Control | Use Git to track changes for easy rollback and comparison |
| Security Awareness | Don’t send sensitive information (keys, passwords, etc.) to AI |
| Cost Control | Monitor token usage to avoid unnecessary API calls |
9. Resource Links
Official Resources
Third-Party Resources
- GPT Proto - Direct Connection API Service in China
- Node.js Official Website
- Windows WSL Documentation
- Visual Studio Code
Summary
Through this guide, you have successfully:
- ✅ Understood basic concepts and features of OpenAI Codex CLI
- ✅ Installed Codex CLI on Linux/macOS/Windows systems
- ✅ Configured GPT Proto Aggregation API (direct connection in China)
- ✅ Mastered basic usage methods and common commands
- ✅ Understood IDE integration methods
- ✅ Learned troubleshooting and problem solving
- ✅ Mastered advanced usage tips and best practices
Need Help?
If you encounter problems during use:- Check GitHub Issues
- Visit OpenAI Community
- Refer to Official Documentation
© 2025 OpenAI Codex CLI Tutorial | Complete Installation Configuration Guide Thank you for using Codex CLI - Let AI be your programming assistant Recommended to use GPT Proto for stable direct connection API service in China

