Zero-dependency Cloudflare DNS, cutover audit, and hash-locked record change CLI (legends-cloudflare) for coding agents: audit zones and assigned nameservers, snapshot complete paginated DNS inventories, preview single-record changes with automatic orange-cloud proxy and TTL preservation, enforce SHA-256 plan locks with immediate API readback, and attach source-cited DNS migration runbooks to legends-empire.
Install or update legends-cloudflare via cto-legends (https://github.com/avalonreset/cto-legends): run `cto-legends install legends-cloudflare --apply`, then `cto-legends handoff legends-cloudflare` and follow the returned JSON recipe to verify `legends-cloudflare doctor`.
Letting an AI agent edit live Cloudflare DNS records with improvised curl calls or ad-hoc dashboard clicks is one of the fastest ways to take down production traffic or break domain email delivery:
- Silent orange-cloud proxy and custom TTL resets: In Cloudflare's API, sending a naive replacement payload without carrying forward existing metadata routinely turns off orange-cloud edge proxying, exposes origin server IPs, or resets custom TTL and MX priority values.
- Accidental destruction of sibling TXT, MX, and round-robin records: Production domains often hold multiple SPF/DKIM/ACME
TXTverification entries, multipleMXmail servers, or round-robinArecords on the same hostname. A script that filters by hostname and loops over matches can wipe out sibling records in seconds. - Blind writes over concurrent zone drift: Applying a DNS change from stale chat history without re-checking the live zone right before writing can overwrite an ACME certificate challenge or a teammate's hotfix, while assuming an HTTP response means worldwide cutover success hides broken authoritative state.
legends-cloudflare wraps the official Cloudflare DNS API in a preview-first, hash-locked change engine that pairs naturally with legends-hetzner, legends-coolify, and legends-empire. Every single-record change (A, AAAA, CNAME, TXT, MX, NS) begins as a zero-write preview that snapshots the live before-state, preserves unspecified proxy and TTL fields, and outputs a deterministic sha256 plan hash. Nothing touches Cloudflare until you explicitly pass --apply --confirm-zone <zone> --confirm-plan <sha256>.
Once cto-legends is installed, you ask your coding agent in plain english. It snapshots the zone inventory, builds a zero-write change plan with proxy and TTL preservation, waits for your confirmation, and verifies the live readback:
Before planning any domain migration or server cutover, legends-cloudflare gives your agent a bounded, read-only inspection surface:
- Fixed-origin HTTPS transport with redirect refusal (
legends_cloudflare/api.py): Every request is locked tohttps://api.cloudflare.com/client/v4/zones...withProxyHandler({})andNoRedirectenforced so bearer tokens are never forwarded across HTTP redirects or ambient proxies. Raw provider error bodies are sanitized so secrets never leak into logs. - Complete paginated inventory with duplicate & truncation guards:
zonesandrecordsiterate across all API pages (per_page=50) and fail closed iftotal_pagesmetadata is truncated, if pagination ends early, or if a concurrent zone edit causes duplicate record IDs across pages.
Every subcommand in legends-cloudflare separates read-only discovery and zero-write plan generation from confirmed single-record writes:
| Surface | legends-cloudflare Subcommands |
What It Does |
|---|---|---|
| Runtime & Resource Checks | doctor, doctor --live, resources |
Offline Python 3.11+ readiness check (doctor), live zone-list token verification (doctor --live), and packaged recipe + knowledge-pack path resolution (resources). |
| Zone & Nameserver Audit | zones, nameservers --zone <zone> |
Lists accessible zones (id, name, status, name_servers) and inspects assigned Cloudflare nameservers for registrar cutover planning. |
| Paginated DNS Inventory | records --zone <zone> [--name <name>] [--type <type>] |
Returns complete, normalized DNS record snapshots (id, type, name, content, ttl, proxied, priority, comment, tags, settings, modified_on). |
| Preview-First Record Upsert | upsert --zone <zone> --name <name> --type <type> --content <val> |
Validates IPv4/IPv6 and ASCII/punycode hostnames offline, preserves existing proxied, ttl, and priority settings when omitted, and returns a zero-write JSON plan (writes_sent: 0) with a sha256 digest. |
| Hash-Confirmed Cutover Write | upsert ... --apply --confirm-zone <zone> --confirm-plan <sha256> |
Re-fetches the live record before writing to refuse mid-cutover drift, executes a targeted PATCH or POST, and performs an immediate GET readback to verify every updated and preserved attribute. |
| Exact-ID Guarded Delete | delete --zone <zone> --name <name> --type <type> --record-id <id> |
Refuses multi-record set deletion by requiring the exact 32-character hexadecimal --record-id for both preview and --apply, then confirms via readback that the target ID is absent while sibling records remain intact. |
- Pre-change rollback snapshots (
plan.before): Everyupsertanddeleteplan embeds the fullbeforesnapshot (id,type,name,content,ttl,proxied,priority,comment,tags,settings,modified_on) alongside the proposedpayloadandsha256hash so operators have the exact pre-change state required to roll back a cutover. - Attachable
legends-empireknowledge pack (knowledge/cloudflare/pack.json): Ships with alegends.knowledge-pack/v1operational library and wiki/index.md covering least-privilege token scoping, full-zone DNS migrations, DNSSEC DS coordination, authoritative vs recursive lookup checks, and private change-receipt templates (templates/change-receipt.md).
# 1. Verify offline runtime health and packaged knowledge resources
legends-cloudflare doctor
legends-cloudflare resources
# 2. Check live token reachability, accessible zones, and assigned nameservers
legends-cloudflare doctor --live
legends-cloudflare zones
legends-cloudflare nameservers --zone example.com
legends-cloudflare records --zone example.com
# 3. Preview a single-record DNS update (zero writes sent; preserves proxy & TTL)
legends-cloudflare upsert --zone example.com --name www --type A --content 192.0.2.10
# 4. Apply the reviewed plan using its exact zone name and SHA-256 preview hash
legends-cloudflare upsert --zone example.com --name www --type A --content 192.0.2.10 \
--apply --confirm-zone example.com --confirm-plan SHA256_FROM_PREVIEW
# 5. Preview and apply an exact-ID record deletion (protects sibling TXT/MX records)
legends-cloudflare delete --zone example.com --name old --type A --record-id EXACT_32_CHAR_RECORD_ID
legends-cloudflare delete --zone example.com --name old --type A --record-id EXACT_32_CHAR_RECORD_ID \
--apply --confirm-zone example.com --confirm-plan SHA256_FROM_PREVIEWKnowledge vault, DNS migration runbooks, and legends-empire integration
Start at wiki/index.md or attach the versioned knowledge pack at knowledge/cloudflare/pack.json (legends.knowledge-pack/v1). Attach into a legends-empire vault or read it directly as plain Markdown.
- Operational runbooks: Authentication & token scoping, DNS operations & post-write checks, DNS hosting migration & DNSSEC, Troubleshooting, and the dated source ledger.
- Private operating templates: Use the Empire integration guide with templates/domain-inventory.md, templates/change-receipt.md, and templates/incident-review.md to keep private domain inventories, rollback snapshots, and cutover receipts in your own vault outside public repositories.
Agent setup (via cto-legends) and standalone installation
The module recipe is docs/AGENT-RECIPE.md. The vendored skills/cto-legends/SKILL.md is an unchanged copy of the central cto-legends router. Do not register a separate Cloudflare skill.
Run cto-legends handoff legends-cloudflare to inspect the installed recipe and readiness checks, or run cto-legends run legends-cloudflare -- doctor. For a standalone checkout:
python -m pip install .
legends-cloudflare doctor
legends-cloudflare resourcesLoad CLOUDFLARE_API_TOKEN from your secret manager into the process environment (Zone:Read and DNS:Read for inspection; DNS:Edit only for approved writes on selected zones). The CLI never auto-loads .env files or accepts tokens as command-line arguments.
Repository layout, verification, and scope boundaries
Operator / Agent
-> legends-cloudflare CLI (doctor, resources, zones, nameservers, records, upsert, delete)
-> Plan builder (before-state snapshot + proposed payload + SHA-256 digest, writes_sent=0)
-> Explicit confirmation (--apply --confirm-zone --confirm-plan) + pre-write drift re-check
-> Cloudflare DNS API PATCH/POST/DELETE + immediate GET readback verification
legends_cloudflare/: Zero-dependency Python 3.11+ CLI (cli.py), hash-locked plan builder (dns.py), fixed-origin API client (api.py), and packaged resource resolver (resources.py).wiki/andknowledge/cloudflare/: Source-cited DNS runbooks, migration checklists, and attachablelegends-empireknowledge pack.docs/: Agent recipe, Empire integration guide, release readiness, release protocol, and search strategy.
python -m unittest discover -s tests -v
python scripts/check_release.pySupported record writes: A, AAAA, CNAME, TXT, MX, and NS. This module does not transfer registrar ownership, change registrar nameservers, deploy Cloudflare Workers, manage tunnels, or run unreviewed bulk DNS imports. Exit codes: 0 completed inspection, preview, or verified change; 1 operational failure; 2 invalid CLI syntax. A failed write or readback can mean remote state changed: inspect live zone state before retrying, as no automatic retry or blind rollback occurs.
This is an independent community project built on the official Cloudflare API and is not affiliated with or endorsed by Cloudflare. See CONTRIBUTING.md, SUPPORT.md, PRIVACY.md, CODE_OF_CONDUCT.md, and SECURITY.md.
MIT License. See LICENSE, NOTICE, and THIRD_PARTY_NOTICES.md.
Paste the agent handoff block at the top of this page into your coding agent, let it wire the cto-legends router skill, and speak your task in plain English.
Running a company and not a terminal? Founders and operators who want this way of working applied directly to their own business stack have one route: message Avalon Reset at cto-legends.com/dm or start with a 48-hour diagnostic at cto-legends.com/home#home-offer. The desk is async, so the conversation starts the moment you write and nobody forces you onto a sales call.
Specification & benchmarks on cto-legends.com:
- Module specification & architecture matrix: cto-legends.com/modules/legends-cloudflare
- Related engineering dispatches: Hetzner vs DigitalOcean: The $850 Cloud Invoice Audit · How Zapier Alternatives Bill a 500-Item Webhook Loop · How to Choose MCP vs CLI Tools Without Context Bloat
- Ecosystem hub: cto-legends.com/home
