Code Mode, explained in three minutes

What Cloudflare's Code Mode is, why it shrinks an entire API into about 1,000 tokens, and how you can start using it today. Press play for the narrated version.

Cloudflare · Agents
Code Mode
async () => { /* the model writes this */ }
The problem
2,500+ endpoints, each one a tool definition
0
tokens just to describe the tools
model's context window

Classic tool calling

model → toolround trip 1
model → toolround trip 2
model → toolround trip 3
model → toolround trip 4
every result back through context…

Code Mode

// one plan, many calls (illustrative) const zones = await api.zones.list(); for (const z of zones) { rules.push(await api.dns.list(z.id)); } return summarize(rules);
code→sandbox→only the answer
Server-side Code Mode · Feb 2026
search()code that explores the API spec
execute()code that calls the endpoints
1,170,000
tokens for the whole Cloudflare API
−99.9%
Dynamic Worker isolate · V8 sandbox
execute(async () => { … })
file system env variables internet (blocked by default)
Credentials stay on the hostThe code never sees your API keys.
OAuth with scopesOnly the permissions you approve.
dns:readworkers:edit
Use it today
Connect any MCP client
# remote MCP server (OAuth, or a bearer API token)
https://mcp.cloudflare.com/mcp
# Claude Code: install Cloudflare's plugin
/plugin marketplace add cloudflare/skills
/plugin install cloudflare@cloudflare
Build your own Experimental
npm i @cloudflare/codemode agents @modelcontextprotocol/sdk zod
codeMcpServer()

Wraps an existing MCP server. Clients see one code tool.

openApiMcpServer()

For large APIs. Exposes search + execute over an OpenAPI spec.

# wrangler.toml [[worker_loaders]] binding = "LOADER" → npx wrangler deploy
Fewer tools.
Less context.
Agents that write code.
0:00 / 0:00

Chapters

Start using it today

1 · Use Cloudflare's Code Mode server

One endpoint covers 2,500+ Cloudflare API endpoints in about 1,000 tokens. Sign in with OAuth and pick the permissions, or pass an API token as a bearer token for CI.

https://mcp.cloudflare.com/mcp

In Claude Code, the Cloudflare plugin registers the servers for you:

/plugin marketplace add cloudflare/skills
/plugin install cloudflare@cloudflare

2 · Add Code Mode to your own MCP server

On Cloudflare Workers: install the SDK, add a Worker Loader binding, wrap your server with codeMcpServer() (or use openApiMcpServer() for a big OpenAPI spec), then deploy.

npm i @cloudflare/codemode agents @modelcontextprotocol/sdk zod
compatibility_flags = ["nodejs_compat"]

[[worker_loaders]]
binding = "LOADER"

Cloudflare labels Code Mode experimental, with possible breaking changes. Check the guide for the full server file.

Also: Cloudflare One MCP server portals have had Code Mode on by default since March 26, 2026; append ?codemode=search_and_execute to the portal URL.

Sources

Narration generated with ElevenLabs. The code in the third scene is illustrative.