ai-coding-agents

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

AI Coding Agents Skill

AI编码代理技能指南

Expert knowledge for Codex CLI and Claude Code CLI — the two leading AI coding agents.
Note: This skill documents both tools for reference. VMark development primarily uses Claude Code CLI. The Codex CLI sections are retained for completeness and cross-tool workflows.
掌握Codex CLI和Claude Code CLI这两款领先AI编码代理的专业知识。
注意: 本技能文档同时记录了这两款工具以供参考。VMark开发主要使用Claude Code CLI。保留Codex CLI部分是为了内容完整以及支持跨工具工作流。

When to Use

适用场景

  • Orchestrating complex coding tasks via CLI
  • Configuring MCP servers for either tool
  • Setting up automation pipelines (CI/CD)
  • Troubleshooting authentication or sandbox issues
  • Comparing capabilities between agents
  • Custom agent/subagent configuration
  • 通过CLI编排复杂编码任务
  • 为任意一款工具配置MCP服务器
  • 搭建自动化流水线(CI/CD)
  • 排查认证或沙箱问题
  • 对比两款代理的能力
  • 自定义代理/子代理配置

Quick Reference

快速参考

Starting Sessions

启动会话

TaskCodex CLIClaude Code CLI
Interactive session
codex
claude
With prompt
codex "fix the bug"
claude "fix the bug"
Non-interactive
codex exec "task"
claude -p "task"
Resume last
codex resume --last
claude -c
Resume by ID
codex resume <id>
claude -r <id>
任务Codex CLIClaude Code CLI
交互式会话
codex
claude
带初始提示
codex "fix the bug"
claude "fix the bug"
非交互式
codex exec "task"
claude -p "task"
恢复最近会话
codex resume --last
claude -c
通过ID恢复会话
codex resume <id>
claude -r <id>

Safety Modes

安全模式

ModeCodex CLIClaude Code CLI
Read-only
-s read-only
--permission-mode plan
Workspace write
-s workspace-write
(default)
Full access
-s danger-full-access
--dangerously-skip-permissions
Auto mode
--full-auto
--permission-mode default
YOLO mode
--yolo
--dangerously-skip-permissions
模式Codex CLIClaude Code CLI
只读
-s read-only
--permission-mode plan
工作区可写
-s workspace-write
(默认)
完全访问
-s danger-full-access
--dangerously-skip-permissions
自动模式
--full-auto
--permission-mode default
YOLO模式
--yolo
--dangerously-skip-permissions

Model Selection

模型选择

TaskCodex CLIClaude Code CLI
Select model
-m gpt-5-codex
--model opus
Use local OSS
--oss
N/A
Fallback modelN/A
--fallback-model sonnet

任务Codex CLIClaude Code CLI
选择模型
-m gpt-5-codex
--model opus
使用本地OSS模型
--oss
N/A
备用模型N/A
--fallback-model sonnet

Codex CLI (OpenAI)

Codex CLI (OpenAI)

Installation

安装

bash
npm i -g @openai/codex
bash
npm i -g @openai/codex

or

or

brew install --cask codex
undefined
brew install --cask codex
undefined

Authentication

认证

bash
codex login              # OAuth via ChatGPT
codex login --with-api-key   # Read API key from stdin
codex login status       # Check auth status
codex logout             # Remove credentials
bash
codex login              # 通过ChatGPT进行OAuth认证
codex login --with-api-key   # 从标准输入读取API密钥
codex login status       # 检查认证状态
codex logout             # 删除凭证

Core Commands

核心命令

codex
- Interactive Mode

codex
- 交互模式

bash
codex                           # 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 search
bash
codex                           # 启动终端用户界面(TUI)
codex "fix all TypeScript errors"  # 带初始提示启动
codex -i screenshot.png "explain"  # 附带图片
codex --full-auto "refactor"    # 低摩擦模式
codex --search "find docs"      # 启用网页搜索

codex exec
- Non-Interactive

codex exec
- 非交互模式

