OpenAI Codex CLI Complete Tutorial
Codex is an AI coding assistant developed by OpenAI. It helps developers write, debug, and improve code using natural language instructions.📖 Contents Covered:This guide explains how to install and set up the OpenAI Codex CLI using the AGCloud Aggregation API, enabling direct usage in China without the need for a proxy. It supports Windows, Linux, and macOS, and can be integrated with third-party IDEs like VS Code.
1. Codex CLI Introduction and System Requirements
Codex AI is an AI-powered coding assistant developed by OpenAI. It can understand natural language instructions and help developers with software tasks such as writing code, fixing bugs, refactoring, and generating pull requests. Codex works across tools like terminals, IDEs, and web interfaces, and is designed to make software development faster and more efficient by acting as an intelligent partner that can read and modify your codebase in context.
System Requirements
2. Codex CLI Installation
2.1 Linux(Ubuntu) Installation
Step 1: Update System Packages🎉 Congratulations! Codex CLI installation is complete!
2.2 macOS Installation
macOS users are recommended to use Homebrew for installation: 1. Install Homebrew2.3 Windows (WSL) Installation
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
1. Get You API Key
2. Temporary Configuration (Valid for Current Session)Windows Environment Variables & Model Configuration
PowerShell Environment Variables
Run the following commands in PowerShell. To persist them, add the same lines to
$PROFILE or set them through System Properties → Environment Variables.Reload Your Profile
Configure Models in config.toml
On Windows, the Codex CLI config file lives atC:\Users\<USERNAME>\.codex\config.toml. Use it to persist your model choices and AGCloud endpoint:
Configure config.toml
Default configuration file path:~/.codex/config.toml
Official configuration documentation:Codex Configuration Documentation
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 AGCloud Aggregation API)env_key: Environment variable namewire_api: API type (chat or completions)
- 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
5. Getting Started with Codex CLI
Initialize Project
Usage Scenario Examples
Scenario 1: Code Generation6. Troubleshooting and Common Issues
Common Issue Solutions
1. Permission Issues Solution:- Confirm API Key is configured correctly
- Check if
base_urlconfiguration is correct - Use AGCloud to ensure direct connection in China
- Verify network connection:
curl https://aiandgpu.com/v1/models
Verify 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:~/.bashrc or ~/.zshrc:
8. Best Practice Recommendations
9. Resource Links
9.1 Official Resources 9.2 Third-Party Resources- AGCloud - Direct Connection API Service in China
- Node.js Official Website
- Windows WSL Documentation
- Visual Studio Code
Summary
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 AGCloud for stable direct connection API service in China