Home › Cloudflare Workers / Hono › Hono on Cloudflare Workers rules

Hono on Cloudflare Workers rules

Cursor rules for Hono 4 APIs on Cloudflare Workers with Wrangler, typed bindings, D1, KV, and Vitest.

CursorCloudflare Workers / Hono

How to use

Save this as .cursor/rules/hono-workers.mdc in your repository root, commit it, and your agent will pick it up automatically. Edit the commands to match your project.

.cursor/rules/hono-workers.mdcDownload  
---
description: Hono on Cloudflare Workers conventions
globs: ["src/**/*.ts","wrangler.jsonc","wrangler.toml"]
alwaysApply: false
---

# Hono on Cloudflare Workers

- Type the app with its bindings: `new Hono<{ Bindings: Env }>()`. Generate `Env` with `npx wrangler types` after changing `wrangler.jsonc`; don't hand-write binding types.
- Access bindings and secrets through `c.env`, never `process.env`. Secrets are set with `wrangler secret put`, never committed.
- Validate input with `@hono/zod-validator` (`zValidator('json', schema)`) and read it via `c.req.valid('json')`.
- Split routes into sub-apps (`app.route('/users', users)`) and export the app type for the `hc` RPC client when a frontend consumes it.
- D1: prepared statements with `.bind()`; schema changes as files in `migrations/` applied with `wrangler d1 migrations apply`.
- KV is eventually consistent; don't use it for counters or locks (use a Durable Object).
- Workers have CPU and memory limits: stream large responses, avoid Node-only packages unless `nodejs_compat` is on.
- Background work after the response goes in `c.executionCtx.waitUntil()`.
- Errors via `app.onError` returning JSON; throw `HTTPException` for expected failures.

## Don't
- Don't use global mutable state to share data across requests.

## Done when
`npx tsc --noEmit` and `npx vitest run` (with `@cloudflare/vitest-pool-workers`) pass and `npx wrangler deploy --dry-run` succeeds.

Related rules

Astro content site rules

Cursor rules for Astro 5 sites with content collections, islands, and zero-JS-by-default pages.

CursorAstro

Chrome extension (Manifest V3) rules

Cursor rules for building Manifest V3 browser extensions with TypeScript and minimal permissions.

CursorChrome extensions

Cloudflare Agents SDK rules

Cursor rules for stateful AI agents on Cloudflare (agents package): Durable Object state, SQL, scheduling, and WebSockets.

CursorCloudflare Workers / Hono

Convex backend rules

Cursor rules for Convex backends: schema, validated queries/mutations/actions, indexes, and auth checks.

CursorConvex

Get new rules weekly

One email a week: fresh rule files, agent tips, and what's changing in Cursor, Claude Code and Copilot. Free, unsubscribe anytime.

Opens the Rulestack Newsletter on beehiiv in a new tab. Or subscribe directly on beehiiv.