跳转到内容
搜索文档
All agents
Claude Code iconClaude Code icon

Claude Code + Cloudflare

Anthropic

Terminal-based coding agent that understands your codebase, runs commands, edits files, and manages git. Made by Anthropic.

TerminalStandaloneCloudExtension

快速入门

  1. 安装 Claude Code

    安装 Claude Code CLI。针对 Windows、Homebrew、WinGet 或 npm,请参阅 Claude Code 安装指南

    curl -fsSL https://claude.ai/install.sh | bash
  2. 在你的项目中启动 Claude Code

    从你项目的根目录启动 Claude Code(如果已存在,即 wrangler.jsonc 所在位置)。

    claude
  3. 安装 Cloudflare 插件

    在 Claude Code 中运行这两个斜杠命令。这将安装 Cloudflare Skills 并注册 Cloudflare MCP 服务器。

    /plugin marketplace add cloudflare/skills
    /plugin install cloudflare@cloudflare
  4. 尝试提示词

    例如:

    Connect my Worker to an existing Postgres database using Hyperdrive for connection pooling.

Cloudflare 平台访问权限

Expand any section to learn more.

Cloudflare Skills

Persistent platform context that teaches the agent how Cloudflare works.

Skills are instructions the agent loads on demand. The cloudflare/skills bundle covers every layer of the platform — so the agent knows your conventions without you re-explaining them.

  • agents-sdkBuild AI agents on Cloudflare Workers using the Agents SDK. Load when creating stateful agents, durable workflows, real-time WebSocket apps, scheduled tasks, MCP servers, chat applications, voice agents, or browser automation. Covers Agent class, state management, callable RPC, Workflows, durable execution, queues, retries, observability, and React hooks. Biases towards retrieval from Cloudflare docs over pre-trained knowledge.
  • cloudflareComprehensive Cloudflare platform skill covering Workers, Pages, storage (KV, D1, R2), AI (Workers AI, Vectorize, Agents SDK), feature flags (Flagship), networking (Tunnel, Spectrum), security (WAF, DDoS), and infrastructure-as-code (Terraform, Pulumi). Use for any Cloudflare development task. Biases towards retrieval from Cloudflare docs over pre-trained knowledge.
  • cloudflare-email-serviceSend and receive transactional emails with Cloudflare Email Service (Email Sending + Email Routing). Use when building email sending (Workers binding or REST API), email routing, Agents SDK email handling, or integrating email into any app — Workers, Node.js, Python, Go, etc. Also use for email deliverability, SPF/DKIM/DMARC, wrangler email setup, MCP email tools, or when a coding agent needs to send emails. Even for simple requests like "add email to my Worker" — this skill has critical config details.
  • cloudflare-one"Guides Cloudflare One Zero Trust and SASE work across Access, Gateway, WARP, Tunnel, Cloudflare WAN, DLP, CASB, device posture, and identity. Use when designing, configuring, troubleshooting, or reviewing Cloudflare One deployments. Retrieval-first: use current Cloudflare docs/API schemas instead of embedded product docs."
  • cloudflare-one-migrationsPlans migrations from Zscaler ZIA/ZPA, Palo Alto, legacy VPN, SWG, or SASE stacks to Cloudflare One. Use for migration assessments, policy mapping, rollout plans, and parity/gap analysis.
  • durable-objectsCreate and review Cloudflare Durable Objects. Use when building stateful coordination (chat rooms, multiplayer games, booking systems), implementing RPC methods, SQLite storage, alarms, WebSockets, or reviewing DO code for best practices. Covers Workers integration, wrangler config, and testing with Vitest. Biases towards retrieval from Cloudflare docs over pre-trained knowledge.
  • sandbox-sdkBuild sandboxed applications for secure code execution. Load when building AI code execution, code interpreters, CI/CD systems, interactive dev environments, or executing untrusted code. Covers Sandbox SDK lifecycle, commands, files, code interpreter, and preview URLs. Biases towards retrieval from Cloudflare docs over pre-trained knowledge.
  • turnstile-spinSet up Cloudflare Turnstile end-to-end in a project. Scan the codebase, create the widget via the Cloudflare API, embed it on the right forms, wire canonical server-side siteverify in the customer's existing backend, validate, and persist the skill. Load this when a user asks to add Turnstile, set up CAPTCHA, protect a form from bots, or fix a Turnstile integration. Mirrors developers.cloudflare.com/turnstile/spin.
  • web-perfAnalyzes web performance using Chrome DevTools MCP. Measures Core Web Vitals (LCP, INP, CLS) and supplementary metrics (FCP, TBT, Speed Index), identifies render-blocking resources, network dependency chains, layout shifts, caching issues, and accessibility gaps. Use when asked to audit, profile, debug, or optimize page load performance, Lighthouse scores, or site speed. Biases towards retrieval from current documentation over pre-trained knowledge.
  • workers-best-practicesReviews and authors Cloudflare Workers code against production best practices. Load when writing new Workers, reviewing Worker code, configuring wrangler.jsonc, or checking for common Workers anti-patterns (streaming, floating promises, global state, secrets, bindings, observability). Biases towards retrieval from Cloudflare docs over pre-trained knowledge.
  • wranglerCloudflare Workers CLI for deploying, developing, and managing Workers, KV, R2, D1, Vectorize, Hyperdrive, Workers AI, Containers, Queues, Workflows, Pipelines, and Secrets Store. Load before running wrangler commands to ensure correct syntax and best practices. Biases towards retrieval from Cloudflare docs over pre-trained knowledge.
