Files
dotfiles/dot_agents/skills/cloudflare/references/snippets
Prad Nukala 6406208b35 shell: fish functions -> ~/.local/bin executables + bash/zsh ports; manage ~/.agents
- 16 cross-shell utilities converted to sh/bash chezmoi executables:
  ai c2p cp-appid extract_agents fab gdc gh-sonr-org-migrate ghg-clone
  ghn gho git-summary launch_omp_livediff_overlay lc-elir mdcp mdp pj
  (ghg-clone not named ghg: unrelated cargo binary owns that name)
- cwd/history helpers stay per-shell: yy c cd clip-last + ghg/ghn/gho
  cd-wrappers in bash/functions/ and zsh/functions/, loaded by rc files
- fish keeps only shell-state functions; converted ones now hit PATH
- cp-appid ignore gating moved to .local/bin path
- dot_agents/skills: 82 skills materialized from dotstate storage so
  dot_claude skill symlinks resolve on fresh bootstrap; dotstate
  profile/symlinks.json released .agents/skills .bashrc .zshrc
2026-08-10 15:15:06 -04:00
..

Cloudflare Snippets Skill Reference

Description

Expert guidance for Cloudflare Snippets ONLY - a lightweight JavaScript-based edge logic platform for modifying HTTP requests and responses. Snippets run as part of the Ruleset Engine and are included at no additional cost on paid plans (Pro, Business, Enterprise).

What Are Snippets?

Snippets are JavaScript functions executed at the edge as part of Cloudflare's Ruleset Engine. Key characteristics:

  • Execution time: 5ms CPU limit per request
  • Size limit: 32KB per snippet
  • Runtime: V8 isolate (subset of Workers APIs)
  • Subrequests: 2-5 fetch calls depending on plan
  • Cost: Included with Pro/Business/Enterprise plans

Snippets vs Workers Decision Matrix

Factor Choose Snippets If... Choose Workers If...
Complexity Simple request/response modifications Complex business logic, routing, middleware
Execution time <5ms sufficient Need >5ms or variable time
Subrequests 2-5 fetch calls sufficient Need >5 subrequests or complex orchestration
Code size <32KB sufficient Need >32KB or npm dependencies
Cost Want zero additional cost Can afford $5/mo + usage
APIs Need basic fetch, headers, URL Need KV, D1, R2, Durable Objects, cron triggers
Deployment Need rule-based triggers Want custom routing logic

Rule of thumb: Use Snippets for modifications, Workers for applications.

Execution Model

  1. Request arrives at Cloudflare edge
  2. Ruleset Engine evaluates snippet rules (filter expressions)
  3. If rule matches, snippet executes within 5ms limit
  4. Modified request/response continues through pipeline
  5. Response returned to client

Snippets execute synchronously in the request path - performance is critical.

Reading Order

  1. configuration.md - Start here: setup, deployment methods (Dashboard/API/Terraform)
  2. api.md - Core APIs: Request, Response, headers, request.cf properties
  3. patterns.md - Real-world examples: geo-routing, A/B tests, security headers
  4. gotchas.md - Troubleshooting: common errors, performance tips, API limitations

In This Reference

Quick Start

// Snippet: Add security headers
export default {
  async fetch(request) {
    const response = await fetch(request);
    const newResponse = new Response(response.body, response);
    newResponse.headers.set("X-Frame-Options", "DENY");
    newResponse.headers.set("X-Content-Type-Options", "nosniff");
    return newResponse;
  }
}

Deploy via Dashboard (Rules → Snippets) or API/Terraform. See configuration.md for details.

See Also