When to Use
User wants to use Codex as a real coding agent instead of a generic chat assistant: inspect a repo, make bounded edits, run review mode, resume work, use MCP safely, or hand work off with clear verification evidence.
Use this skill when the hard part is not "write code" but "make Codex behave safely and predictably" across CLI, exec, review, resume, MCP, app-server, cloud tasks, or local OSS-provider workflows.
Architecture
Memory lives in ~/codex/. If ~/codex/ does not exist, run setup.md. See memory-template.md for structure.
CODEBLOCK0
Quick Reference
Load only the smallest file needed for the current blocker.
| Topic | File |
|---|
| Setup guide | INLINECODE7 |
| Memory template |
memory-template.md |
| Install, login, and first-run checks |
install-and-auth.md |
| Repo execution and
codex exec workflows |
repo-execution.md |
| Approval modes and sandbox choices |
approvals-and-sandbox.md |
| MCP, app-server, cloud, and local-provider guardrails |
mcp-and-cloud.md |
| Review mode and handoff patterns |
review-and-handoffs.md |
| Recovery playbooks for auth, stuck sessions, and wrong-scope work |
troubleshooting.md |
Requirements
- -
codex binary installed and working on the target machine. - Active authentication through
codex login or an explicit OPENAI_API_KEY flow when that mode is chosen. - INLINECODE19 available when the task involves repository inspection, diff review, or commit-ready workflows.
- Explicit user approval before dangerous sandbox bypass, remote MCP usage, Codex Cloud apply, production commands, or any operation with irreversible side effects.
- Treat model names, features, and app-server behavior as live product surface: verify with
codex --help, subcommand help, or official docs instead of hardcoding stale assumptions.
Operating Coverage
This skill treats Codex as an operational coding surface, not as generic AI advice. It covers:
- - interactive Codex CLI usage with explicit working-directory and safety choices
- non-interactive
codex exec and codex review workflows - INLINECODE23 ,
fork, and handoff-friendly session recovery - sandbox and approval policy selection by blast radius
- MCP server trust decisions and local-versus-remote tool boundaries
- Codex app-server and cloud task usage only when their extra trust and review requirements are explicit
- local OSS-provider routing via
--oss and --local-provider when the user intentionally wants local execution
Data Storage
Keep only durable Codex operating context in ~/codex/:
- - which repos or workspaces are approved for Codex use
- default sandbox and approval posture per task type
- preferred execution surfaces: interactive CLI,
exec, review, cloud, or local OSS provider - approved MCP servers and what each one is allowed to touch
- recurring recovery notes for wrong directory, dirty worktree, stalled commands, or broken auth
Core Rules
1. Preflight the Task Before Codex Acts
- - Lock five facts first: target repo, current directory, dirty worktree state, required permissions, and expected verification.
- If any of those are unclear, pause and resolve them before running Codex with write capability.
- "Start coding" is never the first step in an unfamiliar repo.
2. Choose the Operating Mode Explicitly
- - Use interactive Codex for exploratory repo work,
codex exec for bounded non-interactive execution, and codex review for review-first tasks. - If resuming or branching prior work, prefer
resume or fork over re-describing the entire context from scratch. - Treat cloud, app-server, and MCP-assisted runs as separate modes with separate risk.
3. Match Sandbox and Approval to Blast Radius
- - Read-only fits inspection, planning, and low-trust exploration.
- Workspace-write fits normal local coding in the approved repo.
- Full access or dangerous bypass is a special-case mode that needs explicit user intent and an external sandbox story.
- Do not normalize high-trust modes for convenience.
4. Read the Repo Before Editing It
- - Inspect tree shape, git status, entrypoints, conventions, and test surface before proposing edits.
- When the worktree is already dirty, separate user changes from agent changes and avoid destructive cleanup.
- Codex should adapt to the repo, not force the repo into a generic workflow.
5. Keep Changes Reviewable and Scoped
- - Favor minimal diffs, targeted commands, and explicit file ownership.
- Avoid unrelated cleanup, speculative refactors, or "while here" edits unless requested.
- If a command or edit expands scope, stop and surface that expansion immediately.
6. Treat Auth, MCP, and Cloud as Trust Boundaries
- - A tool being available does not mean it is approved.
- Review each MCP server for scope, data access, and side effects before enabling it.
- Use existing login sessions when possible; never scrape secrets from local files without clear user intent.
- Inspect cloud diffs before applying them locally.
7. Verify Outcomes and Leave a Handoff Trail
- - A successful Codex run ends with checks, not with code edits alone.
- Report what changed, what was verified, what failed, and what remains risky.
- For interrupted or long-running work, leave a crisp checkpoint that another operator can resume without guesswork.
Codex Traps
- - Running Codex in the wrong directory -> edits land in the wrong repo or outside intended scope.
- Treating
workspace-write as harmless -> it still writes real files and can widen a diff quickly. - Using
--dangerously-bypass-approvals-and-sandbox for routine work -> convenience becomes unreviewable risk. - Enabling MCP servers because they are available -> hidden data reach and side effects expand silently.
- Applying cloud output without reviewing the diff -> local repo changes become opaque.
- Letting Codex work through a dirty tree without clarifying ownership -> review noise and accidental overwrite risk.
- Re-running vague prompts after interruption -> duplicated work and inconsistent verification.
External Endpoints
Only these external categories are allowed unless the user explicitly approves more:
| Endpoint | Data Sent | Purpose |
|---|
| https://api.openai.com | prompts, selected repository context, tool results, and execution metadata needed for Codex runs | Codex model execution, cloud tasks, login-linked agent work |
| https://developers.openai.com/* |
doc queries only | Verify current Codex product behavior and configuration details |
| https://{user-approved-mcp-host} | request payloads required by the specific MCP server | Optional user-approved tool access beyond the local machine |
No other data is sent externally unless the user explicitly approves additional MCP servers, Git remotes, or service endpoints.
Security & Privacy
Data that leaves your machine:
- - prompts and the repo context selected for Codex runs against OpenAI services
- optional MCP payloads only for user-approved MCP servers
- optional cloud task payloads and diffs when Codex Cloud is intentionally used
Data that stays local:
- -
~/.codex/config.toml and the user's local Codex session/config state - durable operating notes under INLINECODE37
- local diffs, verification output, and repo metadata unless the user explicitly pushes or uploads them
This skill does NOT:
- - assume dangerous bypass is acceptable by default
- enable remote MCP or cloud apply silently
- scrape tokens from arbitrary files to "help" auth succeed
- hide sandbox or approval choices from the user
- claim that CLI, app-server, cloud, and local
--oss flows have identical risk
Trust
By using this skill, Codex work may send prompts and selected repository context to OpenAI, plus any optional user-approved MCP endpoints.
Only install if you trust those services with that data.
Scope
This skill ONLY:
- - helps operate Codex safely and effectively in real coding environments
- structures repo work into explicit execution, review, and handoff modes
- keeps durable memory for approved repos, safety posture, and recurring recovery patterns
This skill NEVER:
- - treat every available Codex feature as automatically approved
- recommend destructive git cleanup as a default fix
- blur the line between local-only, cloud, and MCP-assisted execution
- modify its own skill files
Related Skills
Install with
clawhub install <slug> if user confirms:
- -
agentic-engineering - Strengthen the human workflow around parallel coding agents and blast-radius thinking. - INLINECODE41 - Improve implementation quality once Codex is operating inside the right repo boundaries.
- INLINECODE42 - Handle branches, diffs, and non-destructive repository recovery safely.
- INLINECODE43 - Reuse structured API and request-debugging patterns when Codex integrates with services.
- INLINECODE44 - Turn recurring Codex tasks into repeatable, reviewable execution paths.
Feedback
- - If useful: INLINECODE45
- Stay updated: INLINECODE46
何时使用
用户希望将 Codex 用作真正的编码代理,而非通用聊天助手:检查仓库、进行有限编辑、运行审查模式、恢复工作、安全使用 MCP,或附带清晰的验证证据移交工作。
当难点不在于编写代码,而在于让 Codex 在 CLI、exec、review、resume、MCP、应用服务器、云任务或本地 OSS 提供商工作流中安全且可预测地运行时,使用此技能。
架构
记忆存储在 ~/codex/ 中。如果 ~/codex/ 不存在,则运行 setup.md。结构参见 memory-template.md。
text
~/codex/
|-- memory.md # 持久的激活边界和运行默认值
|-- repo-profiles.md # 每个仓库的约定、测试范围和影响半径说明
|-- safety.md # 沙箱、审批和信任默认值
|-- mcp-notes.md # 已批准的 MCP 服务器、范围和拒绝原因
-- incidents.md # 卡住的会话、失败的命令和恢复模式
快速参考
仅加载解决当前阻塞问题所需的最小文件。
memory-template.md |
| 安装、登录和首次运行检查 | install-and-auth.md |
| 仓库执行和 codex exec 工作流 | repo-execution.md |
| 审批模式和沙箱选择 | approvals-and-sandbox.md |
| MCP、应用服务器、云和本地提供商护栏 | mcp-and-cloud.md |
| 审查模式和移交模式 | review-and-handoffs.md |
| 针对认证、卡住会话和错误范围工作的恢复手册 | troubleshooting.md |
要求
- - codex 二进制文件已安装并在目标机器上正常工作。
- 通过 codex login 或选择该模式时通过显式的 OPENAIAPIKEY 流程进行活跃认证。
- 当任务涉及仓库检查、差异审查或可提交工作流时,需要 git 可用。
- 在危险的沙箱绕过、远程 MCP 使用、Codex Cloud 应用、生产命令或任何具有不可逆副作用的操作之前,需要显式的用户批准。
- 将模型名称、特性和应用服务器行为视为实时产品表面:通过 codex --help、子命令帮助或官方文档验证,而不是硬编码过时的假设。
运行覆盖范围
此技能将 Codex 视为一个操作性的编码表面,而非通用的 AI 建议。它涵盖:
- - 交互式 Codex CLI 使用,带有显式的工作目录和安全选择
- 非交互式 codex exec 和 codex review 工作流
- resume、fork 和便于移交的会话恢复
- 根据影响半径选择沙箱和审批策略
- MCP 服务器信任决策以及本地与远程工具边界
- Codex 应用服务器和云任务使用,仅当它们的额外信任和审查要求明确时
- 当用户有意希望本地执行时,通过 --oss 和 --local-provider 进行本地 OSS 提供商路由
数据存储
仅在 ~/codex/ 中保存持久的 Codex 运行上下文:
- - 哪些仓库或工作区已批准供 Codex 使用
- 每种任务类型的默认沙箱和审批姿态
- 首选执行表面:交互式 CLI、exec、review、云或本地 OSS 提供商
- 已批准的 MCP 服务器以及每个服务器允许接触的内容
- 针对错误目录、脏工作树、卡住命令或认证损坏的重复恢复说明
核心规则
1. 在 Codex 行动前预先检查任务
- - 首先锁定五个事实:目标仓库、当前目录、脏工作树状态、所需权限和预期验证。
- 如果其中任何一项不清楚,在运行具有写入能力的 Codex 之前暂停并解决它们。
- 开始编码永远不是在不熟悉的仓库中的第一步。
2. 明确选择运行模式
- - 使用交互式 Codex 进行探索性仓库工作,使用 codex exec 进行有限非交互式执行,使用 codex review 进行审查优先的任务。
- 如果恢复或分支先前的工作,优先使用 resume 或 fork,而不是从头重新描述整个上下文。
- 将云、应用服务器和 MCP 辅助的运行视为具有不同风险的独立模式。
3. 将沙箱和审批与影响半径匹配
- - 只读适合检查、规划和低信任度探索。
- 工作区写入适合在已批准的仓库中进行正常的本地编码。
- 完全访问或危险绕过是一种特殊情况模式,需要明确的用户意图和外部沙箱方案。
- 不要为了方便而将高信任模式正常化。
4. 在编辑前阅读仓库
- - 在提出编辑之前,检查树形结构、git 状态、入口点、约定和测试范围。
- 当工作树已经脏时,将用户更改与代理更改分开,避免破坏性清理。
- Codex 应适应仓库,而不是将仓库强制纳入通用工作流。
5. 保持更改可审查且范围明确
- - 优先选择最小差异、针对性命令和显式文件所有权。
- 除非要求,否则避免无关的清理、推测性重构或顺带编辑。
- 如果命令或编辑扩大了范围,立即停止并呈现该扩展。
6. 将认证、MCP 和云视为信任边界
- - 工具可用并不意味着它已获批准。
- 在启用每个 MCP 服务器之前,审查其范围、数据访问和副作用。
- 尽可能使用现有登录会话;在没有明确用户意图的情况下,切勿从本地文件中抓取密钥。
- 在本地应用之前检查云差异。
7. 验证结果并留下移交痕迹
- - 成功的 Codex 运行以检查结束,而非仅以代码编辑结束。
- 报告哪些内容已更改、哪些已验证、哪些失败以及哪些仍有风险。
- 对于中断或长时间运行的工作,留下清晰的可恢复检查点,使其他操作员无需猜测即可恢复。
Codex 陷阱
- - 在错误目录中运行 Codex -> 编辑落在错误的仓库或预期范围之外。
- 将 workspace-write 视为无害 -> 它仍然写入真实文件,并可能迅速扩大差异。
- 将 --dangerously-bypass-approvals-and-sandbox 用于常规工作 -> 便利性变成不可审查的风险。
- 因为 MCP 服务器可用而启用它们 -> 隐藏的数据访问范围和副作用悄然扩大。
- 不审查差异就应用云输出 -> 本地仓库更改变得不透明。
- 让 Codex 在未明确所有权的情况下处理脏树 -> 审查噪音和意外覆盖风险。
- 中断后重新运行模糊提示 -> 重复工作和不一致的验证。
外部端点
除非用户明确批准更多,否则仅允许以下外部类别:
| 端点 | 发送的数据 | 目的 |
|---|
| https://api.openai.com | 提示词、选定的仓库上下文、工具结果以及 Codex 运行所需的执行元数据 | Codex 模型执行、云任务、与登录关联的代理工作 |
| https://developers.openai.com/* |
仅文档查询 | 验证当前 Codex 产品行为和配置详情 |
| https://{用户批准的 MCP 主机} | 特定 MCP 服务器所需的请求负载 | 超出本地机器的可选用户批准工具访问 |
除非用户明确批准额外的 MCP 服务器、Git 远程仓库或服务端点,否则不会将其他数据发送到外部。
安全与隐私
离开您机器的数据:
- - 针对 OpenAI 服务的 Codex 运行所选的提示词和仓库上下文
- 仅针对用户批准的 MCP 服务器的可选 MCP 负载
- 有意使用 Codex Cloud 时的可选云任务负载和差异
保留在本地的数据:
- - ~/.codex/config.toml 和用户的本地 Codex 会话/配置状态
- ~/codex/ 下的持久运行说明
- 本地差异、验证输出和仓库元数据,除非用户明确推送或上传它们
此技能不会:
- - 默认认为危险绕过是可接受的
- 静默启用远程 MCP 或云应用
- 从任意文件中抓取令牌以帮助认证成功
- 向用户隐藏沙箱或审批选择
- 声称 CLI、应用服务器、云和本地 --oss 流程具有相同的风险
信任
通过使用此技能,Codex 工作可能会将提示词和选定的仓库上下文发送到 OpenAI,以及任何可选用户批准的 MCP 端点。
仅当您信任这些服务处理这些数据时才安装。
范围
此技能仅:
- - 帮助在真实编码环境中安全有效地操作 Codex
- 将仓库工作结构化为明确的执行、审查和移交模式
- 为已批准的仓库、安全姿态和重复恢复模式保留持久