bash
codex 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 output
bash
codex exec "write tests"        # 执行任务后退出
codex e "task"                  # 短别名
echo "task" | codex exec -      # 从标准输入读取任务
codex exec --json "task"        # 输出JSONL格式
codex exec -o result.txt "task" # 将结果保存到文件
codex exec --output-schema schema.json "task"  # 验证输出格式

codex resume
- Continue Sessions

codex resume
- 恢复会话

bash
codex 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 prompt
bash
codex resume                    # 交互式选择会话
codex resume --last             # 恢复最近的会话
codex resume --all              # 显示所有会话(任意目录)
codex resume <session-id>       # 恢复指定会话
codex resume <id> "continue with this"  # 带提示恢复会话

codex review
- Code Review

codex review
- 代码评审

bash
codex 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 instructions
bash
codex review                    # 评审当前分支与main分支的差异
codex review --uncommitted      # 评审未提交的更改
codex review --base develop     # 与指定分支对比评审
codex review --commit abc123    # 评审指定提交
codex review "focus on security"  # 自定义评审指令

codex apply
- Apply Cloud Task

codex apply
- 应用云端任务

bash
codex apply <task-id>           # Apply diff from cloud task
bash
codex apply <task-id>           # 应用云端任务的差异

codex cloud
- Cloud Tasks (Experimental)

codex cloud
- 云端任务(实验性)

bash
codex 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 changes
bash
codex cloud                     # 浏览云端任务
codex cloud exec "task" --env <env-id>  # 提交任务
codex cloud status <task-id>    # 检查任务状态
codex cloud diff <task-id>      # 显示差异
codex cloud apply <task-id>     # 应用更改

codex mcp
- MCP Server Management

codex mcp
- MCP服务器管理

bash
codex 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 OAuth
bash
codex mcp list                  # 列出服务器
codex mcp list --json           # 以JSON格式输出
codex mcp get <name>            # 查看服务器详情
codex mcp add <name> -- npx my-server   # 添加标准输入输出服务器
codex mcp add <name> --url https://... # 添加HTTP服务器
codex mcp add <name> --env API_KEY=xxx -- cmd  # 附带环境变量
codex mcp remove <name>         # 删除服务器
codex mcp login <name> --scopes read,write  # 为HTTP服务器进行OAuth认证
codex mcp logout <name>         # 移除OAuth认证

codex sandbox
- Run Sandboxed Commands

codex sandbox
- 运行沙箱命令

bash
undefined
bash
undefined

macOS

macOS

codex sandbox macos -- npm test codex sandbox seatbelt --full-auto -- ./script.sh
codex sandbox macos -- npm test codex sandbox seatbelt --full-auto -- ./script.sh

Linux

Linux

codex sandbox linux -- npm test codex sandbox landlock -- ./script.sh
undefined
codex sandbox linux -- npm test codex sandbox landlock -- ./script.sh
undefined

codex completion
- Shell Completions

codex completion
- Shell补全

bash
codex completion bash >> ~/.bashrc
codex completion zsh >> ~/.zshrc
codex completion fish > ~/.config/fish/completions/codex.fish
bash
codex completion bash >> ~/.bashrc
codex completion zsh >> ~/.zshrc
codex completion fish > ~/.config/fish/completions/codex.fish

Slash Commands (Interactive)

斜杠命令(交互模式)

CommandPurpose
/model
Switch model (gpt-5-codex, gpt-5, etc.)
/approvals
Change approval policy
/compact
Summarize conversation, free context
/diff
Show git diff
/review
Analyze working tree
/status
Show config and token usage
/mcp
List available MCP tools
/mention
Attach files
/fork
Branch conversation
/resume
Reopen previous session
/new
Fresh conversation
/init
Create AGENTS.md scaffold
/feedback
Submit logs/diagnostics
/quit
,
/exit
Exit CLI
命令用途
/model
切换模型(gpt-5-codex、gpt-5等)
/approvals
更改审批策略
/compact
总结对话,释放上下文空间
/diff
显示Git差异
/review
分析工作目录
/status
显示配置和令牌使用情况
/mcp
列出可用的MCP工具
/mention
附加文件
/fork
分支对话
/resume
重新打开之前的会话
/new
开启新对话
/init
创建AGENTS.md脚手架
/feedback
提交日志/诊断信息
/quit
,
/exit
退出CLI

