cf-cli
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCloudflare CLI (cf
)
cfCloudflare CLI (cf
)
cfcfPrefer retrieval over pre-trained knowledge. Describe the task to , inspect the match with or , and preview with before running a command you have not verified.
cf cli searchcf schema--help--dry-runDocs index: https://developers.cloudflare.com/cf/llms.txt
cf优先检索,不要依赖预训练知识。 向 描述任务,使用 或 检查匹配项,并在运行尚未验证的命令前通过 进行预览。
cf cli searchcf schema--help--dry-runDocumentation
文档
| 主题 | 页面 |
|---|---|
| 安装、登录、凭据与账户选择 | https://developers.cloudflare.com/cf/get-started/index.md |
使用 | https://developers.cloudflare.com/cf/get-started/first-worker/index.md |
| 从终端查找、创建和删除资源 | https://developers.cloudflare.com/cf/get-started/resources/index.md |
面向 Wrangler 用户的 | https://developers.cloudflare.com/cf/wrangler/index.md |
使用 | https://developers.cloudflare.com/cf/wrangler/migrate/index.md |
Wrangler 到 | https://developers.cloudflare.com/cf/wrangler/reference/index.md |
| 开发、构建和部署;模式与预览 | https://developers.cloudflare.com/cf/projects/index.md |
类型化的 | https://developers.cloudflare.com/cf/projects/cloudflare-config/index.md |
将 | https://developers.cloudflare.com/cf/agents/index.md |
| CI、API token 与无人值守身份验证 | https://developers.cloudflare.com/cf/ci/index.md |
| 环境变量 | https://developers.cloudflare.com/cf/environment-variables/index.md |
FIRST: check installation and sign in
首先:检查安装和登录状态
bash
npm install --global cf # installs two equivalent commands: `cf` and `cloudflare`
cf --version
cf auth whoami- Requires Node.js 22.18 or later. Bun is not supported.
- If another tool named is on your
cf, usePATHinstead — the package installs both commands.cloudflare - prints a link and a one-time code, then opens the browser. On a remote machine, over SSH, or in a container, add
cf auth loginso--no-browseronly prints the link; approve it from another device. Addcfto sign in again.--force - keeps its own credentials and does not reuse a Wrangler login.
cf - Unattended agents and CI cannot complete — set
cf auth logininstead (see https://developers.cloudflare.com/cf/ci/index.md).CLOUDFLARE_API_TOKEN
To make agents prefer , add this to the user-level , , or equivalent:
cfAGENTS.mdCLAUDE.mdmd
When interacting with Cloudflare, use the `cf` CLI unless the project has a
Wrangler configuration file.bash
npm install --global cf # installs two equivalent commands: `cf` and `cloudflare`
cf --version
cf auth whoami- 需要 Node.js 22.18 或更高版本。不支持 Bun。
- 如果 中已有另一个名为
PATH的工具,请改用cf——该软件包会同时安装这两个命令。cloudflare - 会打印一个链接和一次性代码,然后打开浏览器。在远程机器、SSH 会话或容器中运行时,请添加
cf auth login,使--no-browser仅打印链接;然后在另一台设备上完成授权。添加cf可重新登录。--force - 会保存自己的凭据,不会复用 Wrangler 登录状态。
cf - 无人值守 Agent 和 CI 无法完成 ——请改用
cf auth login(参见 https://developers.cloudflare.com/cf/ci/index.md)。CLOUDFLARE_API_TOKEN
要让 Agent 优先使用 ,请将以下内容添加到用户级 、 或同类文件中:
cfAGENTS.mdCLAUDE.mdmd
When interacting with Cloudflare, use the `cf` CLI unless the project has a
Wrangler configuration file.Find commands
查找命令
bash
cf cli search "create a DNS record" # local, no credentials; quote the whole task; up to 5 JSON matches
cf schema d1 create # API request shape: method, path, params, body fields
cf <command> --help # arguments and options (e.g. cf deploy --help)cf cli searchcf schema--helpbash
cf cli search "create a DNS record" # local, no credentials; quote the whole task; up to 5 JSON matches
cf schema d1 create # API request shape: method, path, params, body fields
cf <command> --help # arguments and options (e.g. cf deploy --help)cf cli searchcf schema--helpRead output
读取输出
- Results are JSON on standard output; status messages and errors go to standard error, so piping to or redirecting needs no extra flags.
jq - Lists print one JSON array page; paging options differ per command — check .
--help - A failed command exits non-zero and prints the error to standard error.
- 结果以 JSON 形式输出到标准输出;状态消息和错误输出到标准错误,因此管道传给 或重定向输出时无需额外标志。
jq - 列表每次打印一个 JSON 数组页面;分页选项因命令而异——请查看 。
--help - 命令失败时退出码非零,并将错误输出到标准错误。
Run commands safely
安全运行命令
- Preview first. prints the request as JSON without sending it, and needs no credentials.
--dry-run - Aborted deletes still exit 0. In a non-interactive session, a destructive command without prints
--forceto standard error and exitsAborted.— a zero exit does not mean the resource was deleted.0 - Review before allowing it. On some commands
--forceis also an API parameter (for example,--forcealso deletes a Worker that other Workers reference).cf workers delete --force - is limited. It works for KV keys, D1 databases (
--local,cf d1 raw), and R2 objects; other commands (includingcf d1 migrations list|apply) return an error instead of calling the API.cf d1 query
- 先预览。 会以 JSON 形式打印请求但不予发送,并且不需要凭据。
--dry-run - 中止的删除操作仍会以 0 退出。 在非交互式会话中,破坏性命令若未带 ,会向标准错误打印
--force,并以Aborted.退出——退出码为 0 并不意味着资源已被删除。0 - 允许使用 前应先审查。 在某些命令中,
--force同时也是 API 参数(例如,--force还会删除被其他 Worker 引用的 Worker)。cf workers delete --force - 的支持范围有限。 它适用于 KV 键、D1 数据库(
--local、cf d1 raw)和 R2 对象;其他命令(包括cf d1 migrations list|apply)会返回错误,而不会调用 API。cf d1 query
Choose the CLI for this project
为项目选择 CLI
- exists: use
cloudflare.config.ts.cf - ,
wrangler.jsonc, orwrangler.jsonexists, and nowrangler.toml: keep Wrangler forcloudflare.config.ts,dev, andbuild. Do not rundeploy,cf dev, orcf buildthere — they can generate a new configuration that ignores the Wrangler file, or fail.cf deployresource commands (DNS, zones, storage) are fine alongside it. Runcfonly when the user asks, and follow Migrate a Wrangler project: preview withcf migrate, runcf migrate --dry-run, then resolve thecf migratecomments in the generatedTODO(@cloudflare).cloudflare.config.ts - Neither exists: use , as Use cf with coding agents recommends. Do not install Wrangler or create a Wrangler configuration file.
cf
For Wrangler equivalents, use the Wrangler to cf reference or . Do not translate Wrangler commands from memory. For the full comparison, refer to for Wrangler users.
cf cli searchcf- 存在 :使用
cloudflare.config.ts。cf - 存在 、
wrangler.jsonc或wrangler.json,但不存在wrangler.toml:继续使用 Wrangler 执行cloudflare.config.ts、dev和build。不要在该项目中运行deploy、cf dev或cf build——这些命令可能生成忽略 Wrangler 配置文件的新配置,或者直接失败。可以同时使用cf deploy资源命令(DNS、zones、storage)。仅当用户提出要求时运行cf,并遵循迁移 Wrangler 项目中的说明:先使用cf migrate预览,再运行cf migrate --dry-run,最后处理生成的cf migrate中的cloudflare.config.ts注释。TODO(@cloudflare) - 两者都不存在:使用 ,正如将
cf与编程 Agent 配合使用所建议的那样。不要安装 Wrangler 或创建 Wrangler 配置文件。cf
如需查找 Wrangler 的等价命令,请使用 Wrangler 到 参考或 。不要凭记忆转换 Wrangler 命令。有关完整比较,请参阅面向 Wrangler 用户的 。
cfcf cli searchcfCommands cf
does not support yet
cfcf
尚不支持的命令
cfcfnpx wranglercloudflare.config.ts- Live logs: .
npx wrangler tail <WORKER_NAME> - A single secret: . Or upload secrets with a new Worker version by passing
npx wrangler secret put <SECRET_NAME> --name <WORKER_NAME>to--secrets-file <PATH>orcf deploy.cf workers versions create
For the current list, refer to "Commands not yet supported" in the Wrangler to cf reference.
cfnpx wranglercloudflare.config.ts- 实时日志:。
npx wrangler tail <WORKER_NAME> - 单个 secret:。也可以通过向
npx wrangler secret put <SECRET_NAME> --name <WORKER_NAME>或cf deploy传入cf workers versions create,使用新的 Worker 版本上传 secrets。--secrets-file <PATH>
有关当前列表,请参阅 Wrangler 到 参考中的“尚未支持的命令”。
cf