场景 053 · Codex Use Case

创建 Codex 易用的 CLI

构建可从任意目录运行、与仓库脚本组合、下载文件,并通过配套技能记住用法的 CLI。

EngineeringCode
Create a CLI Codex can useEngineeringCode

原文核对:2026-10-13 · 中文正文 · 英文提示词与演示

场景定位

构建可从任意目录运行、与仓库脚本组合、下载文件,并通过配套技能记住用法的 CLI。

难度
中级
时间跨度
1 小时

适合用于

  • 反复搜索、读取、下载或安全写入同一服务、导出、归档或脚本。
  • 需要分页搜索、按 ID 读取、稳定 JSON、文件下载、本地索引或先草稿后写入的工具。

相关工具

Cli Creator

设计命令、构建 CLI、检查设置认证、安装到 PATH 并跨目录验证。

Cli Creator ↗
Skill Creator

创建配套技能,记录首选命令和写入审批边界。

Skill Creator ↗

起步提示词

英文原文 · 可复制后按实际材料修改

Use $cli-creator to create a CLI you can use, and use $skill-creator to create the companion skill in this same chat.

Source to learn from: [docs URL, OpenAPI spec, redacted curl command, existing script path, log folder, CSV or JSON export, SQLite database path, or pasted --help output].

First job the CLI should support: [download failed CI logs from a build URL, search support tickets and read one by ID, query an admin API, read a local database, or run one step from an existing script].

Optional write job: [create a draft comment, upload media, retry a failed job, or read-only for now].

Command name: [cli-name, or recommend one].

Before coding, show me the proposed command surface and ask only for missing details that would block the build.

简介

反复使用同一 API、日志、邮箱导出、数据库或团队脚本时,提供可从任意目录执行、缩小范围并与 git、gh、rg、测试组合的命令接口。

配套技能记录何时使用、先运行什么、如何限制输出、下载位置及需批准的写操作。

$cli-creator 构建命令,$skill-creator 保存 $ci-logs 等可按名调用的技能。

使用步骤

  1. 判断是否需要 CLI。
  2. 提供可学习的来源。
  3. 运行 $cli-creator。
  4. 测试安装后的命令。
  5. 以后调用保存的技能。

明确 CLI 的任务

从要完成的任务出发,将重复读取、搜索、下载、导出、起草、上传、轮询或安全写入变成跨仓库命令。

情况CLI 行为
CI 日志藏在构建页接收 URL,下载失败日志到 ./logs,返回路径和短片段。
客服工单每周导出索引最新 CSV/JSON,按客户或词语搜索,按稳定 ID 读取。
API 响应过大仅列所需字段,按 ID 读取完整对象,将全量响应导出文件。
Slack 导出会话很长用 --limit 搜索,读取单个会话和邻近背景。
团队脚本包含多个步骤将设置、发现、下载、起草、上传、轮询和正式写入拆开。
插件找到记录但需要文件保留插件,用 CLI 下载附件、trace、报告、视频或日志包并返回路径。

提供文档、文件或命令

提供文档/OpenAPI、脱敏 curl、导出或数据库路径、日志目录或已有脚本。希望沿用风格时,附上 gh、kubectl 或团队工具的简短 --help。

认证只说明环境变量名、配置路径或登录流程;自行设置密钥,不粘贴到聊天中。缺少认证时,设置检查应清楚失败。

构建 CLI 和技能

填写起步提示词中的来源和首个任务。

编码前展示命令设计,只追问真正阻碍构建的缺失信息。

验证跨目录可用

不应停在 cargo run、python 路径或未安装命令;在其他仓库或临时目录测试已安装命令,模拟后续真实使用。

按后续代理的方式测试

官方提示词

英文原文 · 可复制后按实际材料修改

Test [cli-name] the way you would use it in a future task.

Please show proof that:

- command -v [cli-name] succeeds from outside the CLI source folder
- [cli-name] --help explains the main commands
- the setup/auth check runs
- one safe discovery, list, or search command works
- one exact read command works with an ID from the discovery result
- any large log, export, trace, or payload writes to a file and returns the path
- live write commands are not run unless I explicitly approved them

Then read the companion skill and tell me the shortest prompt I should use when I need this CLI again.

输出巨大 JSON 时缩小默认响应、增加全量文件导出;遗漏审批边界时先更新配套技能。

以后使用技能

再次需要 CLI 时调用技能,无需重复粘贴文档:

官方提示词