Configuration (
~/.codex/config.toml
)

配置文件 (
~/.codex/config.toml
)

toml
model = "gpt-5-codex"
approval_policy = "on-request"

[sandbox]
mode = "workspace-write"

[features]
web_search = true

[profiles.ci]
model = "gpt-4.1"
approval_policy = "never"
toml
model = "gpt-5-codex"
approval_policy = "on-request"

[sandbox]
mode = "workspace-write"

[features]
web_search = true

[profiles.ci]
model = "gpt-4.1"
approval_policy = "never"

Global Flags

全局标志

-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 model

-m, --model <MODEL>          选择模型
-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>     覆盖配置项
-C, --cd <DIR>               指定工作目录
-i, --image <FILE>           附加图片
-p, --profile <NAME>         使用配置文件
--full-auto                  低摩擦模式
--yolo                       绕过所有安全检查(危险)
--search                     启用网页搜索
--add-dir <DIR>              授予额外的写入权限
--enable <FEATURE>           启用功能标志
--disable <FEATURE>          禁用功能标志
--oss                        使用本地OSS模型

Claude Code CLI (Anthropic)

Claude Code CLI (Anthropic)

Installation

安装

bash
npm install -g @anthropic-ai/claude-code
bash
npm install -g @anthropic-ai/claude-code

Authentication

认证

bash
claude                      # First run prompts login
claude setup-token          # Set up long-lived token
bash
claude                      # 首次运行时提示登录
claude setup-token          # 设置长期令牌

Requires Claude Pro/Max subscription OR API key

需要Claude Pro/Max订阅或API密钥

undefined
undefined

Core Commands

核心命令

claude
- Interactive Mode

claude
- 交互模式

bash
claude                          # 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 IDE
bash
claude                          # 启动REPL环境
claude "explain this project"   # 带初始提示启动
claude -c                       # 继续上一次对话
claude -r "session-name"        # 通过名称/ID恢复会话
claude --model opus             # 选择模型
claude --chrome                 # 启用Chrome集成
claude --ide                    # 自动连接到IDE

claude -p
- Print Mode (Non-Interactive)

claude -p
- 打印模式(非交互)

bash
claude -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 schema
bash
claude -p "explain this function"   # 执行查询后退出
cat file | claude -p "explain"      # 处理管道输入
claude -p --output-format json "q"  # 输出JSON格式
claude -p --output-format stream-json "q"  # 流式JSON输出
claude -p --max-turns 3 "task"      # 限制代理交互轮次
claude -p --max-budget-usd 5 "task" # 设置支出限额
claude -p --json-schema '{...}' "q" # 验证输出JSON格式

claude mcp
- MCP Server Management

claude mcp
- MCP服务器管理

bash
claude 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 approvals
bash
claude mcp list                 # 列出服务器
claude mcp get <name>           # 查看服务器详情
claude mcp add <name> <cmd>     # 添加标准输入输出服务器
claude mcp add -t http <name> <url>  # 添加HTTP服务器
claude mcp add -e KEY=val <name> -- cmd  # 附带环境变量
claude mcp add -H "Auth: Bearer x" <name> <url>  # 附带请求头
claude mcp add -s project <name> <cmd>  # 项目范围
claude mcp remove <name>        # 删除服务器
claude mcp serve                # 作为MCP服务器运行
claude mcp add-from-claude-desktop   # 从桌面应用导入
claude mcp reset-project-choices     # 重置审批选项

claude plugin
- Plugin Management

claude plugin
- 插件管理

bash
claude 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 marketplaces
bash
claude plugin list              # 列出插件
claude plugin install <name>    # 安装插件
claude plugin install <name>@marketplace  # 从指定市场安装
claude plugin uninstall <name>  # 卸载插件
claude plugin enable <name>     # 启用已禁用的插件
claude plugin disable <name>    # 禁用插件
claude plugin update <name>     # 更新插件
claude plugin validate <path>   # 验证插件清单
claude plugin marketplace       # 管理插件市场

