Skip to content

CLI and Slash Command Tips

You open a terminal, type codex "fix the bug", and wait. It works, but it is the slowest way to use the CLI. Power users chain sessions, pipe structured output, fork conversations when they hit a dead end, and use slash commands to trigger code reviews without leaving the TUI. The Codex CLI is a full development environment disguised as a single binary.

  • Session management patterns that eliminate context re-entry
  • Slash commands for review, permissions, and model switching
  • Image input techniques for visual debugging from the terminal
  • Scripting patterns with codex exec for automation
  • Keyboard shortcuts and TUI tricks that save time on every turn

The most common CLI waste is re-explaining context. Use resume instead:

Terminal window
# Resume the most recent session
codex resume --last
# Resume from any directory (not just the current one)
codex resume --last --all
# Resume a specific session by ID
codex resume abc12345-...
# Resume and immediately give a follow-up instruction
codex resume --last "The approach we discussed works. Implement it and run tests."

The resumed session carries over the entire transcript, so Codex remembers every decision, constraint, and file it touched.

Want to try an alternative approach without losing your current conversation?

Terminal window
# Fork the most recent session
codex fork --last
# Fork a specific session
codex fork abc12345-...

This creates a new thread with the full transcript of your previous session. You can branch the conversation in a different direction while the original stays intact.

Resume works with codex exec too, so you can continue automated sessions:

Terminal window
# Continue the last exec session with new instructions
codex exec resume --last "Fix the race conditions you found"
# Resume a specific exec session
codex exec resume abc12345-... "Implement the plan"

Type these inside the interactive TUI:

CommandWhat It Does
/reviewOpen the code review menu
/forkFork the current session
/modelSwitch the model mid-session
/permissionsChange approval mode without restarting
/statusCheck remaining context, credits, and loaded files
/exitClose the session
/feedbackSubmit feedback to OpenAI
/skillsBrowse and invoke available skills
/compactManually trigger context compaction

/review opens a menu with four presets:

  1. Review against a base branch — Diffs your work against the upstream merge base
  2. Review uncommitted changes — Inspects staged, unstaged, and untracked files
  3. Review a commit — Picks a recent commit and analyzes the exact changeset
  4. Custom review instructions — Your own prompt (e.g., “Focus on accessibility regressions”)

The review runs as a read-only pass and reports findings without modifying files. Set a dedicated review model in config:

review_model = "gpt-5.3-codex"

You started in read-only mode but now trust the agent enough for full auto? Switch without restarting:

/permissions

Choose between Auto, Read-only, and Full Access mid-session.

ShortcutWhat It Does
@Fuzzy file search — drop a path into your message
!Run a local shell command inline
Enter (while running)Inject instructions into the current turn
Tab (while running)Queue a follow-up for the next turn
Esc (2x)Edit your previous message
Esc (repeated)Walk back through earlier messages to fork from any point
Ctrl + GOpen your $VISUAL editor for composing long prompts
Ctrl + CCancel the current operation

Type @ in the composer and a fuzzy file search opens over your workspace. Press Tab or Enter to drop the path into your message. This is faster than typing paths manually and ensures accuracy.

Prefix a line with ! to run a shell command without leaving the TUI:

!git log --oneline -5
!npm test -- --filter=auth
!cat src/routes/users.ts | head -20

Codex treats the output as context for your next prompt. Useful for feeding error messages, test output, or file contents directly into the conversation.

For long, multi-paragraph prompts, press Ctrl + G to open your configured editor ($VISUAL or $EDITOR). Write the prompt in your editor, save and close, and Codex sends it.

Terminal window
# Single image
codex -i screenshot.png "This screenshot shows a broken layout. Fix the CSS."
# Multiple images
codex --image before.png,after.png "The first image is correct. The second shows a regression. Find what changed."

Paste images directly into the composer. On macOS, you can screenshot with Cmd + Shift + 4 and paste the clipboard image.

Terminal window
# Non-interactive task
codex exec --full-auto "Fix the failing linter warnings and run the tests"
# With structured JSON output
codex exec --json --full-auto "Analyze the test coverage" 2>/dev/null | jq '.item.text'
# Pipe prompt from stdin
echo "Explain the auth middleware in src/middleware/auth.ts" | codex exec -

Force Codex to return data in a specific format:

Terminal window
codex exec --output-schema schema.json --full-auto "List all API endpoints with their HTTP methods and paths"

Where schema.json defines the expected shape:

{
"type": "object",
"properties": {
"endpoints": {
"type": "array",
"items": {
"type": "object",
"properties": {
"method": { "type": "string" },
"path": { "type": "string" },
"description": { "type": "string" }
}
}
}
}
}
Terminal window
codex exec --output-last-message result.md --full-auto "Generate a changelog for the last 10 commits"

The agent’s final response is written to result.md for downstream processing.

Terminal window
# Set the working root without cd
codex --cd /path/to/project "Analyze the codebase"
# Grant write access to additional directories
codex --cd apps/frontend --add-dir ../backend --add-dir ../shared "Coordinate changes across frontend and backend"

For one-off tasks outside a Git repository:

Terminal window
codex exec --skip-git-repo-check "Generate a Python script that parses CSV files"
Terminal window
# Interactive picker for cloud tasks
codex cloud
# Submit a task directly
codex cloud exec --env my-env-id "Run the full integration test suite and fix any failures"
# Submit with best-of-N attempts
codex cloud exec --env my-env-id --attempts 3 "Implement the caching layer"
# List recent cloud tasks
codex cloud list --json | jq '.tasks[] | {id, status, title}'
# Apply a cloud task's diff locally
codex apply TASK_ID
  • Session resume shows wrong context: Sessions are scoped to the working directory by default. Use --all to find sessions from other directories.
  • Shell completions not appearing: Ensure the eval line is after compinit in your shell config. Restart your shell.
  • codex exec hangs: The agent may be waiting for approval. Add --full-auto or --ask-for-approval on-request to avoid interactive prompts in non-interactive mode.
  • Image input rejected: Codex accepts PNG and JPEG. Other formats may not be supported. Convert with convert input.webp output.png before attaching.
  • ! command blocked: The sandbox still applies to inline shell commands. If the command needs write access or network, adjust your sandbox mode.