Openclaw Codex CLI
Overview
Use this skill to give short, practical instructions for codex-cli in Openclaw contexts. Keep answers concise and command-focused. For Openclaw integrations, prefer codex exec because Openclaw should call Codex non-interactively rather than trying to type into the interactive TUI.
Core Commands
Use these as the default examples:
CODEBLOCK0
Mention codex "<prompt>" only when the user explicitly wants a human-driven interactive session.
Install and Update
When asked about installation or update:
- - Install with
npm install -g @openai/codex. - Check the version with
codex --version. - Update with the same package manager used for installation.
- If
codex is not found, tell the user to check PATH and restart the terminal.
Login
When asked about login:
- - Use
codex login for the standard login flow. - Use
codex login --device-auth when device authentication is preferred. - If needed, API key auth can be used with
OPENAI_API_KEY. - The user must complete the sign-in flow.
- If login succeeds and
codex works normally, the user does not need to log in again on every launch. - Log in again only if the session expires, credentials are cleared, or the CLI asks for authentication.
Examples:
CODEBLOCK1
CODEBLOCK2
CODEBLOCK3
CODEBLOCK4
Authentication Errors
If codex exec returns 401 unauthorized or 500 internal server error, tell the user to reset authentication and log in again.
Use this recovery flow:
CODEBLOCK5
After login, run the codex exec command again.
Openclaw Integration Style
Use this distinction clearly:
- - Preferred for Openclaw integration: INLINECODE15
- Interactive only when a human wants to work directly in the Codex UI: INLINECODE16
For Openclaw, prefer codex exec because the default Codex CLI interface is interactive and not ideal for another tool to control by typing into the chat window.
Use codex exec when Openclaw needs to send a task programmatically as a one-off run.
Workspace Folder
Recommend creating a dedicated workspace folder for each Openclaw task or project.
Use this guidance:
- - Run Codex inside a dedicated workspace directory.
- Keep project files, generated files, and temporary outputs inside that workspace.
- Prefer
workspace-write style execution in that workspace. - If the workspace is not a git repository, add
--skip-git-repo-check. - Use
--cd to point Codex at the intended working directory. - Use
--add-dir when Openclaw must allow writes in additional directories.
This makes file scope clearer and reduces the risk of changing unrelated files.
Examples:
CODEBLOCK6
CODEBLOCK7
Git Repository Check
If the target directory is not a git repository, mention --skip-git-repo-check.
Use this when Openclaw needs to run Codex in a folder that does not contain a .git directory.
Example:
CODEBLOCK8
Trust and Approvals
Explain these briefly:
- -
Trust this folder: use for a known safe Openclaw workspace. - INLINECODE26 : use when the user wants one-time approval.
- INLINECODE27 : use only for safe, repeatable command patterns.
Preferred guidance:
- - Trust only known folders.
- Prefer
Allow once when unsure. - Use
Always allow carefully.
Approval and Sandbox Options
Mention these options when the user asks how Codex should run commands:
- -
-a, --ask-for-approval: controls when Codex asks for approval before running commands. - INLINECODE31 : controls how restricted command execution is.
- INLINECODE32 : convenience mode for lower-friction automatic execution.
- INLINECODE33 : skips the git repository check when the folder is not tracked by git.
Use this practical guidance:
- - For Openclaw, prefer safer settings first.
- Use
-a on-request when approvals should be requested as needed. - Use
-a never only when the environment is already controlled and non-interactive execution is intended. - Use
-s workspace-write as the normal default when Codex needs to edit files in the workspace. - INLINECODE37 is a shortcut for a lower-friction setup and is useful when the user wants more automation with workspace-limited writes.
- Add
--skip-git-repo-check when the working folder is not a git repository. - Avoid
--dangerously-bypass-approvals-and-sandbox. - Avoid
--sandbox danger-full-access unless the user explicitly wants that risk.
Examples:
CODEBLOCK9
CODEBLOCK10
CODEBLOCK11
Useful Exec Options
Mention these when relevant:
- -
--json: use when Openclaw needs machine-readable output. - INLINECODE42 : attach image inputs for UI or design tasks.
- INLINECODE43 : override the model when the user specifies one.
- INLINECODE44 : enable web search when current information is needed.
Examples:
CODEBLOCK12
CODEBLOCK13
CODEBLOCK14
Prompt Examples
Use short examples like these:
CODEBLOCK15
CODEBLOCK16
CODEBLOCK17
CODEBLOCK18
CODEBLOCK19
If the user explicitly wants an interactive chat, use:
CODEBLOCK20
Prompting Rule
Prefer prompts that include:
- - The exact outcome
- The target file or component when known
- Important constraints
- Optional verification requests
Openclaw Codex CLI
概述
使用此技能在Openclaw环境中为codex-cli提供简短实用的指令。回答应简洁且以命令为核心。对于Openclaw集成,优先使用codex exec,因为Openclaw应以非交互方式调用Codex,而非尝试在交互式TUI中输入。
核心命令
使用以下命令作为默认示例:
bash
npm install -g @openai/codex
codex --version
codex login
codex login --device-auth
codex exec <提示>
仅当用户明确需要人工驱动的交互式会话时,才提及codex <提示>。
安装与更新
当被问及安装或更新时:
- - 使用npm install -g @openai/codex进行安装。
- 使用codex --version检查版本。
- 使用与安装时相同的包管理器进行更新。
- 如果找不到codex,请告知用户检查PATH并重启终端。
登录
当被问及登录时:
- - 使用codex login进行标准登录流程。
- 当首选设备认证时,使用codex login --device-auth。
- 如有需要,可使用OPENAIAPIKEY进行API密钥认证。
- 用户必须完成登录流程。
- 如果登录成功且codex正常运行,用户无需每次启动时重新登录。
- 仅在会话过期、凭据被清除或CLI要求认证时重新登录。
示例:
bash
codex login
bash
codex login --device-auth
bash
printenv OPENAIAPIKEY | codex login --with-api-key
bash
codex login status
认证错误
如果codex exec返回401 unauthorized或500 internal server error,请告知用户重置认证并重新登录。
使用以下恢复流程:
bash
codex logout
codex login --device-auth
登录后,重新运行codex exec命令。
Openclaw集成风格
明确区分以下用法:
- - Openclaw集成首选:codex exec <提示>
- 仅当用户希望直接在Codex UI中工作时使用交互模式:codex <提示>
对于Openclaw,优先使用codex exec,因为默认的Codex CLI界面是交互式的,不适合其他工具通过聊天窗口输入来控制。
当Openclaw需要以一次性运行的方式以编程方式发送任务时,使用codex exec。
工作区文件夹
建议为每个Openclaw任务或项目创建一个专用工作区文件夹。
使用以下指导:
- - 在专用工作区目录内运行Codex。
- 将项目文件、生成的文件和临时输出保留在该工作区内。
- 优先在该工作区内使用workspace-write风格的执行。
- 如果工作区不是git仓库,添加--skip-git-repo-check。
- 使用--cd将Codex指向目标工作目录。
- 当Openclaw必须允许在其他目录中写入时,使用--add-dir。
这使文件范围更清晰,并降低修改无关文件的风险。
示例:
bash
codex exec --cd /path/to/workspace <提示>
bash
codex exec --cd /path/to/app --add-dir /path/to/shared <提示>
Git仓库检查
如果目标目录不是git仓库,提及--skip-git-repo-check。
当Openclaw需要在不包含.git目录的文件夹中运行Codex时使用此选项。
示例:
bash
codex exec --skip-git-repo-check <提示>
信任与审批
简要说明以下内容:
- - 信任此文件夹:用于已知安全的Openclaw工作区。
- 允许一次:当用户希望一次性审批时使用。
- 始终允许:仅用于安全、可重复的命令模式。
首选指导:
- - 仅信任已知文件夹。
- 不确定时优先选择允许一次。
- 谨慎使用始终允许。
审批与沙箱选项
当用户询问Codex应如何运行命令时,提及以下选项:
- - -a, --ask-for-approval:控制Codex在运行命令前何时请求审批。
- -s, --sandbox:控制命令执行的限制程度。
- --full-auto:用于降低摩擦的自动执行便捷模式。
- --skip-git-repo-check:当文件夹不受git跟踪时跳过git仓库检查。
使用以下实用指导:
- - 对于Openclaw,优先使用更安全的设置。
- 当需要按需请求审批时,使用-a on-request。
- 仅当环境已受控且需要非交互式执行时,使用-a never。
- 当Codex需要编辑工作区中的文件时,使用-s workspace-write作为正常默认值。
- --full-auto是降低摩擦设置的快捷方式,当用户希望在工作区受限写入的情况下实现更多自动化时很有用。
- 当工作文件夹不是git仓库时,添加--skip-git-repo-check。
- 避免使用--dangerously-bypass-approvals-and-sandbox。
- 除非用户明确希望承担该风险,否则避免使用--sandbox danger-full-access。
示例:
bash
codex exec -a on-request -s workspace-write <提示>
bash
codex exec --full-auto <提示>
bash
codex exec --skip-git-repo-check <提示>
有用的Exec选项
在相关时提及以下选项:
- - --json:当Openclaw需要机器可读的输出时使用。
- -i, --image:为UI或设计任务附加图像输入。
- -m, --model:当用户指定模型时覆盖模型。
- --search:当需要当前信息时启用网络搜索。
示例:
bash
codex exec --json <提示>
bash
codex exec -i screenshot.png 匹配此UI设计。
bash
codex exec -m gpt-5.4 <提示>
提示示例
使用以下简短示例:
bash
codex exec 为本地开发添加README部分。
bash
codex exec 在Openclaw客户端中实现带有指数退避的登录重试功能。
bash
codex exec 编写一个Python脚本,读取CSV文件并按类别输出JSON摘要。
bash
codex exec 修改文件上传端点,拒绝大于10 MB的文件,并为其添加测试。
bash
codex exec --json 列出此工作区中的所有API端点。
如果用户明确希望进行交互式聊天,使用:
bash
codex <提示>
提示规则
优先使用包含以下内容的提示:
- - 确切的结果
- 已知的目标文件或组件
- 重要的约束条件
- 可选的验证请求