claude update
- Self-Update

claude update
- 自我更新

bash
claude update                   # Check and install updates
bash
claude update                   # 检查并安装更新

claude doctor
- Diagnostics

claude doctor
- 诊断

bash
claude doctor                   # Check health/issues
bash
claude doctor                   # 检查健康状态/问题

claude install
- Native Build

claude install
- 原生构建安装

bash
claude install                  # Install native build
claude install stable           # Specific version
claude install latest           # Latest version
bash
claude install                  # 安装原生构建版本
claude install stable           # 安装稳定版本
claude install latest           # 安装最新版本

Slash Commands (Interactive)

斜杠命令(交互模式)

CommandPurpose
/init
Generate CLAUDE.md
/clear
Reset context
/compact
Summarize conversation
/bug
Report issues
/doctor
Run diagnostics
/model
Switch model
/config
View/edit settings
/permissions
Manage permissions
/memory
View/edit memory
/project:<cmd>
Project-specific commands
/user:<cmd>
User-specific commands
命令用途
/init
生成CLAUDE.md文件
/clear
重置上下文
/compact
总结对话
/bug
报告问题
/doctor
运行诊断
/model
切换模型
/config
查看/编辑设置
/permissions
管理权限
/memory
查看/编辑记忆
/project:<cmd>
项目特定命令
/user:<cmd>
用户特定命令

Custom Commands

自定义命令

Create
.claude/commands/fix-issue.md
:
markdown
Fix GitHub issue #$ARGUMENTS

1. Read the issue details
2. Identify the problem
3. Implement the fix
4. Write tests
5. Create a commit
Usage:
/project:fix-issue 1234
创建
.claude/commands/fix-issue.md
:
markdown
修复GitHub问题#$ARGUMENTS

1. 阅读问题详情
2. 定位问题
3. 实现修复
4. 编写测试
5. 创建提交
使用方式:
/project:fix-issue 1234

Configuration

配置

User settings (
~/.claude/settings.json
):
json
{
  "model": "claude-sonnet-4-5-20250929",
  "verbose": false,
  "theme": "dark"
}
Project settings (
.claude/settings.json
):
json
{
  "allowedTools": ["Bash(git:*)", "Read", "Edit"],
  "disallowedTools": ["Bash(rm:*)"]
}
用户设置 (
~/.claude/settings.json
):
json
{
  "model": "claude-sonnet-4-5-20250929",
  "verbose": false,
  "theme": "dark"
}
项目设置 (
.claude/settings.json
):
json
{
  "allowedTools": ["Bash(git:*)", "Read", "Edit"],
  "disallowedTools": ["Bash(rm:*)"]
}

CLI Flags

CLI标志

Core

核心

-p, --print                 Non-interactive mode
-c, --continue              Continue last conversation
-r, --resume <ID>           Resume specific session
-v, --version               Show version
-p, --print                 非交互模式
-c, --continue              继续上一次对话
-r, --resume <ID>           恢复指定会话
-v, --version               显示版本号

Model & Config

模型与配置

--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
--model <MODEL>             模型选择:sonnet|opus|haiku或完整模型名称
--fallback-model <MODEL>    过载时使用的备用模型
--settings <FILE>           加载指定的JSON设置文件
--setting-sources <LIST>    设置来源:user,project,local
--session-id <UUID>         使用指定的会话ID

System Prompt

系统提示

--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)
--system-prompt <TEXT>      替换默认系统提示
--append-system-prompt <T>  追加到默认系统提示
--system-prompt-file <F>    使用文件内容替换默认提示(仅打印模式)
--append-system-prompt-file 使用文件内容追加到默认提示(仅打印模式)

Agent & Tools

代理与工具

--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
--agent <NAME>              指定代理
--agents <JSON>             定义自定义子代理
--tools <LIST>              限制内置工具
--allowedTools <LIST>       自动批准的工具
--disallowedTools <LIST>    从上下文中移除的工具

Permissions

权限

