Set up Cloudflare Workers with Hono routing, Vite plugin, and Static Assets. Prevents 8 errors including export syntax, routing conflicts, HMR crashes, and free tier 429s. Use when: creating Workers projects, configuring Hono/Vite, or troubleshooting export syntax, API route conflicts, or HMR issues.
/plugin marketplace add jezweb/claude-skills/plugin install jezweb-tooling-skills@jezweb/claude-skillsThis skill inherits all available tools. When active, it can use any tool Claude has access to.
README.mdagents/cloudflare-debug.mdagents/cloudflare-deploy.mdagents/d1-migration.mdagents/worker-scaffold.mdcommands/deploy.mdcommands/init.mdreferences/architecture.mdreferences/common-issues.mdreferences/deployment.mdrules/cloudflare-worker-base.mdtemplates/package.jsontemplates/public/index.htmltemplates/public/script.jstemplates/public/styles.csstemplates/src/index.tstemplates/tsconfig.jsontemplates/vite.config.tstemplates/wrangler.jsoncProduction-tested: cloudflare-worker-base-test (https://cloudflare-worker-base-test.webfonts.workers.dev) Last Updated: 2026-01-03 Status: Production Ready ✅ Latest Versions: hono@4.11.3, @cloudflare/vite-plugin@1.17.1, vite@7.3.1, wrangler@4.54.0
Recent Updates (2025-2026):
wrangler deploy --x-autoconfig)WorkerEntrypoint class for service bindings# 1. Scaffold project
npm create cloudflare@latest my-worker -- --type hello-world --ts --git --deploy false --framework none
# 2. Install dependencies
cd my-worker
npm install hono@4.11.3
npm install -D @cloudflare/vite-plugin@1.17.1 vite@7.3.1
# 3. Create wrangler.jsonc
{
"name": "my-worker",
"main": "src/index.ts",
"account_id": "YOUR_ACCOUNT_ID",
"compatibility_date": "2025-11-11",
"assets": {
"directory": "./public/",
"binding": "ASSETS",
"not_found_handling": "single-page-application",
"run_worker_first": ["/api/*"] // CRITICAL: Prevents SPA fallback from intercepting API routes
}
}
# 4. Create vite.config.ts
import { defineConfig } from 'vite'
import { cloudflare } from '@cloudflare/vite-plugin'
export default defineConfig({ plugins: [cloudflare()] })
# 5. Create src/index.ts
import { Hono } from 'hono'
type Bindings = { ASSETS: Fetcher }
const app = new Hono<{ Bindings: Bindings }>()
app.get('/api/hello', (c) => c.json({ message: 'Hello!' }))
app.all('*', (c) => c.env.ASSETS.fetch(c.req.raw))
export default app // CRITICAL: Use this pattern (NOT { fetch: app.fetch })
# 6. Deploy
npm run dev # Local: http://localhost:8787
wrangler deploy # Production
Critical Configuration:
run_worker_first: ["/api/*"] - Without this, SPA fallback intercepts API routes returning index.html instead of JSON (workers-sdk #8879)export default app - Using { fetch: app.fetch } causes "Cannot read properties of undefined" (honojs/hono #3955)This skill prevents 8 documented issues:
Error: "Cannot read properties of undefined (reading 'map')"
Source: honojs/hono #3955
Prevention: Use export default app (NOT { fetch: app.fetch })
Error: API routes return index.html instead of JSON
Source: workers-sdk #8879
Prevention: Add "run_worker_first": ["/api/*"] to wrangler.jsonc
Error: "Handler does not export a scheduled() function" Source: honojs/vite-plugins #275 Prevention: Use Module Worker format when needed:
export default {
fetch: app.fetch,
scheduled: async (event, env, ctx) => { /* ... */ }
}
Error: "A hanging Promise was canceled" during development
Source: workers-sdk #9518
Prevention: Use @cloudflare/vite-plugin@1.13.13 or later
Error: Non-deterministic deployment failures in CI/CD Source: workers-sdk #7555 Prevention: Use Wrangler 4.x+ with retry logic (fixed in recent versions)
Error: Using deprecated Service Worker format Source: Cloudflare migration guide Prevention: Always use ES Module format
Error: 404 errors for fingerprinted assets during gradual deployments
Source: Cloudflare Static Assets Docs
Why It Happens: Modern frameworks (React/Vue/Angular with Vite) generate fingerprinted filenames (e.g., index-a1b2c3d4.js). During gradual rollouts between versions, a user's initial request may go to Version A (HTML references index-a1b2c3d4.js), but subsequent asset requests route to Version B (only has index-m3n4o5p6.js), causing 404s
Prevention:
Error: 429 (Too Many Requests) responses on asset requests when exceeding free tier limits
Source: Cloudflare Static Assets Billing Docs
Why It Happens: When using run_worker_first, requests matching specified patterns ALWAYS invoke your Worker script (counted toward free tier limits). After exceeding limits, these requests receive 429 instead of falling back to free static asset serving
Prevention:
!/pattern) to exclude paths from Worker invocationrun_worker_first patterns to only essential API routesCritical Understanding: "not_found_handling": "single-page-application" returns index.html for unknown routes (enables React Router, Vue Router). Without run_worker_first, this intercepts API routes!
Request Routing with run_worker_first: ["/api/*"]:
/api/hello → Worker handles (returns JSON)/ → Static Assets serve index.html/styles.css → Static Assets serve styles.css/unknown → Static Assets serve index.html (SPA fallback)Static Assets Caching: Automatic edge caching. Cache bust with query strings: <link href="/styles.css?v=1.0.0">
Free Tier Warning (2025): run_worker_first patterns count toward free tier limits. After exceeding, requests get 429 instead of falling back to free static assets. Use negative patterns (!/pattern) or upgrade to Paid plan.
Default Behavior: Wrangler automatically provisions R2 buckets, D1 databases, and KV namespaces when deploying. This eliminates manual resource creation steps.
How It Works:
// wrangler.jsonc - Just define bindings, resources auto-create on deploy
{
"d1_databases": [{ "binding": "DB", "database_name": "my-app-db" }],
"r2_buckets": [{ "binding": "STORAGE", "bucket_name": "my-app-files" }],
"kv_namespaces": [{ "binding": "CACHE", "title": "my-app-cache" }]
}
# Deploy - resources auto-provisioned if they don't exist
wrangler deploy
# Disable auto-provisioning (use existing resources only)
wrangler deploy --no-x-provision
Benefits:
wrangler d1 create / wrangler r2 create steps neededwrangler dev creates local emulated resources)What It Is: JavaScript-native RPC system for calling methods between Workers. Uses Cap'n Proto under the hood for zero-copy message passing.
Use Case: Split your application into multiple Workers (e.g., API Worker + Auth Worker + Email Worker) that call each other with type-safe methods.
Defining an RPC Service:
import { WorkerEntrypoint } from 'cloudflare:workers'
export class AuthService extends WorkerEntrypoint<Env> {
async verifyToken(token: string): Promise<{ userId: string; valid: boolean }> {
// Access bindings via this.env
const session = await this.env.SESSIONS.get(token)
return session ? { userId: session.userId, valid: true } : { userId: '', valid: false }
}
async createSession(userId: string): Promise<string> {
const token = crypto.randomUUID()
await this.env.SESSIONS.put(token, JSON.stringify({ userId }), { expirationTtl: 3600 })
return token
}
}
// Default export still handles HTTP requests
export default { fetch: ... }
Calling from Another Worker:
// wrangler.jsonc
{
"services": [
{ "binding": "AUTH", "service": "auth-worker", "entrypoint": "AuthService" }
]
}
// In your main Worker
const { valid, userId } = await env.AUTH.verifyToken(authHeader)
Key Points:
wrangler dev, shows as [connected] for same-Worker calls/deploy - One-Command Deploy PipelineUse when: Ready to commit, push, and deploy your Cloudflare Worker in one step.
Does:
wrangler deploy, captures Worker URLTime savings: 2-3 min per deploy cycle
Edge Cases Handled:
Templates: Complete setup files in templates/ directory (wrangler.jsonc, vite.config.ts, package.json, tsconfig.json, src/index.ts, public/index.html, styles.css, script.js)
mcp__cloudflare-docs__search_cloudflare_documentation for latest docs{
"dependencies": {
"hono": "^4.11.3"
},
"devDependencies": {
"@cloudflare/vite-plugin": "^1.17.1",
"@cloudflare/workers-types": "^4.20260103.0",
"vite": "^7.3.1",
"wrangler": "^4.54.0",
"typescript": "^5.9.3"
}
}
Live Example: https://cloudflare-worker-base-test.webfonts.workers.dev (build time: 45 min, 0 errors, all 8 issues prevented)
This skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.