MCP servers

Live access to the Cloudflare API, docs, and observability.

MCP servers provide typed tools to call into Cloudflare at runtime. There are two options: Code Mode — a single server that covers the entire Cloudflare API (2,500+ endpoints in ~1,000 tokens) — or a set of focused, domain-specific servers hosted in the cloudflare/mcp-server-cloudflare repo. The full catalog is also in the MCP servers for Cloudflare docs.

  • Code mode APIcode modeBroad access to the full Cloudflare API via code execution, with minimal token overheadhttps://mcp.cloudflare.com/mcp
  • AI Gateway serverSearch your logs, get details about the prompts and responseshttps://ai-gateway.mcp.cloudflare.com/mcp
  • Audit Logs serverQuery audit logs and generate reports for reviewhttps://auditlogs.mcp.cloudflare.com/mcp
  • Browser Run serverFetch web pages, convert them to markdown and take screenshotshttps://browser.mcp.cloudflare.com/mcp
  • Cloudflare Blog serverSearch and read posts from the Cloudflare Bloghttps://blog.mcp.cloudflare.com/mcp
  • Cloudflare One CASB serverQuickly identify any security misconfigurations for SaaS applications to safeguard users & datahttps://casb.mcp.cloudflare.com/mcp
  • Container serverSpin up a sandbox development environmenthttps://containers.mcp.cloudflare.com/mcp
  • Digital Experience Monitoring serverGet quick insight on critical applications for your organizationhttps://dex.mcp.cloudflare.com/mcp
  • DNS Analytics serverOptimize DNS performance and debug issues based on current set uphttps://dns-analytics.mcp.cloudflare.com/mcp
  • Documentation serverGet up to date reference information on Cloudflarehttps://docs.mcp.cloudflare.com/mcp
  • GraphQL serverGet analytics data using Cloudflare’s GraphQL APIhttps://graphql.mcp.cloudflare.com/mcp
  • Logpush serverGet quick summaries for Logpush job healthhttps://logs.mcp.cloudflare.com/mcp
  • Observability serverDebug and get insight into your application's logs and analyticshttps://observability.mcp.cloudflare.com/mcp
  • Workers Bindings serverBuild Workers applications with storage, AI, and compute primitiveshttps://bindings.mcp.cloudflare.com/mcp
  • Workers Builds serverGet insights and manage your Cloudflare Workers Buildshttps://builds.mcp.cloudflare.com/mcp
Wrangler CLI

Local dev, deploys, and Workers-specific commands.

