Loading...
Loading...
Comprehensive guide for using Codex CLI (OpenAI) and Claude Code CLI (Anthropic) - AI-powered coding agents. Use when orchestrating CLI commands, automating tasks, configuring agents, or troubleshooting issues.
npx skill4agent add xiaolai/vmark ai-coding-agents| Task | Codex CLI | Claude Code CLI |
|---|---|---|
| Interactive session | | |
| With prompt | | |
| Non-interactive | | |
| Resume last | | |
| Resume by ID | | |
| Mode | Codex CLI | Claude Code CLI |
|---|---|---|
| Read-only | | |
| Workspace write | | (default) |
| Full access | | |
| Auto mode | | |
| YOLO mode | | |
| Task | Codex CLI | Claude Code CLI |
|---|---|---|
| Select model | | |
| Use local OSS | | N/A |
| Fallback model | N/A | |
npm i -g @openai/codex
# or
brew install --cask codexcodex login # OAuth via ChatGPT
codex login --with-api-key # Read API key from stdin
codex login status # Check auth status
codex logout # Remove credentialscodexcodex # Start TUI
codex "fix all TypeScript errors" # With initial prompt
codex -i screenshot.png "explain" # With image
codex --full-auto "refactor" # Low-friction mode
codex --search "find docs" # Enable web searchcodex execcodex exec "write tests" # Run and exit
codex e "task" # Short alias
echo "task" | codex exec - # From stdin
codex exec --json "task" # JSONL output
codex exec -o result.txt "task" # Save to file
codex exec --output-schema schema.json "task" # Validate outputcodex resumecodex resume # Interactive picker
codex resume --last # Most recent
codex resume --all # Show all (any directory)
codex resume <session-id> # Specific session
codex resume <id> "continue with this" # With promptcodex reviewcodex review # Review current branch vs main
codex review --uncommitted # Review uncommitted changes
codex review --base develop # Against specific branch
codex review --commit abc123 # Review specific commit
codex review "focus on security" # Custom instructionscodex applycodex apply <task-id> # Apply diff from cloud taskcodex cloudcodex cloud # Browse cloud tasks
codex cloud exec "task" --env <env-id> # Submit task
codex cloud status <task-id> # Check status
codex cloud diff <task-id> # Show diff
codex cloud apply <task-id> # Apply changescodex mcpcodex mcp list # List servers
codex mcp list --json # JSON output
codex mcp get <name> # Server details
codex mcp add <name> -- npx my-server # Add stdio server
codex mcp add <name> --url https://... # Add HTTP server
codex mcp add <name> --env API_KEY=xxx -- cmd # With env vars
codex mcp remove <name> # Remove server
codex mcp login <name> --scopes read,write # OAuth for HTTP
codex mcp logout <name> # Remove OAuthcodex sandbox# macOS
codex sandbox macos -- npm test
codex sandbox seatbelt --full-auto -- ./script.sh
# Linux
codex sandbox linux -- npm test
codex sandbox landlock -- ./script.shcodex completioncodex completion bash >> ~/.bashrc
codex completion zsh >> ~/.zshrc
codex completion fish > ~/.config/fish/completions/codex.fish| Command | Purpose |
|---|---|
| Switch model (gpt-5-codex, gpt-5, etc.) |
| Change approval policy |
| Summarize conversation, free context |
| Show git diff |
| Analyze working tree |
| Show config and token usage |
| List available MCP tools |
| Attach files |
| Branch conversation |
| Reopen previous session |
| Fresh conversation |
| Create AGENTS.md scaffold |
| Submit logs/diagnostics |
| Exit CLI |
~/.codex/config.tomlmodel = "gpt-5-codex"
approval_policy = "on-request"
[sandbox]
mode = "workspace-write"
[features]
web_search = true
[profiles.ci]
model = "gpt-4.1"
approval_policy = "never"-m, --model <MODEL> Model selection
-s, --sandbox <MODE> read-only|workspace-write|danger-full-access
-a, --ask-for-approval <P> untrusted|on-failure|on-request|never
-c, --config <KEY=VALUE> Override config
-C, --cd <DIR> Working directory
-i, --image <FILE> Attach image(s)
-p, --profile <NAME> Config profile
--full-auto Low-friction mode
--yolo Bypass all safety (DANGEROUS)
--search Enable web search
--add-dir <DIR> Grant additional write access
--enable <FEATURE> Enable feature flag
--disable <FEATURE> Disable feature flag
--oss Use local OSS modelnpm install -g @anthropic-ai/claude-codeclaude # First run prompts login
claude setup-token # Set up long-lived token
# Requires Claude Pro/Max subscription OR API keyclaudeclaude # Start REPL
claude "explain this project" # With prompt
claude -c # Continue last conversation
claude -r "session-name" # Resume by name/ID
claude --model opus # Select model
claude --chrome # Enable Chrome integration
claude --ide # Auto-connect to IDEclaude -pclaude -p "explain this function" # Query and exit
cat file | claude -p "explain" # Process piped input
claude -p --output-format json "q" # JSON output
claude -p --output-format stream-json "q" # Streaming JSON
claude -p --max-turns 3 "task" # Limit agent turns
claude -p --max-budget-usd 5 "task" # Spending limit
claude -p --json-schema '{...}' "q" # Validate output schemaclaude mcpclaude mcp list # List servers
claude mcp get <name> # Server details
claude mcp add <name> <cmd> # Add stdio server
claude mcp add -t http <name> <url> # Add HTTP server
claude mcp add -e KEY=val <name> -- cmd # With env vars
claude mcp add -H "Auth: Bearer x" <name> <url> # With headers
claude mcp add -s project <name> <cmd> # Project scope
claude mcp remove <name> # Remove server
claude mcp serve # Run as MCP server
claude mcp add-from-claude-desktop # Import from desktop app
claude mcp reset-project-choices # Reset approvalsclaude pluginclaude plugin list # List plugins
claude plugin install <name> # Install plugin
claude plugin install <name>@marketplace # From specific marketplace
claude plugin uninstall <name> # Remove plugin
claude plugin enable <name> # Enable disabled plugin
claude plugin disable <name> # Disable plugin
claude plugin update <name> # Update plugin
claude plugin validate <path> # Validate manifest
claude plugin marketplace # Manage marketplacesclaude updateclaude update # Check and install updatesclaude doctorclaude doctor # Check health/issuesclaude installclaude install # Install native build
claude install stable # Specific version
claude install latest # Latest version| Command | Purpose |
|---|---|
| Generate CLAUDE.md |
| Reset context |
| Summarize conversation |
| Report issues |
| Run diagnostics |
| Switch model |
| View/edit settings |
| Manage permissions |
| View/edit memory |
| Project-specific commands |
| User-specific commands |
.claude/commands/fix-issue.mdFix GitHub issue #$ARGUMENTS
1. Read the issue details
2. Identify the problem
3. Implement the fix
4. Write tests
5. Create a commit/project:fix-issue 1234~/.claude/settings.json{
"model": "claude-sonnet-4-5-20250929",
"verbose": false,
"theme": "dark"
}.claude/settings.json{
"allowedTools": ["Bash(git:*)", "Read", "Edit"],
"disallowedTools": ["Bash(rm:*)"]
}-p, --print Non-interactive mode
-c, --continue Continue last conversation
-r, --resume <ID> Resume specific session
-v, --version Show version--model <MODEL> sonnet|opus|haiku or full name
--fallback-model <MODEL> Fallback when overloaded
--settings <FILE> Load settings JSON
--setting-sources <LIST> user,project,local
--session-id <UUID> Use specific session ID--system-prompt <TEXT> Replace default prompt
--append-system-prompt <T> Append to default
--system-prompt-file <F> Replace with file (print only)
--append-system-prompt-file Replace with file (print only)--agent <NAME> Specify agent
--agents <JSON> Define custom subagents
--tools <LIST> Restrict built-in tools
--allowedTools <LIST> Auto-approve tools
--disallowedTools <LIST> Remove tools from context--permission-mode <MODE> acceptEdits|bypassPermissions|default|delegate|dontAsk|plan
--dangerously-skip-permissions Skip all prompts (DANGEROUS)
--allow-dangerously-skip-permissions Enable bypass option--output-format <FMT> text|json|stream-json
--input-format <FMT> text|stream-json
--include-partial-messages Include streaming chunks
--verbose Verbose logging
--debug [FILTER] Debug mode with filtering--max-turns <N> Limit agent turns (print only)
--max-budget-usd <AMT> Spending limit (print only)
--json-schema <SCHEMA> Validate JSON output
--chrome / --no-chrome Chrome integration
--ide IDE auto-connect
--fork-session Create new session on resume
--no-session-persistence Don't save session
--add-dir <DIRS> Additional directories
--plugin-dir <DIRS> Load plugins
--disable-slash-commands Disable all skills
--mcp-config <FILES> MCP server configs
--strict-mcp-config Only use specified MCP
--betas <HEADERS> Beta API headersclaude --agents '{
"reviewer": {
"description": "Code reviewer. Use after changes.",
"prompt": "You are a senior code reviewer...",
"tools": ["Read", "Grep", "Glob"],
"model": "sonnet"
}
}'- name: Run Codex
run: |
echo "${{ secrets.OPENAI_API_KEY }}" | codex login --with-api-key
codex exec --json -o result.txt "fix linting errors"- name: Run Claude
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
run: |
claude -p --output-format json "review this PR" > review.json--fallback-modelclaude -p --fallback-model haiku "quick task"# Codex: Use /compact to free context
# In session: /compact
# Claude: Use /compact or start fresh
claude --no-session-persistence -p "analyze src/"# Codex
codex --add-dir ../shared-lib --add-dir ../config
# Claude
claude --add-dir ../shared-lib ../configcodex exec --output-schema schema.json "generate API spec"claude -p --json-schema '{"type":"object","properties":{"name":{"type":"string"}}}' "extract data"codex -i screenshot.png "explain this UI"
codex -i img1.png -i img2.png "compare these"# Via file reference in prompt
claude "analyze the image at ./screenshot.png"# Codex: /fork in session
# Claude
claude -r "session-id" --fork-session "try alternative approach"codex mcp list --json | jq .claude --debug "mcp" --mcp-config ./mcp.json| Problem | Codex | Claude |
|---|---|---|
| Not logged in | | |
| Token expired | | |
| API key issues | Check | Check |
| Problem | Solution |
|---|---|
| Permission denied | Use |
| Can't run commands | Check sandbox mode, use |
| Network blocked | Sandbox may block network; use |
| Problem | Solution |
|---|---|
| Server not found | Check |
| Connection failed | Check server logs, verify URL/command |
| Auth required | Use |
| Problem | Solution |
|---|---|
| Slow responses | Use lighter model (gpt-4.1-mini / haiku) |
| Context overflow | Use |
| High costs | Set |
--max-budget-usd/diffcodex cloud diff