aliHossain Academy

“GIFT20” কুপন কোডে ২০% ডিস্কাউন্ট 🎉

Claude Code vs OpenAI Codex CLI: The Complete Command Cheatsheet

If you’ve been spending time in AI coding tools, you’ve probably noticed two names keep coming up: Claude Code from Anthropic and Codex CLI from OpenAI. Both run inside your terminal. Both can read your codebase, write code, run commands, and handle git. But the commands, shortcuts, and mental models are different enough that jumping between them is disorienting.

I went through the official documentation for both, verified every command, and built this reference from scratch. No guesswork, no recycled Twitter screenshots. Just what actually works.

Whether you’re exclusively on one tool or switching between them, this post will save you a lot of time.


What’s the Difference at a Glance?

Before we get into commands, quick context:

  • Claude Code is built with Node.js, uses CLAUDE.md for project context, and leans into a permission-based system for controlling what it can do.
  • Codex CLI is built in Rust, uses AGENTS.md for project context, and relies on OS-native sandboxing (Seatbelt on macOS, Bubblewrap on Linux) for safety.

Both support MCP servers, both have a non-interactive mode for automation, and both let you write custom commands. The fundamentals are similar. The details are not.


Claude Code: Verified Command Reference

Everything below was verified against Anthropic’s official documentation. I also cross-checked against the Claude Code source and community references.

Special Inputs and Keyboard Shortcuts

InputWhat It Does
!Bash mode. Runs a shell command directly without going through Claude’s conversational layer. Saves tokens for quick terminal tasks.
Shift + TabCycles through three modes: Normal → Auto-accept → Plan mode. The active mode shows below your prompt.
Option+T / Alt+TShortcut for extended thinking (same budget as /ultrathink).
Option+P / Alt+POpens the model picker directly.
Ctrl+GOpens your current prompt in the external editor set in $VISUAL or $EDITOR. Great for writing long prompts.

Why Shift + Tab matters more than people realize: Most people use Claude Code in Normal mode the whole time. But Plan mode (one more press of Shift+Tab after Auto-accept) puts Claude in read-only exploration before it touches anything. For unfamiliar codebases or big refactors, that’s extremely useful. Auto-accept mode is the other extreme: Claude just executes without asking. Useful for trusted automation flows.


Session Management Commands

CommandWhat It Does
/contextShows exactly what’s consuming your token budget. Important: if you hit 70%+ context window, Claude will auto-compact.
/compactCompresses conversation history into a summary while preserving context. You can add custom keep-instructions to control what gets preserved.
/clearWipes the entire conversation. Keeps CLAUDE.md and supporting files. Use this when switching to a completely unrelated task.
/rewindRolls back the conversation to a previous checkpoint. Useful when Claude goes in a direction you didn’t want.
/cost or /usageShows token usage and cost for the current session.
/tasksLists background tasks running in parallel.

/compact vs /clear is a question people always ask. Use /compact when you want Claude to remember the thread of what you were doing but need to free up token budget. Use /clear when you’re done and starting something completely fresh. Think of it like “save a summary and continue” vs “new file.”


Project and Configuration Commands

CommandWhat It Does
/initScans your project and generates a starter CLAUDE.md with project context. Run this first in any new repo.
/modelSwitches between Claude Sonnet 4.6, Opus 4.6, or Haiku 4.5.
/statuslineAdds a live dashboard to your terminal showing context %, model, and cost.
/terminal-setupConfigures multiline input mode.
/hooksConfigure event hooks, for example audio alerts when a long task completes.
/permissionsSets what Claude can do without asking for approval. Controls tool access at a granular level.
/memoryView and refine what’s stored in CLAUDE.md.
/output-styleControls response format/style. Availability depends on your plan.

/init is the most underused command. A lot of people start prompting Claude immediately without any project context. Running /init first means every session in that repo starts with Claude already understanding your stack, your patterns, and your conventions. That context reduces the back-and-forth significantly.


AI and Tool Commands

CommandWhat It Does
/ultrathinkAllocates approximately 32,000 thinking tokens for hard problems. Use this for complex multi-step architecture decisions, debugging sessions, or anything that requires deep reasoning.
/voiceNative voice-to-code input.
/reviewCode review of your current working tree changes. This is a bundled skill, not just a chat.
/mcpManage MCP (Model Context Protocol) server connections.

/ultrathink tip: This is not a magic button. It costs significantly more tokens and takes longer. Save it for problems where you’ve already tried a normal prompt and the answer wasn’t good enough. Don’t open every session with it.


OpenAI Codex CLI: Full Command Reference

Codex CLI is OpenAI’s terminal-based coding agent. Install it with:

bash

npm install -g @openai/codex

Or on macOS via Homebrew:

bash

brew install --cask codex

Keyboard Shortcuts

ShortcutWhat It Does
!Run a local shell command directly. Same behavior as Claude Code.
TabQueue a follow-up prompt or command while the agent is still working.
Ctrl+GOpens your prompt in $VISUAL or $EDITOR. Same as Claude Code.
Ctrl+RSearch prompt history from the composer. Press Enter to accept, Esc to cancel.
Ctrl+CCancel current operation. Press twice to quit.
Ctrl+LClear terminal screen.
Up / DownNavigate draft history in the composer.
Esc + EscEdit your previous message when the composer is empty.
@Fuzzy file search to attach files to the conversation.