Use Wrangler for local development, deploys, and product-specific commands like wrangler d1 migrations apply or wrangler tail. The bundled wrangler Skill teaches the agent when to reach for it.

Agent-friendly docs

Token-efficient references optimized for agents.

Append /index.md to any Cloudflare docs URL for a clean markdown version. Every top-level product section also has its own llms.txt — a page index sized for a single context window. A few useful ones:

For a full overview of how these docs are structured for agents, refer to the Docs for Agents guide.

示例提示词

技巧与建议

  • Skills 插件包含一个 wrangler Skill — Claude 会自动知道何时调用 npx wrangler deploywrangler d1 migrations apply 以及其他 CLI 命令。
  • 尝试 /cloudflare:build-agent 斜杠命令来脚手架出一个完整的 Agents SDK 项目,或使用 /cloudflare:build-mcp 构建远程 MCP 服务器。
  • Cloudflare API MCP 服务器使用 Code Mode — Claude 在约 1,000 个 token 内针对类型化的 API 编写 JavaScript 以访问 2,500+ 个端点中的任何一个。
  • Claude Code 在 wrangler.jsonc 所在的 Workers 项目根目录下运行效果最佳 — Agent 正是利用此文件来理解你的 binding。
  • 使用 claude mcp list 验证 Cloudflare 服务器已连接。对于 CI/CD,可以通过将 Cloudflare API token 作为 bearer token 传递来跳过 OAuth。
  • 有关安装其他 MCP 服务器的更多信息,或何时使用 Code Mode 与传统 MCP 服务器的对比,请参阅 Cloudflare MCP 服务器代码库

常见问题 (FAQ)

我是应该使用 Skills、MCP 服务器、Wrangler CLI,还是全部使用?

全部三者 — 且 Skills 插件会将它们配置在一起。Skills 赋予 Claude 持续的 Cloudflare 专业知识(何时使用 Durable Objects 与 KV, 优秀的 Workers 项目布局长什么样)。Cloudflare API MCP 服务器处理平台操作(DNS、WAF、R2 bucket、Zero Trust)。 Wrangler 运行本地开发和 Workers 特定命令。捆绑的 wrangler Skill 指导 Claude 何时调用哪一个。

如何向 Claude Code 授予我 Cloudflare 账户的访问权限?

Claude 首次调用 Cloudflare 工具时,你将被重定向到 通过 OAuth 授权并选择要授予的权限。

Claude Code 能否部署到现有的 Workers 项目?

可以。从位于 wrangler.jsonc 所在的现有项目目录运行 Claude Code,它将理解你的项目配置并进行相应部署。

Code Mode 对 MCP 意味着什么?

Code Mode 是 Cloudflare API MCP 服务器将所有 2,500+ 个 API 端点 容纳到约 1,000 个 token 中的方式。它没有将每个端点作为独立工具暴露, 而是暴露了两个 — search()execute() — 且 Claude 编写 JavaScript 来调用它们。了解关于 Code Mode 的更多信息

故障排查

MCP 服务器连接失败或超时

运行 claude mcp list 确认服务器已注册。尝试删除并 重新添加:claude mcp remove cloudflare 然后重新添加。确保你有 npxmcp-remote 可用。

Claude 无法在 Cloudflare 中完成身份验证

MCP 服务器使用 OAuth。出现提示时,在你的浏览器中完成 授权流程。对于 CI/CD,创建一个 Cloudflare API token 并作为 bearer token 传递。

获取到关于 Cloudflare 产品的过时信息

启用 Cloudflare 文档 MCP 服务器 以便 Agent 可以在运行时拉取 最新文档。如果你不想使用 MCP 服务器,可以将 Agent 直接指向 developers.cloudflare.com/llms.txt 以获取每个产品的目录, 或指向 developers.cloudflare.com/<product>/llms.txt 获取特定产品的索引。

在 Cloudflare 上构建 Agent

Also worth knowing

Cloudflare is not just a deploy target for agents, it is a full stack for building your own.

其他 Agent

这篇文档对您有帮助吗?