Skip to content
Free Tool Arena

AI & LLMs · Guide · AI & Prompt Tools

How to Use Codex CLI

Installing codex, running sandboxed commands, multimodal inputs, approval modes, config file, and gotchas.

Updated April 2026 · 6 min read

Codex CLI is OpenAI’s open-source terminal agent: a `codex` command that edits files, runs shell commands, and reasons about code inside a sandbox.

Advertisement

Codex CLI gives you an agentic loop at the command line, backed by OpenAI’s coding-tuned models. You launch `codex` in any directory, describe a task, and it reads files, proposes edits, runs commands, and iterates until the task is done or it needs your input. Unlike a chat window, it keeps execution inside a sandbox and surfaces diffs for approval before touching disk, which makes it safer to hand real work.

What it is

Codex CLI is an Apache-2.0 project from OpenAI on GitHub. It ships as an npm package and authenticates with either a ChatGPT login (tied to your plan’s usage) or an OpenAI API key. The agent is multimodal — it can read images pasted into the terminal — and uses the Responses API under the hood. It supports MCP servers for extending tools.

Install

# Node 20+
npm install -g @openai/codex

# first run prompts for login or API key
codex

First session

Run `codex` in a project directory. Pick an approval mode (suggest, auto-edit, or full-auto) and describe a task.

$ codex
> Fix the failing test in tests/users.spec.ts
→ reads test → greps source → proposes patch → runs npm test

Everyday workflows

  • Bug triage — paste a failing CI log and let Codex reproduce and patch locally.
  • Small features — scope a single endpoint or component and let it run in auto-edit mode.
  • Refactors — ask for a rename or extraction, review the diff, commit.

Gotchas and tips

Full-auto mode is tempting but will happily rewrite large swaths of code if the task is vague. Use suggest mode for anything near production, and keep dirty working trees out — Codex occasionally stages changes it then undoes. Commit or stash before starting.

The sandbox blocks network by default on some platforms; if your task needs npm install or a curl, enable network access explicitly for that session. A codex.md or AGENTS.md file at the repo root lets you pin conventions that apply every run.

Who it’s for

Developers already in the OpenAI ecosystem who want a terminal-native alternative to ChatGPT’s code interpreter, with real access to their local filesystem. Start with a test-fix task — narrow, verifiable, and a great sanity check of the tool’s behavior.

Advertisement

Found this useful?Email