agentleFS
CloudflareKnown publishercloudflare/workerd/types/AGENTS.md

workerd / types

AGENTS.md8.8k starsChanged 9 months agoApache-2.0View on GitHub

Generates @cloudflare/workers-types .d.ts files from C++ RTTI (via jsg/rtti.capnp) + hand-written defines/*.d.ts. A workerd-hosted Worker extracts RTTI at runtime per compat-date; TypeScript transforms post-process into ambient and importable outputs. CI validates generated-snapshot/ matches. Types in this project come from three layers. Changes must be made in the correct layer: Do not edit files in generated-snapshot/ directly — they are overwritten by just generate-types. If the generated output looks wrong, fix the source layer (C++ RTTI, JSG_TS_OVERRIDE, or defines/). Types in…

Trending

Quiet since August.thin dataabout the whole repository

Dec 2025: 0 mentionsJan 2026: 0 mentionsFeb 2026: 0 mentionsMar 2026: 2 mentionsApr 2026: 0 mentionsMay 2026: 0 mentionsJun 2026: 0 mentionsJul 2026: 0 mentionsAug 2026: 1 mentionSep 2026: 0 mentionsOct 2026: 0 mentionsNov 2026: 0 mentions
Dec 2025Jun 2026Nov 2026
Mentions a month of the cloudflare/workerd repository that our weekly crawl found: only 12 in all, so this is a hint, not a trend. There is no adoption data for this file yet.

Who's talking about cloudflare/workerd

The biggest 5 of 12 mentions linking to the repository that our crawl found. Each line is their own headline.

See all 12

Talked about on GitHub, Bluesky and Hacker News (12 times).

On GitHub · 6

1 more on GitHub

On Hacker News · 2

The file

We split this AGENTS.md into the rules it gives an agent

3 rules. About 0 are common, 1 is distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  • could be automatic: a setting could enforce it
  1. Very specific:

    Do not edit files in generated-snapshot/ directly — they are overwritten by just generate-types.

    line 39
  2. Very specific:

    After any change that affects types (C++ API changes, JSG_TS_OVERRIDE edits, defines/ modifications), regenerate the snapshot:

    line 65
  3. Distinctive:

    When adding new types or changing existing ones, add or update type tests to cover the new shapes.

    line 77

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

types/

OVERVIEW

Generates @cloudflare/workers-types .d.ts files from C++ RTTI (via jsg/rtti.capnp) + hand-written defines/*.d.ts. A workerd-hosted Worker extracts RTTI at runtime per compat-date; TypeScript transforms post-process into ambient and importable outputs. CI validates generated-snapshot/ matches.

PIPELINE

  1. RTTI extraction: src/worker/ runs inside workerd, imports binary RTTI via workerd:rtti + param names from param-extractor.rs
  2. Generation: src/generator/ converts Cap'n Proto structures to TS AST nodes (walks types, members, methods recursively via collectIncluded)
  3. Transforms (ordered, in src/index.ts): iterators -> overrides/defines -> global scope extraction -> class-to-interface -> comments -> onmessage declaration; then second pass: import-resolve -> ambient. Importable variant runs separately.
  4. Defines concatenation: defines/*.d.ts appended after transforms (AI, D1, R2, RPC, Vectorize, etc.)
  5. Build: scripts/build-types.ts iterates compat-date entrypoints (oldest through experimental), type-checks output against TS libs

KEY DIRECTORIES

DirectoryPurpose
src/generator/RTTI-to-TS-AST: structure.ts (classes/interfaces), type.ts (type mapping)
src/transforms/11 post-processing TS transformer factories
src/worker/Workerd-hosted entry; imports RTTI binary + virtual modules
defines/Hand-written .d.ts for APIs not expressible via C++ RTTI (~25 files)
generated-snapshot/Checked-in latest/ + experimental/ output; CI diff-checked
scripts/build-types.ts (full generation), build-worker.ts (worker bundle)
test/Vitest specs for generator, transforms, print; type-check tests in test/types/

ADDING OR UPDATING TYPES

Where type changes belong

Types in this project come from three layers. Changes must be made in the correct layer:

LayerLocationWhen to use
C++ RTTIsrc/workerd/api/*.h (JSG macros)Types derived from C++ classes — the generator extracts these automatically
JSG_TS_OVERRIDESame .h files, inside JSG_RESOURCE_TYPE blocksWhen the auto-generated TS signature needs adjustment (e.g., conditional properties, union narrowing)
Hand-written definestypes/defines/*.d.tsTypes for APIs not expressible via C++ RTTI (Cloudflare product bindings like AI, D1, R2, Vectorize, etc.)

Do not edit files in generated-snapshot/ directly — they are overwritten by just generate-types. If the generated output looks wrong, fix the source layer (C++ RTTI, JSG_TS_OVERRIDE, or defines/).

Naming conventions

Types in defines/*.d.ts become top-level ambient declarations visible to every Worker project. Generic names will collide or confuse.

  • Prefix types with the product or feature name. For example: D1Meta, AiSearchConfig, VectorizeVector — not Meta, Config, or Vector.
  • Follow the existing convention for the relevant product. Check the existing defines/ file for that product (e.g., cf.d.ts uses IncomingRequestCfProperties*, d1.d.ts uses D1*, ai-search.d.ts uses AiSearch*).
  • When in doubt, be more specific. A name like TracePreviewInfo is better than Preview. The cost of a verbose name is low; the cost of a naming collision in every user's project is high.

Interface design

  • Never use bare object as a type. type Foo = object prevents all property access without casting, providing no value to users. Use a proper interface with known fields instead.
  • Use interfaces with known fields + index signature for types where the shape is partially known but extensible. Follow the IncomingRequestCfPropertiesBase pattern:
    interface CloudflareAccessIdentity extends Record<string, unknown> {
      email?: string;
      name?: string;
      // ... other known fields
    }
  • Index signatures ([key: string]: unknown) need justification. Only add them when forward-compatibility is genuinely required (e.g., the API frequently adds new fields across releases). Document the reason in a JSDoc comment. Do not add index signatures by default.
  • Add JSDoc comments to interfaces and their fields, especially for types used in defines/. These comments appear in users' IDEs.

Snapshot regeneration

After any change that affects types (C++ API changes, JSG_TS_OVERRIDE edits, defines/ modifications), regenerate the snapshot:

just generate-types

CI will fail if generated-snapshot/ does not match the generated output. Always commit the updated snapshot alongside your source changes.

Type tests

Type-level tests live in test/types/ (e.g., test/types/rpc.ts). These are compile-time checks — they verify that type expressions are accepted or rejected by the TypeScript compiler.

  • When adding new types or changing existing ones, add or update type tests to cover the new shapes.
  • Review type test changes carefully — a test that compiles successfully may still be asserting the wrong thing.

PR hygiene for type changes

  • Do not include unrelated formatting changes in PRs that modify types. If formatting needs fixing, do it in a separate commit or PR.
  • Type changes in feature PRs need review from someone familiar with the types system. The Wrangler team typically reviews type changes that affect @cloudflare/workers-types.

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.