agentleFS
CloudflareKnown publishercloudflare/templates/AGENTS.md

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

Dec 2025: 0 mentionsJan 2026: 0 mentionsFeb 2026: 0 mentionsMar 2026: 0 mentionsApr 2026: 0 mentionsMay 2026: 0 mentionsJun 2026: 0 mentionsJul 2026: 0 mentionsAug 2026: 0 mentionsSep 2026: 0 mentionsOct 2026: 0 mentionsNov 2026: 0 mentions
Dec 2025Jun 2026Nov 2026
Mentions a month of the cloudflare/templates repository that our weekly crawl found: only 5 in all, so this is a hint, not a trend. There is no adoption data for this file yet.
  • 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.

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
  1. Distinctive:

    When reviewing a template PR, verify these items in order:

    line 25
  2. Very specific:

    Fix: Add a one-line description to package.json:

    line 41
  3. Distinctive:

    Fix: Add markers around the content that should appear in Cloudflare Dashboard:

    line 54
  4. Very specific:

    Fix: Create tests using @cloudflare/vitest-pool-workers.

    line 84
  5. Distinctive:

    Fix: Run from repo root:

    line 96
  6. Very specific:

    Every template needs a vitest.config.ts and test file(s).

    line 108
  7. Very specific:

    When a template uses Service Bindings to call other Workers, you need stub workers for testing.

    line 151
  8. Distinctive:

    Service Bindings: Use inline stub workers as shown above.

    line 208
  9. Distinctive:

    When reviewing template code, watch for these common issues:

    line 226
  10. Distinctive:

    When updating a PR that exists on a different branch:

    line 273
  11. Very specific:

    Add missing description to package.json

    line 311
  12. Distinctive:

    Add/fix dashboard content markers in README.md

    line 312
  13. Distinctive:

    Add or fix tests to meet minimum of 5

    line 314
  14. Distinctive:

    Test quality (only checks count, not coverage)

    line 370
  15. Distinctive:

    If tests fail with "binding not found" errors:

    line 374
  16. Very specific:

    Check wrangler.json has the binding defined

    line 376
  17. Distinctive:

    Ensure binding names match exactly (case-sensitive)

    line 378

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
AGENTS.md

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:templates

PR Review Checklist

When reviewing a template PR, verify these items in order:

  1. package.json - Has all required fields
  2. README.md - Has dashboard markers and deploy button at top
  3. Tests - Minimum 5 tests exist and pass
  4. Template Linter - pnpm run check:templates passes
  5. 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:

[![Deploy to Cloudflare](https://deploy.workers.cloudflare.com/button)](...)

<!-- 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:lockfiles

Testing 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:

  1. Happy path - Main functionality works
  2. Error handling - Invalid inputs return appropriate errors
  3. Edge cases - Empty data, missing parameters
  4. API endpoints - Each endpoint returns expected status/data
  5. 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:

  1. Deploy button at the very top
  2. Dashboard content section with overview (between markers)
  3. Screenshot or demo link
  4. Local development instructions
  5. Environment variables/secrets documentation
  6. 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-lease

Example:

# PR #877 is on branch "brayden/mfe"
git push origin HEAD:brayden/mfe --force-with-lease

Workflow 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 test

2. Fix Common Issues

Address issues in this order (most common first):

  1. Add missing description to package.json
  2. Add/fix dashboard content markers in README.md
  3. Move Deploy button to top of README.md
  4. Add or fix tests to meet minimum of 5
  5. Fix any code bugs discovered during testing

3. Verify Fixes

# From repo root
pnpm run check:templates
cd <template-dir> && pnpm test

4. 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-lease

Template 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.json required fields and cloudflare metadata
  • README.md content requirements and dashboard markers
  • package-lock.json generation
  • .gitignore requirements
  • 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 team
  • cloudflare.preview_icon_url - Icon uploaded by Growth team
  • cloudflare.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:

  1. Check wrangler.json has the binding defined
  2. For Service Bindings, add stub workers in vitest.config.ts
  3. 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.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.