The @ fuzzy file picker is something Claude Code doesn’t have natively. It’s a small quality-of-life thing that you start missing when you switch back.


Session Management Commands

CommandWhat It Does
/clearReset UI and conversation history.
/compactSummarize conversation to free token space.
/newStart a fresh conversation in the same session.
/resumeResume a saved previous conversation.
/forkClone the current conversation into a new thread.
/copyCopy the latest Codex output to clipboard.
/diffDisplay git diff including untracked files.
/statusShow session config and token usage. Equivalent to /cost in Claude Code.
/exit or /quitExit Codex CLI.

/fork is one of the more interesting commands. If you’re partway through a debugging session and want to explore an alternative approach without losing your current thread, /fork lets you branch off. Claude Code’s equivalent is /rewind, but they work differently. /rewind goes backward. /fork goes sideways.


Configuration Commands

CommandWhat It Does
/initGenerates an AGENTS.md scaffold with project context. Equivalent to /init in Claude Code.
/modelChoose model and reasoning effort level.
/fastToggle fast mode for GPT-5.4.
/statuslineConfigure footer status bar items.
/permissionsSet what Codex can do without asking.
/themeChoose syntax highlighting theme.
/personalitySet communication style: friendly, pragmatic, or none.
/experimentalToggle experimental features.
/debug-configPrint config layer diagnostics. Useful when something isn’t loading right.

Code and Project Tools

CommandWhat It Does
/reviewCode review of working tree changes.
/planSwitch to plan mode for read-only exploration before executing.
/mentionAttach files to the conversation.
/mcpList configured MCP tools.
/agentSwitch active agent thread.
/psShow background terminals and their output. Equivalent to /tasks in Claude Code.
/feedbackSubmit session logs to the maintainers.

CLI Subcommands (Run Outside a Session)

These run from your terminal, not from inside a Codex session:

CommandWhat It Does
codex execNon-interactive mode. Like claude -p in Claude Code. Use for automation and scripts.
codex reviewNon-interactive code review from the terminal.
codex resumeOpens a picker of recent sessions to resume.
codex applyApplies the latest diff as git apply.
codex mcpManage MCP servers from the terminal.
codex loginManage authentication (API key or browser-based).

Side-by-Side Comparison

Here’s where the two tools actually differ:

FeatureClaude CodeCodex CLI
Context viewer/context/status
Compress history/compact/compact
Wipe history/clear/clear
Plan modeShift + Tab/plan
Project config fileCLAUDE.mdAGENTS.md
Generate project file/init/init
Extended thinking/ultrathink--reasoning high/max (flag)
Background tasks/tasks/ps
Roll back session/rewind/resume + /fork
Voice input/voiceNot available natively
Non-interactive modeclaude -pcodex exec
Hooks and alerts/hooksconfig.toml only
File attachImplicit@ fuzzy picker
Sandbox securityPermission systemOS-native (Seatbelt/Bubblewrap)
Built withNode.jsRust

Where Claude Code wins

  • /ultrathink as an in-session command is significantly more accessible than setting reasoning flags at launch
  • /voice native input, which Codex doesn’t have
  • /rewind is cleaner than having to fork or resume to get back to a checkpoint
  • /context gives a clearer picture of token usage in real time

Where Codex CLI wins

  • @ fuzzy file picker is a small but genuinely useful detail
  • /fork for branching conversations is something Claude Code doesn’t have
  • /new lets you start fresh within the same session without fully exiting
  • OS-native sandboxing means the security model doesn’t rely on Claude’s judgment: the OS enforces it at the kernel level
  • Rust-based performance: startup and command execution feel noticeably faster

Setting Up Project Context (CLAUDE.md vs AGENTS.md)

Both tools have a project context file that Claude/Codex reads at the start of every session. This is one of the highest-return things you can do when onboarding either tool to a project.

For Claude Code:

bash

# Run inside your project directory
/init

This generates a CLAUDE.md file. Then open it and customize it. A solid CLAUDE.md for a WordPress project might look like:

markdown

# Project: My WordPress Plugin

## Stack
- PHP 8.2, WordPress 6.5
- Block editor (Gutenberg)
- Composer for dependencies, npm for assets

## Code conventions
- PSR-4 autoloading
- Use WordPress coding standards
- All functions prefixed with `myplugin_`

## Avoid
- Direct database queries without $wpdb
- Enqueueing scripts in admin globally

For Codex CLI:

bash

# Same idea, different file
/init

This creates AGENTS.md. Same concept. Codex reads it every session.

The more specific your context file, the less time you spend re-explaining your stack. This is especially useful if you’re working on multiple projects and switching between them often.


Hooks: Claude Code’s Underrated Feature

If you haven’t used /hooks yet, it’s worth a look.

Hooks in Claude Code let you trigger actions based on events. The most obvious use case: get an audio alert when a long task finishes. But you can also set up hooks to run linters after every file write, format code on save, or trigger a webhook when Claude commits changes.