英文原文 · 可复制后按实际材料修改

Use $ci-logs to download the failed logs for this build URL and tell me the first failing step.

官方提示词

英文原文 · 可复制后按实际材料修改

Use $support-export to search this week's refund complaints and read the three highest-value tickets.

官方提示词

英文原文 · 可复制后按实际材料修改

Use $admin-api to find this user's workspace, read the billing record, and draft a safe account note.

周期工作先在对话中验证技能,再从同一对话安排定时调用。

展开英文原文对照

Ask Codex to create a composable CLI it can run from any folder, combine with repo scripts, use to download files, and remember through a companion skill.

Introduction

When Codex keeps using the same API, log source, exported inbox, local database, or team script, give that work a composable interface: a command it can run from any folder, inspect, narrow, and combine with git, gh, rg, tests, and repo scripts.

Add a companion skill that records when Codex should use the CLI, what to run first, how to keep output small, where downloaded files land, and which write commands need approval.

In this workflow, $cli-creator helps Codex build the command. $skill-creator helps Codex save a reusable skill such as $ci-logs, which future tasks can invoke by name.

How to use

  1. Decide whether the job needs a CLI
  2. Share the source Codex should learn from
  3. Run $cli-creator
  4. Test the installed command
  5. Invoke the saved skill later

Choose what the CLI should do

Start with the thing you want Codex to do, not the technology you want it to write. A good CLI turns a repeated read, search, download, export, draft, upload, poll, or safe write into a command Codex can run from any repo.

SituationWhat Codex can do with the CLI
CI logs live behind a build page.Take a build URL, download failed job logs to ./logs, and return file paths plus short snippets.
Support tickets arrive as a weekly export.Index the newest CSV or JSON export, search by customer or phrase, and read one ticket by stable ID.
An API response is too large for context.List only the fields it needs, read the full object by ID, and export the complete response to a file.
A Slack export has long threads.Search with --limit, read one thread, and return nearby context instead of the whole archive.
A team script runs four different steps.Split setup, discovery, download, draft, upload, poll, and live write into separate commands.
A plugin finds the record, but Codex needs a file.Keep the plugin in the chat; use a CLI to download the attachment, trace, report, video, or log bundle and return the path.

Share the docs, files, or commands

Codex needs something concrete to learn from: docs or OpenAPI, a redacted curl command, an export or database path, a log folder, or an existing script. If you want the CLI to follow a familiar style, paste a short --help output from gh, kubectl, or your team’s own tool.

If the command needs auth, tell Codex the environment variable name, config file path, or login flow it should support. Set the secret yourself in your shell or config file. Do not paste secrets into the chat. Ask Codex to make the CLI’s setup check fail clearly when auth is missing.

Ask Codex to build the CLI and skill

Use the starter prompt on this page. Fill in the source Codex should learn from and the first job the CLI should support.

Before Codex writes code, it should show the proposed command surface and ask only for missing details that would block the build.

Verify the command works from any folder

Codex should not stop after cargo run, python path/to/script.py, or an uninstalled package command. Ask it to test the installed command from another repo or a temporary folder, the way a later task will use it.

Test the CLI like a future agent

官方提示词

英文原文 · 可复制后按实际材料修改

Test [cli-name] the way you would use it in a future task.

Please show proof that:

- command -v [cli-name] succeeds from outside the CLI source folder
- [cli-name] --help explains the main commands
- the setup/auth check runs
- one safe discovery, list, or search command works
- one exact read command works with an ID from the discovery result
- any large log, export, trace, or payload writes to a file and returns the path
- live write commands are not run unless I explicitly approved them

Then read the companion skill and tell me the shortest prompt I should use when I need this CLI again.

If Codex returns a giant JSON blob, ask it to narrow the default response and add a file export for full payloads. If it forgets the approval boundary, ask it to update the companion skill before you use it in another task.

Use the skill later

When you need the CLI again, invoke the skill instead of pasting the docs again:

官方提示词

英文原文 · 可复制后按实际材料修改

Use $ci-logs to download the failed logs for this build URL and tell me the first failing step.

官方提示词

英文原文 · 可复制后按实际材料修改

Use $support-export to search this week's refund complaints and read the three highest-value tickets.

官方提示词

英文原文 · 可复制后按实际材料修改

Use $admin-api to find this user's workspace, read the billing record, and draft a safe account note.

For recurring work, test the skill once in a chat, then ask Codex to schedule a task for that same invocation from the chat.