--permission-mode <MODE>    acceptEdits|bypassPermissions|default|delegate|dontAsk|plan
--dangerously-skip-permissions  Skip all prompts (DANGEROUS)
--allow-dangerously-skip-permissions  Enable bypass option
--permission-mode <MODE>    权限模式:acceptEdits|bypassPermissions|default|delegate|dontAsk|plan
--dangerously-skip-permissions  跳过所有权限提示(危险)
--allow-dangerously-skip-permissions  启用绕过选项

Output

输出

--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
--output-format <FMT>       输出格式:text|json|stream-json
--input-format <FMT>        输入格式:text|stream-json
--include-partial-messages  包含流式输出的片段
--verbose                   详细日志
--debug [FILTER]            调试模式,支持过滤

Advanced

高级

--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 headers
--max-turns <N>             限制代理交互轮次(仅打印模式)
--max-budget-usd <AMT>      支出限额(仅打印模式)
--json-schema <SCHEMA>      验证JSON输出
--chrome / --no-chrome      启用/禁用Chrome集成
--ide                       自动连接IDE
--fork-session              恢复会话时创建新会话
--no-session-persistence    不保存会话
--add-dir <DIRS>            额外的目录
--plugin-dir <DIRS>         加载指定目录的插件
--disable-slash-commands    禁用所有斜杠命令
--mcp-config <FILES>        MCP服务器配置文件
--strict-mcp-config         仅使用指定的MCP配置
--betas <HEADERS>           Beta API请求头

Custom Subagents

自定义子代理

bash
claude --agents '{
  "reviewer": {
    "description": "Code reviewer. Use after changes.",
    "prompt": "You are a senior code reviewer...",
    "tools": ["Read", "Grep", "Glob"],
    "model": "sonnet"
  }
}'

bash
claude --agents '{
  "reviewer": {
    "description": "Code reviewer. Use after changes.",
    "prompt": "You are a senior code reviewer...",
    "tools": ["Read", "Grep", "Glob"],
    "model": "sonnet"
  }
}'

Common Patterns & Edge Cases

常见模式与边缘情况

CI/CD Integration

CI/CD集成

Codex in GitHub Actions:
yaml
- name: Run Codex
  run: |
    echo "${{ secrets.OPENAI_API_KEY }}" | codex login --with-api-key
    codex exec --json -o result.txt "fix linting errors"
Claude in CI:
yaml
- name: Run Claude
  env:
    ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
  run: |
    claude -p --output-format json "review this PR" > review.json
GitHub Actions中使用Codex:
yaml
- name: Run Codex
  run: |
    echo "${{ secrets.OPENAI_API_KEY }}" | codex login --with-api-key
    codex exec --json -o result.txt "fix linting errors"
CI中使用Claude:
yaml
- name: Run Claude
  env:
    ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
  run: |
    claude -p --output-format json "review this PR" > review.json

Handling Rate Limits

处理速率限制

Codex: Automatic backoff built-in.
Claude: Use
--fallback-model
:
bash
claude -p --fallback-model haiku "quick task"
Codex: 内置自动退避机制。
Claude: 使用
--fallback-model
选项:
bash
claude -p --fallback-model haiku "quick task"

Working with Large Codebases

大型代码库处理

bash
undefined
bash
undefined

Codex: Use /compact to free context

Codex: 使用/compact命令释放上下文

In session: /compact

在会话中输入:/compact

Claude: Use /compact or start fresh

Claude: 使用/compact命令或开启新会话

claude --no-session-persistence -p "analyze src/"
undefined
claude --no-session-persistence -p "analyze src/"
undefined

Multi-Directory Access

多目录访问

bash
undefined
bash
undefined

Codex

Codex

codex --add-dir ../shared-lib --add-dir ../config
codex --add-dir ../shared-lib --add-dir ../config

Claude

Claude

claude --add-dir ../shared-lib ../config
undefined
claude --add-dir ../shared-lib ../config
undefined

Structured Output

结构化输出

Codex:
bash
codex exec --output-schema schema.json "generate API spec"
Claude:
bash
claude -p --json-schema '{"type":"object","properties":{"name":{"type":"string"}}}' "extract data"
Codex:
bash
codex exec --output-schema schema.json "generate API spec"
Claude:
bash
claude -p --json-schema '{"type":"object","properties":{"name":{"type":"string"}}}' "extract data"

