templates
AGENTS.md2.1k starsChanged 11 months agoMITView on GitHub
This guide helps AI agents review, maintain, and contribute to Cloudflare Worker templates. It documents patterns, common issues, and testing strategies learned from real PR reviews. When reviewing a template PR, verify these items in order: Symptom: Template linter fails with missing description error. Fix: Add a one-line description to package.json: Symptom: Dashboard won't display template details correctly. Fix: Add markers around the content that should appear in Cloudflare Dashboard: Important: The Deploy to Cloudflare button should be at the…
- Commits and pushes
Trending
Quiet this year.thin dataabout the whole repository
Who's talking about cloudflare/templates
- cloudflare/workers-sdk“Vite plugin has race condition with HMR - `A hanging Promise was canceled.`”GitHub · Jun 6, 2025 · 13 reactions
- cloudflare/workers-sdk“Container builds incompatible with podman”GitHub · Jun 26, 2025 · 12 reactions
- cloudflare/workerd“Switch to hard tabs for indentation”GitHub · Sep 27, 2022 · 7 reactions
- cloudflare/ai-utils“Switch to hard tabs for indentation”GitHub · Jun 27, 2024 · 3 reactions
- tursodatabase/libsql-client-ts“Cloudflare worker error with opennextjs-cloudflare”GitHub · Mar 18, 2025 · 2 reactions
The biggest 5 of 5 mentions linking to the repository that our crawl found. Each line is their own headline.
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.
Of the AGENTS.md files we read, the 11,773 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository4 other files it gives its agents.
- agent-visibility-template/AGENTS.mdAGENTS.md
- ai-brand-visibility-template/AGENTS.mdAGENTS.md
- x402-proxy-template/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
The file
Show its rules and text
We split this AGENTS.md into the rules it gives an agent
17 rules. About 0 are common, 11 are distinctive, and 6 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈11
Distinctive · estimate
This author's own choices. Worth a look.
6
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 25
When reviewing a template PR, verify these items in order:
- Very specific: line 41
Fix: Add a one-line description to package.json:
- Distinctive: line 54
Fix: Add markers around the content that should appear in Cloudflare Dashboard:
- Very specific: line 84
Fix: Create tests using @cloudflare/vitest-pool-workers.
- Distinctive: line 96
Fix: Run from repo root:
- Very specific: line 108
Every template needs a vitest.config.ts and test file(s).
- Very specific: line 151
When a template uses Service Bindings to call other Workers, you need stub workers for testing.
- Distinctive: line 208
Service Bindings: Use inline stub workers as shown above.
- Distinctive: line 226
When reviewing template code, watch for these common issues:
- Distinctive: line 273
When updating a PR that exists on a different branch:
- Very specific: line 311
Add missing description to package.json
- Distinctive: line 312
Add/fix dashboard content markers in README.md
- Distinctive: line 314
Add or fix tests to meet minimum of 5
- Distinctive: line 370
Test quality (only checks count, not coverage)
- Distinctive: line 374
If tests fail with "binding not found" errors:
- Very specific: line 376
Check wrangler.json has the binding defined
- Distinctive: line 378
Ensure binding names match exactly (case-sensitive)
≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
AGENTS.md
This guide helps AI agents review, maintain, and contribute to Cloudflare Worker templates. It documents patterns, common issues, and testing strategies learned from real PR reviews.
Quick Reference
Essential Commands
# Validate everything before starting work
pnpm run check
# After making changes, auto-fix what's possible
pnpm run fix
# Run template-specific tests
cd <template-dir> && pnpm test
# Lint templates for compliance
pnpm run check:templatesPR Review Checklist
When reviewing a template PR, verify these items in order:
- package.json - Has all required fields
- README.md - Has dashboard markers and deploy button at top
- Tests - Minimum 5 tests exist and pass
- Template Linter -
pnpm run check:templatespasses - Build - Template compiles without errors
Common Issues and Fixes
1. Missing description in package.json
Symptom: Template linter fails with missing description error.
Fix: Add a one-line description to package.json:
{
"name": "my-template",
"description": "Brief description of what this template does."
}2. Missing Dashboard Content Markers
Symptom: Dashboard won't display template details correctly.
Fix: Add markers around the content that should appear in Cloudflare Dashboard:
[](...)
<!-- dash-content-start -->
## Overview
This template demonstrates...
<!-- dash-content-end -->
## Getting Started
...Important: The Deploy to Cloudflare button should be at the TOP of the README, before the dash-content markers.
3. Deploy Button in Wrong Location
Symptom: Users can't easily find the deploy button.
Fix: Move the Deploy to Cloudflare button to the very top of README.md, before any other content.
4. Missing or Insufficient Tests
Symptom: Template has fewer than 5 tests or no test file.
Fix: Create tests using @cloudflare/vitest-pool-workers. See Testing Patterns below.
5. Using wrangler.toml Instead of wrangler.json
Symptom: Template linter fails with configuration format error.
Fix: Convert wrangler.toml to wrangler.json or wrangler.jsonc.
6. Missing package-lock.json
Symptom: Slower deployments, potential dependency issues.
Fix: Run from repo root:
pnpm run fix:lockfilesTesting Patterns
Basic Test Setup
Every template needs a vitest.config.ts and test file(s). The simplest setup:
// vitest.config.ts
import { defineWorkersProject } from "@cloudflare/vitest-pool-workers/config";
export default defineWorkersProject({
test: {
poolOptions: {
workers: {
singleWorker: true,
wrangler: {
configPath: "./wrangler.json",
},
},
},
},
});// test/index.test.ts
import { SELF } from "cloudflare:test";
import { describe, it, expect } from "vitest";
describe("Template Name", () => {
it("returns 200 on homepage", async () => {
const response = await SELF.fetch("https://example.com/");
expect(response.status).toBe(200);
});
it("returns HTML content", async () => {
const response = await SELF.fetch("https://example.com/");
const html = await response.text();
expect(html).toContain("<!DOCTYPE html>");
});
// Add at least 3 more meaningful tests...
});Testing with Service Bindings (Stub Workers)
When a template uses Service Bindings to call other Workers, you need stub workers for testing. Define them inline in vitest.config.ts:
// vitest.config.ts
import { defineWorkersProject } from "@cloudflare/vitest-pool-workers/config";
// Define stub worker as inline JavaScript
const stubWorkerScript = /* javascript */ `
export default {
async fetch(request) {
const url = new URL(request.url);
return new Response(\`Stub response for: \${url.pathname}\`, {
headers: { "Content-Type": "text/plain" },
});
},
};
`;
export default defineWorkersProject({
test: {
poolOptions: {
workers: {
singleWorker: true,
wrangler: {
configPath: "./wrangler.json",
},
miniflare: {
workers: [
{
name: "my-service-binding-name", // Must match binding name in wrangler.json
modules: [
{
type: "ESModule",
path: "index.js",
contents: stubWorkerScript,
},
],
compatibilityDate: "2024-01-01",
},
],
},
},
},
},
});Testing Different Binding Types
KV Namespace: Automatically available via wrangler.json config, use env.MY_KV in tests.
D1 Database: Define migrations in wrangler.json, database is auto-created for tests.
R2 Bucket: Automatically available via wrangler.json config.
Durable Objects: Define in wrangler.json, accessible in tests.
Service Bindings: Use inline stub workers as shown above.
What to Test
Aim for at least 5 tests covering:
- Happy path - Main functionality works
- Error handling - Invalid inputs return appropriate errors
- Edge cases - Empty data, missing parameters
- API endpoints - Each endpoint returns expected status/data
- HTML/UI - Key elements are present in responses
Code Review Patterns
Logic Bug Detection
When reviewing template code, watch for these common issues:
Request Interception Order: Middleware or special endpoints must be checked BEFORE forwarding to upstream services.
// WRONG - Check happens after fetch, never executes
const response = await upstream.fetch(request);
if (url.pathname === "/__special") {
return new Response("special");
}
// CORRECT - Check happens before fetch
if (url.pathname === "/__special") {
return new Response("special");
}
const response = await upstream.fetch(request);Environment Variable Access: Bindings must be accessed from the env parameter, not global scope.
// WRONG - Won't work in Workers
const db = globalThis.DB;
// CORRECT - Access from env parameter
export default {
async fetch(request, env) {
const db = env.DB;
},
};README Quality
A good template README should have:
- Deploy button at the very top
- Dashboard content section with overview (between markers)
- Screenshot or demo link
- Local development instructions
- Environment variables/secrets documentation
- Links to relevant Cloudflare docs
Pushing Changes to PRs
When updating a PR that exists on a different branch:
# Find the PR's actual branch name
gh pr view <PR_NUMBER> --json headRefName
# Push to the PR branch (not your local branch name)
git push origin HEAD:<pr-branch-name> --force-with-leaseExample:
# PR #877 is on branch "brayden/mfe"
git push origin HEAD:brayden/mfe --force-with-leaseWorkflow for Reviewing Template PRs
1. Initial Assessment
# Checkout the PR
gh pr checkout <PR_NUMBER>
# Run template linter first - catches most issues
pnpm run check:templates
# Run template's own tests
cd <template-dir> && pnpm test2. Fix Common Issues
Address issues in this order (most common first):
- Add missing
descriptionto package.json - Add/fix dashboard content markers in README.md
- Move Deploy button to top of README.md
- Add or fix tests to meet minimum of 5
- Fix any code bugs discovered during testing
3. Verify Fixes
# From repo root
pnpm run check:templates
cd <template-dir> && pnpm test4. Commit and Push
# Commit with descriptive message
git add -A
git commit -m "Add tests and address review feedback for <template-name>"
# Push to PR branch
git push origin HEAD:<pr-branch-name> --force-with-leaseTemplate Compliance Summary
For the full list of template requirements, see CONTRIBUTING.md.
The CONTRIBUTING.md file contains the authoritative checklist for template compliance, including:
package.jsonrequired fields andcloudflaremetadataREADME.mdcontent requirements and dashboard markerspackage-lock.jsongeneration.gitignorerequirements- Playwright E2E test requirements
- Worker secrets and environment variables
Waiting on Cloudflare Team
These items cannot be completed by external contributors:
cloudflare.preview_image_url- Screenshot uploaded by Growth teamcloudflare.preview_icon_url- Icon uploaded by Growth teamcloudflare.publish: true- Set by Cloudflare team when ready to publish
Debugging Tips
Template Linter Not Finding Issues
The linter doesn't catch everything. Manual checks needed for:
- Dashboard content marker placement
- Deploy button position
- Code logic bugs
- Test quality (only checks count, not coverage)
Tests Failing with Binding Errors
If tests fail with "binding not found" errors:
- Check wrangler.json has the binding defined
- For Service Bindings, add stub workers in vitest.config.ts
- Ensure binding names match exactly (case-sensitive)
Compatibility Date Warnings
The latest compatibility date supported by the installed Cloudflare Workers Runtime is "2025-09-06",
but you've requested "2025-10-08". Falling back to "2025-09-06"...This warning is normal during local testing. The template linter enforces a specific compatibility date that may be newer than the locally installed runtime. Tests will still pass.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