json

{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Write(*.php)",
        "hooks": [
          {
            "type": "command",
            "command": "php-cs-fixer fix $file"
          }
        ]
      }
    ]
  }
}

This runs PHP CS Fixer every time Claude writes to a .php file. Automatic code formatting with zero effort. Codex CLI doesn’t have a direct equivalent in-session. You’d configure this in config.toml manually, which is more setup for less flexibility.


MCP Servers in Both Tools

Both Claude Code and Codex CLI support MCP (Model Context Protocol) servers. This is how you connect external tools: GitHub, Notion, databases, custom APIs, anything.

Claude Code:

bash

# Add an MCP server
claude mcp add --transport http github https://mcp.github.com

# List configured servers in-session
/mcp

Codex CLI:

bash

# Configure in ~/.codex/config.toml
[[mcp_servers]]
name = "github"
url = "https://mcp.github.com"
transport = "http"

# List configured servers in-session
/mcp

The in-session command is the same (/mcp), but setup is slightly different. Claude Code has a CLI command for adding servers. Codex leans more on manual config file editing.


Custom Commands

Both tools let you build your own slash commands.

Claude Code custom commands:

Create a .claude/commands/ directory in your project root and add markdown files. For example, a custom deploy check:

.claude/commands/deploy-check.md

markdown

Run a pre-deployment check on this project:
1. Run all tests
2. Check for any uncommitted changes
3. Verify the build passes
4. List any TODO comments added in the last commit

Then use /deploy-check in any session inside that project.

Codex CLI custom prompts:

Create a ~/.codex/ directory and add prompt files with YAML frontmatter:

markdown

---
description: Prep branch and open draft PR
argument-hint: [PR_TITLE="<title>"]
---

Create a branch named dev/<feature_name> for this work.
Commit staged changes with a clear message.
Open a draft PR. Use $PR_TITLE if supplied, otherwise write a concise summary.

Both systems are straightforward. Claude Code’s is slightly more beginner-friendly since it’s just a markdown file with no frontmatter required. Codex’s frontmatter unlocks more control (argument hints, allowed tools per command).


Practical Workflow Tips

A few things that take time to figure out on your own:

1. Always run /init on a new project before doing anything else. Both tools. The context file compounds over time as you update it. Starting without it means every session starts cold.

2. Use ! for quick tasks instead of just typing. “Check what’s in this directory” wastes tokens. ! ls -la runs it directly. Every time you use ! instead of prompting, you’re saving context budget for actual code work.

3. For Claude Code, /compact before a heavy task. If you’re midway through a session and about to ask Claude to refactor something large, run /compact first. You give it more breathing room and the compressed summary usually keeps the important context.

4. /ultrathink is not for every problem. Save it for architecture decisions, complex bugs with multiple interacting causes, or anything where a normal response has already failed you. Using it on simple tasks just burns budget.

5. In Codex, set your AGENTS.md as the first file you touch in a new project. Run /init, then immediately refine it. Don’t leave it as the auto-generated default. The more specific it is, the better your results will be from the first message.


Quick Reference Card

Claude Code

!              → bash mode
Shift+Tab      → cycle Normal / Auto-accept / Plan mode
Option+T       → extended thinking shortcut
/init          → generate CLAUDE.md
/context       → see token usage breakdown
/compact       → compress history (keeps context)
/clear         → wipe history (keeps CLAUDE.md)
/rewind        → roll back to a checkpoint
/model         → switch models
/ultrathink    → 32k thinking tokens for hard problems
/hooks         → configure event triggers
/statusline    → live token/cost dashboard
/voice         → voice input
/review        → code review current changes
/tasks         → check background tasks
/cost          → session cost

Codex CLI

!              → shell command (same as Claude Code)
@              → fuzzy file picker
Tab            → queue follow-up while agent works
Ctrl+R         → search prompt history
Ctrl+G         → open prompt in external editor
/init          → generate AGENTS.md
/status        → session config + token usage
/compact       → compress history
/clear         → reset conversation
/new           → fresh conversation, same session
/fork          → branch current conversation
/rewind        → (use /resume + /fork instead)
/model         → switch model + reasoning effort
/plan          → read-only mode before execution
/review        → code review current changes
/ps            → background terminals
/mcp           → list MCP tools
codex exec     → non-interactive mode
codex review   → non-interactive code review
codex apply    → apply diff as git apply

Which One Should You Use?

Real talk: they’re both good. The honest answer depends on what you’re already on.

If you’re using Claude in other workflows (Claude.ai, the API, Projects), Claude Code fits naturally. You get a consistent mental model across tools. The /ultrathink command, /voice, and the hooks system are genuinely ahead of what Codex CLI currently offers in-session.

If you’re already deep in the OpenAI ecosystem, Codex CLI’s Rust-based performance, the @ file picker, and the /fork conversation branching make it worth running. The OS-native sandboxing is also a real advantage if you’re working in environments where you want hard security guarantees instead of permission-based trust.

A lot of developers who work at the intersection of different stacks are running both. There’s no rule saying you can’t.

Scroll to Top