The Complete Production SOP: How to Deploy and Run Cloudflare Cache Rules & Edge TTL Optimization in Autonomous AI Agents
Step-by-step SOP to install and run Cloudflare Cache Rules & Edge TTL Optimization in Codex, Claude Code, and Cursor. Includes verified prompts and fixes.
Technical Overview & Architectural Context
Autonomous coding agents frequently make critical architecture mistakes when configuring edge caching on Cloudflare. They often hallucinate deprecated Page Rules instead of modern Cache Rules, misconfigure browser TTL versus edge TTL (leading to stale client assets that cannot be invalidated), or fail to configure origin response headers like Cache-Tag for precise, granular cache purging. These mistakes lead to catastrophic stale content delivery or unintended dynamic data caching across tenant boundaries. The cloudflare-page-rules-edge-cache skill enforces deterministic SOP boundaries for Codex, Claude Code, Cursor, and Windsurf. By constraining the agent to modern Cloudflare Ruleset Engine syntax, explicit Cache-Tag propagation in origin application frameworks, and automated API-based cache invalidation workflows, this skill guarantees that edge configurations stay performant, isolated, and strictly cache-compliant.
Prerequisites & Environment Requirements
Verified Search Intents & Long-Tail Queries Solved
This operational tutorial is engineered to provide deterministic solutions for these developer search queries:
Step-by-Step Execution Playbook
Local Environment Setup & SKILL.md Mounting
Create the local skill manifest directory and inject verified procedural rules into the agent runtime.
Agent runtimes such as Claude Code, Cursor, and Codex automatically scan directory locations like `.agents/skills` or `.claude/skills` for frontmatter trigger terms. Placing the SKILL.md file in the project workspace enables context-aware hot-reloading without restarting your editor or CLI session.
mkdir -p .agents/skills/cloudflare-page-rules-edge-cache && cat << 'EOF' > .agents/skills/cloudflare-page-rules-edge-cache/SKILL.md
---
name: "cloudflare-page-rules-edge-cache"
description: "Accelerate static and dynamic content delivery using Cloudflare Cache Rules and Cache-Tags."
metadata:
author: "Cloudflare"
version: "1.0.0"
runtime_compatibility:
- "codex"
- "claude-code"
- "cursor"
- "windsurf"
triggers:
- "configure cloudflare cache rules"
- "purge cloudflare cache by tag"
- "edge ttl cloudflare"
permissions:
fs_read: true
fs_write: "workspace"
shell_exec: false
net_access: false
---
# Cloudflare Cache Rules & Edge TTL Optimization
Configures Cloudflare Cache Rules: defining cache eligibility by path/file extension, setting Edge Cache TTL and Browser TTL, bypassing cache on dynamic cookies, and purging cache by Cache-Tag via API.
## When to Invoke
Invoke this skill whenever you need to:
- configure cloudflare cache rules
- purge cloudflare cache by tag
- edge ttl cloudflare
## Execution SOP & Rules
1. Navigate to Caching -> Cache Rules and create targeted rules matching URL path expressions.
2. Set Cache Eligibility: Eligible for cache, with Edge TTL: Override origin (e.g. 7 days).
3. Emit 'Cache-Tag: product-123' headers in origin application HTTP responses.
4. Purge targeted tags via API: POST /zones/{zone_id}/purge_cache with JSON: { tags: ['product-123'] }.
## Verification Checklist
- Run local linting, syntax validation, and type-checks before reporting completion.
- Ensure all created or modified files adhere to workspace boundaries and avoid uncommitted secrets.
- Verify tests or build commands exit cleanly with return code 0.
EOF---
name: "cloudflare-page-rules-edge-cache"
description: "Accelerate static and dynamic content delivery using Cloudflare Cache Rules and Cache-Tags."
metadata:
author: "Cloudflare"
version: "1.0.0"
runtime_compatibility:
- "codex"
- "claude-code"
- "cursor"
- "windsurf"
triggers:
- "configure cloudflare cache rules"
- "purge cloudflare cache by tag"
- "edge ttl cloudflare"
permissions:
fs_read: true
fs_write: "workspace"
shell_exec: false
net_access: false
---Setting `shell_exec: false` and `net_access: false` forces the agent to output deterministic infrastructure-as-code or purge scripts rather than making uncontrolled network calls.
Ensure the directory name exactly matches the skill slug `cloudflare-page-rules-edge-cache` so runtime indexers correctly map triggers to the manifest.
Environment Secrets & Dependency Validation
Inject Cloudflare credentials securely using standard environment variable references.
Autonomous agents should never see unmasked API tokens in their prompt history or write them into raw code files. Configure a `.env.template` file with parameter placeholders and reference them via standard process environment variables in Node.js or Python purge utilities.
cat << 'EOF' > .env.template
CLOUDFLARE_ZONE_ID="your_zone_id_here"
CLOUDFLARE_API_TOKEN="your_scoped_api_token_here"
EOF
cp -n .env.template .env.local
git check-ignore -v .env.local || echo '.env.local' >> .gitignoreInstruct your agent to write API wrappers that strictly read `process.env.CLOUDFLARE_API_TOKEN` instead of accepting credentials as CLI argument parameters.
Always verify `.env.local` is tracked by `.gitignore` before allowing the agent to run stage or commit commands.
Intent Matching & Trigger Invocation
Trigger deterministic agent actions using target phrases defined in the SKILL.md manifest.
When invoking Codex or Claude Code, incorporate exact trigger terms such as 'configure cloudflare cache rules' or 'purge cloudflare cache by tag'. This instructs the model's semantic router to load the specific execution SOP from the mounted SKILL.md file instead of falling back to generalized web knowledge.
Prefix the prompt with the exact action verb: 'Execute SOP: configure cloudflare cache rules for /api/products using 7-day edge ttl and Cache-Tag headers.'
Avoid ambiguous prompts like 'make cloudflare faster' which might trigger legacy Page Rules or DNS-level modifications.
Verification, Linting & Output Quality Gate
Run local syntax verification and header validation on generated purge modules and Terraform configurations.
The skill requires local verification before concluding the task. This step executes local linters, validates Terraform or TypeScript purge modules, and ensures origin headers adhere to the Cloudflare Cache-Tag format.
npm run lint && npm run test -- --grep 'cache-tag'Use `curl -I` against a staging endpoint to verify that `Cache-Tag` and `CF-Cache-Status` headers behave as expected prior to production merges.
Cloudflare enforces a 1024-byte limit per individual Cache-Tag header; ensure your agent includes length-validation logic in the header generator.
Real-World Scenario: Configure E-Commerce Product Edge Caching and Instant Cache-Tag Purge Script
“Using the cloudflare-page-rules-edge-cache skill: configure cloudflare cache rules for our Next.js e-commerce app under path '/products/*'. Set edge ttl to 7 days, browser ttl to 2 hours, emit Cache-Tag with product SKU in the response header, and create a Node.js utility script to purge cloudflare cache by tag when an inventory webhook fires.”
Runtime Troubleshooting & Failure Modes
Root Cause: The agent attempted to execute the purge request with an improperly formatted Bearer token, or the API Token lacks 'Cache Purge' zone permissions.
export CLOUDFLARE_API_TOKEN="$(grep CLOUDFLARE_API_TOKEN .env.local | cut -d '=' -f2)" && curl -X POST "https://api.cloudflare.com/client/v4/zones/${CLOUDFLARE_ZONE_ID}/purge_cache" -H "Authorization: Bearer ${CLOUDFLARE_API_TOKEN}" -H "Content-Type: application/json" --data '{"tags":["test-tag"]}'Root Cause: Origin server emits 'Set-Cookie' or 'Cache-Control: private, no-store' headers which override Cloudflare edge cache eligibility by default.
// Ensure origin response does not emit session cookies on public cached routes
headers.set('Cache-Control', 'public, max-age=7200, s-maxage=604800');
headers.delete('Set-Cookie');
headers.set('Cache-Tag', `product-${productId}`);Frequently Asked Questions (Cloudflare Cache Rules & Edge TTL Optimization SOP)
Q:Can I use Cloudflare Cache Rules & Edge TTL Optimization across Codex, Claude Code, and Cursor simultaneously?
Yes. The SKILL.md specification uses platform-agnostic Markdown and YAML frontmatter. Storing it in `.agents/skills/cloudflare-page-rules-edge-cache/SKILL.md` allows Codex Desktop, Claude Code CLI, Cursor, and Windsurf to discover and enforce the exact same operational boundaries.
Q:How does Cloudflare Cache Rules & Edge TTL Optimization prevent context window overflow during long agent sessions?
Instead of re-explaining edge caching mechanics, HTTP caching RFCs, and API structures in every single conversation turn, the SKILL.md provides deterministic triggers and four condensed procedural steps that consume fewer than 350 context tokens upon invocation.
Q:Does this skill require escalated root or container permissions?
No. The skill is audited with a security score of 98/100. It requires read access to workspace files and workspace-scoped write access. It restricts arbitrary shell execution (`shell_exec: false`) and raw agent network calls (`net_access: false`), preventing unintentional production API invocations during code generation.
Ready to equip your autonomous agent with Cloudflare Cache Rules & Edge TTL Optimization?
Copy the complete audited SKILL.md specification or download the 1-click zip bundle directly from our verified registry.