AGENTS.md template for Hono
A ready AGENTS.md for a Hono API on Cloudflare Workers. It covers routes, bindings and validation, the Wrangler commands, and the Node.js assumptions agents make on a runtime that is not Node.
# AGENTS.md A Hono API written in TypeScript and deployed to Cloudflare Workers. ## Commands - `npm run dev`: start `wrangler dev` on http://localhost:8787 - `npm run deploy`: deploy to Cloudflare. Ask before running - `npm test`: run Vitest - `npx tsc --noEmit`: type-check ## Project structure - `src/index.ts`: creates the app and mounts the routes - `src/routes/`: one file per resource - `src/middleware/`: auth, logging, error handling - `wrangler.jsonc`: Worker config and bindings (older projects use `wrangler.toml`) ## Rules for agents - This code runs on Cloudflare Workers, not Node.js. No `fs`, no `path`, and no package that needs them. - Read configuration, secrets and bindings from `c.env`. Never use `process.env` and never hardcode a secret. - Every handler returns its response: `return c.json(...)`. - Ask before running `npm run deploy` or changing bindings in the Wrangler config. ## Conventions ### Hono - Use the validator middleware (`@hono/zod-validator` or similar) for every route with input. - Keep handlers small — compose with `.use()` for shared middleware. - Typed env via `Hono<{ Bindings: ...; Variables: ... }>`. ### TypeScript - Prefer `type` for object shapes, `interface` only when extending third-party types. - Never use `any` — use `unknown` and narrow, or write a proper type. - No non-null assertions (`!`) except in tests or when a type guard just ran. - Use `readonly` for props, return types, and array params that don't mutate. - Prefer discriminated unions over enums. Enums only for stable public APIs. - Import types with `import type { ... }` to avoid runtime import cost. ### Vitest - Co-locate test files (`*.test.ts`) with the code they test. - Prefer `describe` only when grouping helps. Flat tests are fine. - Mock at the boundary (network, fs, clock) — never mock the unit under test. ## Avoid - Declaration-merging global namespaces. - Using `Function`, `Object`, or `{}` as types. ## Guardrails - Never commit secrets, API keys, or credentials. If you spot one in a diff, stop and flag it. - Do not invent dependencies. If a package is not already in the manifest, confirm before adding it. - When a command fails, read the actual error. Do not retry blindly or bypass with `--force`. - Prefer editing existing files over creating new ones. - Run the tests and the linter before saying a task is done, and say what you ran.
The commands and folders are the common defaults for Hono. Change them to match your project before you commit the file: an agent will run exactly what is written here.
How to use it
Save the file as AGENTS.md in the root of your repository and commit it. Then check each tool you use:
| Tool | What to do |
|---|---|
| Claude Code | Reads AGENTS.md only when no CLAUDE.md exists in or above the folder. If you have a CLAUDE.md, put @AGENTS.md on its first line. |
| Cursor | Reads AGENTS.md from the project root, in the desktop app and the terminal. In the app, rules in .cursor/rules must be .mdc files. The terminal reads only plain .md files there. |
| Codex | Reads AGENTS.md from the root down to the folder you are in, with a shared 32 KiB limit across all of them. |
| GitHub Copilot | Reads AGENTS.md on some surfaces only. Keep a .github/copilot-instructions.md as well if your team relies on Copilot. |
Details and sources: the AGENTS.md compatibility matrix.
What agents get wrong in Hono projects
These are the reasons the “Rules for agents” section says what it says.
Using Node APIs on Workers
Agents import fs and path or reach for packages that need them. Those do not exist on Workers by default, and the failure only shows at deploy time.
Reading process.env
On Workers, secrets and bindings arrive on c.env. process.env.API_KEY is undefined there, and agents respond by hardcoding the value.
Forgetting to return the response
A handler that calls c.json(...) without return sends nothing. Agents used to Express res.json() do this constantly.
Trusting the request body
Agents read await c.req.json() and use it directly. The template requires a validator on every route that takes input.
Questions
Where does AGENTS.md go in a Hono project?
In the root of the repository, next to your manifest file. Tools read it from the folder you start them in and, for most tools, from parent folders too.
Does Claude Code read AGENTS.md?
Only when there is no CLAUDE.md in or above the working folder. If you already have a CLAUDE.md, keep it and make its first line @AGENTS.md so both tools read the same rules.
How long should the file be?
Short enough that every line is something the agent would get wrong without it. Codex shares a 32 KiB budget across all the AGENTS.md files it loads, and long files get followed less closely by every tool.
I run Hono on Node or Bun, not Workers. What changes?
Change the summary line, replace the Wrangler commands with your own, and drop the rule about Node APIs. Keep the rest. Hono code is the same across runtimes; only where configuration comes from differs.