Coding agents can use cf to work with your Cloudflare account. Commands
return JSON and describe their own inputs, so an agent can find and run the
right command without prior knowledge of cf.
-
Install
cfglobally so every agent session can run it:npm install --global cfyarn global add cfpnpm add --global cfbun add --global cfInside a project that installs
cfas a dependency, the global command runs the project's copy. -
Sign in:
cf auth loginSign-in opens a browser page where you approve access, so complete this step yourself. For agents that run without a person present, refer to Authenticate unattended agents.
-
Tell your agent to prefer
cf. Add this instruction to your user-levelAGENTS.md,CLAUDE.md, or equivalent instructions file:AGENTS.mdmd When interacting with Cloudflare, use the `cf` CLI unless the project has a Wrangler configuration file.Projects that still use
wrangler.jsoncorwrangler.tomlkeep working with Wrangler, while every other Cloudflare task goes throughcf.
You can also ask your agent to do this setup for you:
Install the Cloudflare CLI with `npm install -g cf`. Then add this line to my
user-level AGENTS.md or CLAUDE.md file: "When interacting with Cloudflare, use
the cf CLI unless the project has a Wrangler configuration file."cf has more than 2,900 commands. Instead of reading help for every product,
an agent can describe the task, inspect the best match, and then run it.
-
Search for a command by describing the task:
cf cli search "create D1 database"The search runs locally and needs no credentials. Put the task in quotes.
cf cli searchtakes the whole task as one argument, and unquoted words after the first fail as unknown commands. It returns up to five matches as a JSON array, best match first. Each match has the command and a short summary. These are the first two matches for this search:[ { "command": "cf d1 create", "summary": "Create D1 Database" }, { "command": "cf d1 update", "summary": "Update D1 Database" } ] -
Inspect the API request of the chosen command:
cf schema d1 createThe JSON result describes the API request that the command sends:
operationId,httpMethod,path,pathParams,queryParams,hasRequestBody, andrequestBodyFields. Each parameter and body field lists its name, its type, and whether it is required. Body fields also include a description.cf schemacovers generated API commands. For a command's arguments and options, or for a command such ascf deploy, run the command with--help.Path and query parameters use their API names, such as
account_id.requestBodyFieldslists the body fields that the command also accepts as options, under the option names. A field inside an object gets a combined name, such asread-replication-modeforread_replication.mode, and array fields show the typestring. For some bodies, the list is incomplete or empty. For these commands, pass the complete body with--body, and check the API reference for its shape. -
Preview the request with
--dry-run, then run the command without it:cf d1 create --name my-database --dry-run
Root and group --help output starts with a reminder for agents to use
cf cli search first. A command's own --help shows its usage as plain text.
If an agent types a command that does not exist, cf lists the closest
matches.
Results go to standard output as JSON. Messages, such as the selected zone,
and errors go to standard error. When standard output is not a terminal, it
contains only the result, so an agent can parse it or filter it with jq
without extra flags.
- Lists print a JSON array and return one page. Paging options differ
between commands, so check the command's
--helpoutput. - Changes that return no data print nothing to standard output.
- Raw content, such as an R2 object or an image from a Workers AI model, goes to standard output unchanged. Redirect it to a file.
- JSON output is indented, whether or not standard output is a terminal. Colors are added only in a terminal.
A failed command exits with a non-zero status and prints the error to standard error.
- Preview changes. Add
--dry-runto print the request as JSON without sending it. Dry runs need no credentials. - Check for aborted deletes. In a non-interactive session, a destructive
command without
--forceprintsAborted.to standard error and exits with status0. A successful exit does not mean the resource was deleted. - Review
--forcebefore you allow it. On some commands,--forceis also an API parameter. For example,cf workers delete --forcealso deletes a Worker that other Workers still reference. - Use local data where supported.
--localworks only for a few resources that local development provides, mainly KV keys, D1 databases throughcf d1 raw,cf d1 migrations list, andcf d1 migrations apply, and R2 objects. Commands without a local equivalent, includingcf d1 query, return an error instead of calling the Cloudflare API.
For local state, refer to Local resource data.
To migrate a project with an agent, ask it to:
-
Preview the migration without writing files:
cf migrate --dry-run -
Run the migration:
cf migrate -
Resolve the
TODO(@cloudflare)comments in the generatedcloudflare.config.ts, and ask you about any choice it cannot make on its own. The build fails until every required item is resolved.
For the full process, refer to Migrate a Wrangler project.
Agents that run without a person present, such as in continuous integration
(CI), cannot complete cf auth login. Set CLOUDFLARE_API_TOKEN instead. The
token takes priority over any stored login. For the variables, token
permissions, and non-interactive behavior, refer to Use cf in CI.
To give an agent separate credentials for one project on your own machine, bind a named profile to the project directory. Refer to Use named profiles.
When cf dev runs inside a supported coding agent, the development server also
prints the URL and main routes of the
Local Explorer API.
The agent can use this API to read and change the data in your Worker's local
bindings, and to query local traces and logs.
- Agent setup configures Cloudflare Skills and MCP servers for popular coding agents.
- Use cf in CI covers API tokens and non-interactive behavior.