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.
What You’ll Walk Away With
Section titled “What You’ll Walk Away With”- 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 execfor automation - Keyboard shortcuts and TUI tricks that save time on every turn
Session Management
Section titled “Session Management”Resume Instead of Re-explaining
Section titled “Resume Instead of Re-explaining”The most common CLI waste is re-explaining context. Use resume instead:
# Resume the most recent sessioncodex resume --last
# Resume from any directory (not just the current one)codex resume --last --all
# Resume a specific session by IDcodex resume abc12345-...
# Resume and immediately give a follow-up instructioncodex 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.
Fork When You Want to Explore
Section titled “Fork When You Want to Explore”Want to try an alternative approach without losing your current conversation?
# Fork the most recent sessioncodex fork --last
# Fork a specific sessioncodex 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.
Non-Interactive Resume
Section titled “Non-Interactive Resume”Resume works with codex exec too, so you can continue automated sessions:
# Continue the last exec session with new instructionscodex exec resume --last "Fix the race conditions you found"
# Resume a specific exec sessioncodex exec resume abc12345-... "Implement the plan"Slash Commands
Section titled “Slash Commands”Built-In Commands
Section titled “Built-In Commands”Type these inside the interactive TUI:
| Command | What It Does |
|---|---|
/review | Open the code review menu |
/fork | Fork the current session |
/model | Switch the model mid-session |
/permissions | Change approval mode without restarting |
/status | Check remaining context, credits, and loaded files |
/exit | Close the session |
/feedback | Submit feedback to OpenAI |
/skills | Browse and invoke available skills |
/compact | Manually trigger context compaction |
Code Review with /review
Section titled “Code Review with /review”/review opens a menu with four presets:
- Review against a base branch — Diffs your work against the upstream merge base
- Review uncommitted changes — Inspects staged, unstaged, and untracked files
- Review a commit — Picks a recent commit and analyzes the exact changeset
- 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"Permission Switching with /permissions
Section titled “Permission Switching with /permissions”You started in read-only mode but now trust the agent enough for full auto? Switch without restarting:
/permissionsChoose between Auto, Read-only, and Full Access mid-session.
Keyboard Shortcuts in the TUI
Section titled “Keyboard Shortcuts in the TUI”| Shortcut | What 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 + G | Open your $VISUAL editor for composing long prompts |
Ctrl + C | Cancel the current operation |
The @ File Reference
Section titled “The @ File Reference”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.
The ! Shell Command
Section titled “The ! Shell Command”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 -20Codex treats the output as context for your next prompt. Useful for feeding error messages, test output, or file contents directly into the conversation.
The Ctrl+G Editor
Section titled “The Ctrl+G Editor”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.
Image Inputs
Section titled “Image Inputs”From the Command Line
Section titled “From the Command Line”# Single imagecodex -i screenshot.png "This screenshot shows a broken layout. Fix the CSS."
# Multiple imagescodex --image before.png,after.png "The first image is correct. The second shows a regression. Find what changed."In the Interactive TUI
Section titled “In the Interactive TUI”Paste images directly into the composer. On macOS, you can screenshot with Cmd + Shift + 4 and paste the clipboard image.
Scripting with codex exec
Section titled “Scripting with codex exec”Basic Automation
Section titled “Basic Automation”# Non-interactive taskcodex exec --full-auto "Fix the failing linter warnings and run the tests"
# With structured JSON outputcodex exec --json --full-auto "Analyze the test coverage" 2>/dev/null | jq '.item.text'
# Pipe prompt from stdinecho "Explain the auth middleware in src/middleware/auth.ts" | codex exec -Structured Output with Schemas
Section titled “Structured Output with Schemas”Force Codex to return data in a specific format:
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" } } } } }}Save the Final Message
Section titled “Save the Final Message”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.
Working Directory Tips
Section titled “Working Directory Tips”Start From Any Directory
Section titled “Start From Any Directory”# Set the working root without cdcodex --cd /path/to/project "Analyze the codebase"
# Grant write access to additional directoriescodex --cd apps/frontend --add-dir ../backend --add-dir ../shared "Coordinate changes across frontend and backend"Skip Git Repo Check
Section titled “Skip Git Repo Check”For one-off tasks outside a Git repository:
codex exec --skip-git-repo-check "Generate a Python script that parses CSV files"Cloud Tasks from the CLI
Section titled “Cloud Tasks from the CLI”# Interactive picker for cloud taskscodex cloud
# Submit a task directlycodex cloud exec --env my-env-id "Run the full integration test suite and fix any failures"
# Submit with best-of-N attemptscodex cloud exec --env my-env-id --attempts 3 "Implement the caching layer"
# List recent cloud taskscodex cloud list --json | jq '.tasks[] | {id, status, title}'
# Apply a cloud task's diff locallycodex apply TASK_IDWhen This Breaks
Section titled “When This Breaks”- Session resume shows wrong context: Sessions are scoped to the working directory by default. Use
--allto find sessions from other directories. - Shell completions not appearing: Ensure the
evalline is aftercompinitin your shell config. Restart your shell. codex exechangs: The agent may be waiting for approval. Add--full-autoor--ask-for-approval on-requestto 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.pngbefore attaching. !command blocked: The sandbox still applies to inline shell commands. If the command needs write access or network, adjust your sandbox mode.
What’s Next
Section titled “What’s Next”- Cloud Workflows — Deep dive into cloud task patterns
- App Features — Visual workflows that complement the CLI
- Advanced Techniques — Power user patterns across surfaces