codex
它能做什么
这项技能把 OpenAI Codex CLI 作为自动化编程任务的工作程序来运行。适合希望用脚本自动完成代码改动和检查的开发者。
适用场景
- ✓当你想让编程任务在没有聊天窗口的情况下于后台运行的时候。
- ✓当你需要在脚本、CI 任务或服务器中设置 Codex 的时候。
- ✓当你想对代码库进行只读分析、且不做任何文件改动的时候。
技能链接
https://github.com/XiaomiMiMo/MiMo-Code/blob/main/packages/cli/src/skill/builtin/.bundle/codex/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请让 Codex 以只读方式审查我的代码仓库,并列出有风险的部分,不要修改任何文件。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会使用 codex exec 命令,并设置安全的沙盒选项,将任务作为提示词传入,然后返回结果。在运行任何内容之前,它会先确认该工具已安装。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Codex CLI
Use Codex CLI as a deterministic, non-interactive worker suitable for automation and agent orchestration.
Operating Rules
- Use
codex exec, not the interactivecodexTUI. - Pass the task as the positional
PROMPTargument. Do not use-pfor the prompt;-pselects a profile. - For ordinary unattended code changes, prefer:
codex exec \
-C /path/to/repo \
--sandbox workspace-write \
--ask-for-approval never \
"<TASK>"
- Use
--yoloonly inside an externally hardened and disposable runner. It disables Codex approvals and sandboxing. - For harnesses and CI, prefer
--jsonplus--output-last-message. - Do not make the run depend on a human answering questions. Resolve ambiguity using repository evidence and conservative defaults.
- Treat credentials as secrets. Inject
CODEX_API_KEYonly into the singlecodex execprocess when possible. - Before giving version-sensitive advice, inspect
codex exec --helpor current official Codex documentation if available. - On Windows, choose one execution environment per task: native PowerShell for Windows toolchains or WSL2 for Linux toolchains. Do not casually mix paths, installations, or authentication across them.
Choose the Execution Mode
Read-only analysis
Use when the task must not modify files:
codex exec \
-C /path/to/repo \
--sandbox read-only \
--ask-for-approval never \
"Analyze the repository and report risks. Do not modify files."
Workspace-scoped implementation
Use as the default for autonomous repository work:
codex exec \
-C /path/to/repo \
--sandbox workspace-write \
--ask-for-approval never \
"Implement the task, run relevant tests, and report unresolved blockers."
Externally isolated unrestricted execution
Use only when the enclosing container, VM, or sandbox enforces the real security boundary:
codex exec \
-C /workspace/repo \
--yolo \
"Implement the task and validate the result."
Never recommend --yolo on a normal developer machine or a runner containing unrelated secrets, host mounts, SSH keys, cloud credentials, or a Docker socket.
Construct an Autonomous Prompt
When headless execution could encounter choices, prepend these instructions:
Work fully autonomously.
Do not ask the user questions and do not request interactive input.
Inspect the repository and available context before making assumptions.
When several valid approaches exist, choose the option that:
1. minimizes unrelated changes,
2. preserves backward compatibility,
3. introduces the fewest new dependencies,
4. avoids destructive or irreversible actions.
Continue until the task is complete or a concrete blocking error is reached.
Record assumptions, validation performed, and unresolved blockers in the final response.
Do not simulate "always select the first option." Option ordering is not a safety or quality policy. Apply the explicit decision rules above instead.
Handle request_user_input Failures
When Codex reports that request_user_input is unavailable in Default mode or non-interactive mode:
- Confirm the invocation uses
codex execand is intentionally headless. - Add the autonomous prompt policy above.
- Supply missing decisions in the task prompt or
AGENTS.mdwhen they are known in advance. - Replace open-ended requests such as "ask me which approach" with deterministic selection criteria.
- If the choice is safety-critical, destructive, or impossible to infer, make the run fail clearly rather than selecting randomly.
- Do not attempt to emulate terminal keystrokes unless the subprocess itself, rather than Codex, requires input and the workflow explicitly defines the safe answer.
Pass Prompts and Context
Use a direct positional prompt:
codex exec "Summarize the repository structure."
Read the prompt from stdin:
codex exec - < prompt.md
Pipe dynamic context while retaining an explicit task:
npm test 2>&1 | codex exec "Analyze this test output and fix the repository."
Use --skip-git-repo-check only for intentional one-off directories outside Git:
codex exec \
--skip-git-repo-check \
-C /tmp/task \
"Analyze the files in this directory."
Produce Harness-Friendly Output
Capture only the final message
codex exec \
-C /workspace/repo \
--output-last-message /output/final.md \
"Review the codebase."
Stream JSONL ev
常见问题
运行过程中它会问我问题吗?
这项技能为无人值守运行而设计,因此会从代码仓库和安全的默认设置中解决不明确的问题。
我的 API 密钥安全吗?
这项技能要求将凭据视为机密,并只把密钥传给需要它的那一个进程。
它能在 Windows 上运行吗?
能。这项技能涵盖原生 PowerShell 和 WSL2,并要求每项任务只选择一种环境。
详情
作者的原始描述
Operate OpenAI Codex CLI in non-interactive headless environments. Load only when the user explicitly authorizes this skill or names Codex / codex. Before any command, confirm the `codex` binary is available; if missing, stop and give install or auth guidance. Covers `codex exec` automation in Bash or PowerShell, native Windows or WSL2, scripts, CI/CD, Docker, Kubernetes, remote servers, agent harnesses, sandbox and approval modes, JSONL events, session resume, and stdin prompts.
repo: XiaomiMiMo/MiMo-Code
热度
- GitHub 星标
- 14k
- 排名
- #11305
- 许可证
- MIT
- 更新时间
- 2026/11/2
评论
- …