Image Input

图片输入

Codex:
bash
codex -i screenshot.png "explain this UI"
codex -i img1.png -i img2.png "compare these"
Claude:
bash
undefined
Codex:
bash
codex -i screenshot.png "explain this UI"
codex -i img1.png -i img2.png "compare these"
Claude:
bash
undefined

Via file reference in prompt

在提示中引用文件路径

claude "analyze the image at ./screenshot.png"
undefined
claude "analyze the image at ./screenshot.png"
undefined

Session Forking

会话分支

bash
undefined
bash
undefined

Codex: /fork in session

Codex: 在会话中使用/fork命令

Claude

Claude

claude -r "session-id" --fork-session "try alternative approach"
undefined
claude -r "session-id" --fork-session "try alternative approach"
undefined

MCP Server Debugging

MCP服务器调试

Codex:
bash
codex mcp list --json | jq .
Claude:
bash
claude --debug "mcp" --mcp-config ./mcp.json

Codex:
bash
codex mcp list --json | jq .
Claude:
bash
claude --debug "mcp" --mcp-config ./mcp.json

Troubleshooting

故障排除

Authentication Issues

认证问题

ProblemCodexClaude
Not logged in
codex login status
claude doctor
Token expired
codex logout && codex login
claude setup-token
API key issuesCheck
OPENAI_API_KEY
Check
ANTHROPIC_API_KEY
问题Codex解决方案Claude解决方案
未登录
codex login status
claude doctor
令牌过期
codex logout && codex login
claude setup-token
API密钥问题检查
OPENAI_API_KEY
环境变量
检查
ANTHROPIC_API_KEY
环境变量

Sandbox Issues

沙箱问题

ProblemSolution
Permission deniedUse
--add-dir
for specific directories
Can't run commandsCheck sandbox mode, use
workspace-write
Network blockedSandbox may block network; use
danger-full-access
carefully
问题解决方案
权限被拒绝对特定目录使用
--add-dir
选项
无法运行命令检查沙箱模式,使用
workspace-write
模式
网络被阻止沙箱可能限制网络;谨慎使用
danger-full-access
模式

MCP Server Issues

MCP服务器问题

ProblemSolution
Server not foundCheck
mcp list
, verify installation
Connection failedCheck server logs, verify URL/command
Auth requiredUse
mcp login
(Codex) or add headers (Claude)
问题解决方案
服务器未找到运行
mcp list
检查,验证服务器是否已安装
连接失败检查服务器日志,验证URL/命令是否正确
需要认证使用
mcp login
(Codex)或添加请求头(Claude)

Performance Issues

性能问题

ProblemSolution
Slow responsesUse lighter model (gpt-4.1-mini / haiku)
Context overflowUse
/compact
to summarize
High costsSet
--max-budget-usd
(Claude)

问题解决方案
响应缓慢使用轻量模型(gpt-4.1-mini / haiku)
上下文溢出使用
/compact
命令总结对话
成本过高使用
--max-budget-usd
设置支出限额(Claude)

Best Practices

最佳实践

  1. Start with read-only for exploration, escalate as needed
  2. Use sessions - resume work instead of starting fresh
  3. Create AGENTS.md/CLAUDE.md for project-specific instructions
  4. Leverage MCP servers for external integrations
  5. Use structured output in CI/CD for parsing
  6. Set spending limits with
    --max-budget-usd
  7. Review diffs before applying (
    /diff
    ,
    codex cloud diff
    )
  8. Commit checkpoints before major changes
  1. 从只读模式开始 进行探索,根据需要提升权限
  2. 使用会话功能 - 恢复工作而非重新开始
  3. 创建AGENTS.md/CLAUDE.md 用于项目特定指令
  4. 利用MCP服务器 实现外部集成
  5. 在CI/CD中使用结构化输出 便于解析
  6. 使用
    --max-budget-usd
    设置支出限额
  7. 应用前先查看差异(使用
    /diff
    codex cloud diff
  8. 重大变更前提交检查点