Codex CLI Quick Start Guide with Copy-Paste Examples

Codex CLI Quick Start Guide with Copy-Paste Examples

If you want to start using Codex CLI quickly, the fastest path is not to memorize every option. It is to learn a small working set of commands and one safe default profile.

This guide focuses on exactly that.

Codex CLI screenshot

Install or update Codex CLI

Start with the latest version:

npm install -g @openai/codex@latest
codex --version

If global npm permissions cause trouble, you may want to use a user-local prefix:

npm config set prefix ~/.npm-global
export PATH="$HOME/.npm-global/bin:$PATH"

The basic workflow

These are the commands worth remembering first:

codex -C <repo-path>
codex exec "describe the task here"
codex apply
codex -i path/to/image.png "Explain what is happening"

Use them like this:

  • codex -C <repo-path> starts an interactive session in a project
  • codex exec "..." runs a non-interactive task
  • codex apply applies a generated patch or diff
  • codex -i ... attaches an image for visual debugging or explanation

Safe approval and sandbox defaults

If you want a practical default that stays productive without being reckless, start here:

codex --sandbox workspace-write -a on-failure

That setup usually gives you a good balance:

  • writable access inside the workspace
  • approval only when needed
  • less friction than fully manual approval

If you intentionally want fully automated behavior, you may use:

codex --full-auto

Use a profile so you do not repeat flags

Create a simple profile in ~/.codex/config.toml:

[profiles.dev]
sandbox = "workspace-write"
ask_for_approval = "on-failure"

Then run:

codex -p dev -C ./your-project

This is easier than repeating the same flags every time.

A prompt template that works well

Weak prompts create retries. Strong prompts reduce wasted time and wasted usage.

Use this structure:

Goal: what should be done
Constraints: what may or may not be changed
Output: what deliverable is expected

Example:

codex -p dev -C ./app "Add ESLint with minimal changes. Update config, fix violations, add CI, and summarize what changed."

Useful commands to know early

codex login
codex logout
codex completion zsh
codex mcp
codex --search "research this and summarize it"

What they are good for:

  • login / logout: session management
  • completion zsh: shell completion
  • mcp: external tool integrations
  • --search: research-heavy tasks that need web access

Good non-interactive examples

codex --full-auto exec "Fix type errors, add tests, apply the patch, and summarize the result."
codex exec -i ./error.png "Find the likely cause and explain the fix."

These examples work because they define both the task and the expected outcome.

Troubleshooting

Command not found after install

Your global npm bin path may not be in PATH. Try:

export PATH="$(npm bin -g):$PATH"

It refuses to run in an untrusted repo

If you intentionally want to bypass that check:

codex exec --skip-git-repo-check "..."

Version issues

Check your Node version:

node -v

A modern Node runtime is usually required. If your environment is old, update Node before debugging Codex itself.

The options most worth remembering

  • -C <DIR>: run in a specific working directory
  • -p <PROFILE>: use a named profile
  • -c key=value: override a config value temporarily
  • -i <FILE>: attach an image
  • --sandbox: choose read-only / workspace-write / danger-full-access
  • -a: choose approval behavior

You do not need every option on day one. You need a reliable default and a few repeatable patterns.

Summary

The fastest way to get value from Codex CLI is:

  1. install the latest version
  2. use a safe profile
  3. prompt with goal, constraints, and output
  4. keep a short list of commands you actually use

That is enough to move from experimentation to a stable working workflow.

attrip

attrip

Turning thoughts into articles, AI workflows, and music.

Writing about bonsai, music, blogging, and everyday experiments.

Publishing since 2010

Leave a Reply