CodexUse logo CodexUse Download

Codex usage basics: commands, examples, pitfalls

The Codex CLI is an AI coding agent that runs in your terminal. This guide covers Codex usage essentials: installation, authentication, and the commands you will actually use.

Installation

Choose your preferred installation method:

# Via npm (requires Node.js 18+)
npm install -g @openai/codex
# Verify installation
codex --version

Authentication

The first time you run codex, it opens a browser for OpenAI authentication. Your credentials are stored locally.

Basic Codex commands

Interactive mode

Just run codex to start an interactive session:

# Start interactive session
codex
# Start in a specific directory
codex -C /path/to/project
# Start with a specific model
codex --model gpt-5.3-codex

Non-interactive (exec mode)

Use codex exec for single tasks, great for scripting:

# Execute a single task and exit
codex exec "Add error handling to main.py"

Codex configuration

Codex configuration controls model selection, sandbox mode, and approval policy. Key settings include:

Understanding sandbox modes

Common Codex usage patterns

Code explanation

codex
> Explain what this function does

Refactoring

codex
> Refactor the UserService class to use dependency injection

Bug fixing

codex
> The login form submits twice when clicking the button - fix it

Test generation

codex
> Write unit tests for the PaymentProcessor class

Common Codex usage pitfalls

1. Wrong model name

If you specify a model that does not exist, Codex will error. Valid models depend on your auth provider. Check your CLI docs for the current list.

2. Sandbox blocking needed operations

If Codex cannot write files or access the network when you expect it to, check your sandbox_mode setting.

3. Rate limits with no warning

The CLI does not show remaining quota. You only know you are rate-limited when you hit a 429 error. CodexUse can help by monitoring rate limits per profile (Pro).

4. Single account limitation

The CLI only supports one account at a time. To manage multiple accounts without constant re-authentication, use CodexUse.

How to log out of Codex

To log out of Codex CLI, you can remove the stored auth credentials. With CodexUse, you can simply switch to a different profile instead of fully logging out.

Tips for effective Codex usage

Related

How do I install the Codex CLI?

Use npm install -g @openai/codex or brew install --cask codex on macOS.

What is the difference between interactive and exec mode?

Interactive mode (codex) is for conversation-style work. Exec mode (codex exec) runs a single task and exits.

How do I log out of Codex?

Remove the stored auth credentials, or use CodexUse to switch profiles instead.

Download CodexUse for multi-account support