agentleFS
CloudflareKnown publishercloudflare/workers-sdk/packages/wrangler/AGENTS.md

workers-sdk / wrangler

AGENTS.md4.6k starsChanged 6 months agoApache-2.0View on GitHub

Wrangler-specific context only. See root AGENTS.md for monorepo conventions. Main CLI for Cloudflare Workers. ~2k-line yargs command tree in src/index.ts. Entry point is src/cli.ts (NOT src/index.ts). - No console.* — use logger singleton - No __dirname / __filename — use getBasePath() - No global fetch — use undici's fetch - Route Cloudflare v4 API calls through the existing cfetch helpers such as fetchResult, fetchListResult, and fetchPagedListResult when possible; do not use global or undici fetch directly. Prefer these helpers over…

Trending

Quiet since August.about the whole repository

Dec 2025: 0 mentionsJan 2026: 0 mentionsFeb 2026: 0 mentionsMar 2026: 0 mentionsApr 2026: 0 mentionsMay 2026: 1 mentionJun 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/workers-sdk repository that our weekly crawl found. There is no adoption data for this file yet.

Who's talking about cloudflare/workers-sdk

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

See all 17

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

On GitHub · 14

9 more on GitHub

The file

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

5 rules. About 0 are common, 1 is distinctive, and 4 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.

  • 4

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    No global fetch — use undici's fetch

    line 32
  2. Distinctive:

    Keep the service/area first and the failure last so telemetry groups consistently.

    line 41
  3. Very specific:

    Test files use .test.ts (not .spec.ts)

    line 62
  4. Very specific:

    Never import expect from vitest — use test context ({ expect }) => {}

    line 63
  5. Very specific:

    When adding expect as a parameter to helper functions, check ALL call sites (e.g., across deployments.test.ts, versions.test.ts)

    line 64

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

Wrangler — Agent Guide

Wrangler-specific context only. See root AGENTS.md for monorepo conventions.

Overview

Main CLI for Cloudflare Workers. ~2k-line yargs command tree in src/index.ts. Entry point is src/cli.ts (NOT src/index.ts).

Structure

  • src/ — CLI source
  • src/__tests__/ — Unit tests, helpers in src/__tests__/helpers/
  • e2e/ — E2E tests, requires Cloudflare credentials
  • bin/wrangler.js — Shim that spawns Node to run wrangler-dist/cli.js, forwarding stdio and IPC
  • bin/cf-wrangler.js — cf-wrangler delegate entrypoint. Owns verb dispatch, argv parsing (parseCfWranglerArgs), and the StartDevOptions literal; hands off to runCfWranglerDev from wrangler-dist/cli.js in-process (no re-spawn — the parent tool owns the Node runtime)
  • src/containers/ssh.ts — Thin command adapter; SSH options, authorization request, and transport live in @cloudflare/containers-shared/src/ssh.ts, shared with cf.
  • src/cf-wrangler/ — The cf-wrangler delegate entrypoint (see below)
  • src/containers/images.ts — Command/presentation adapter; registry image operations live in containers-shared/src/registry-images.ts, shared with cf.
  • templates/ — Worker templates

Entry Points

  • src/cli.ts — Build entry AND library API surface (dual-purpose). Calls main() when run directly; re-exports ./api when imported as library. Also re-exports parseCfWranglerArgs, parseCfWranglerBuildArgs, ArgParseError, runCfWranglerDev, and runCfWranglerBuild for the cf-wrangler bin to call in-process.
  • src/index.ts — Yargs CLI tree builder (large file). Exports main(). NOT the package entry point despite the name.
  • src/api/index.ts — Public programmatic API barrel.
  • src/cf-wrangler/ — The cf-wrangler delegate entrypoint, an experimental escape hatch for projects that can't use @cloudflare/vite-plugin. It exposes dev + four flags (--mode, --port, --host, --local) and build + --mode; the wrangler config file is found via wrangler's standard discovery (no --config flag). Preview build context is supplied through CLOUDFLARE_PREVIEW_BUILD, matching framework-owned build commands. It is NOT a separate package and does NOT use the unstable_dev test harness. It shares its spawn contract (verb dispatch, flag vocabulary, exit-2 feature detection) with the sibling cf-vite delegate in @cloudflare/vite-plugin. bin/cf-wrangler.js owns verb dispatch, argv parsing, and the StartDevOptions literal; src/cf-wrangler/dev.ts (exported as runCfWranglerDev) wraps startDev in the experimental-flags context and waits for teardown. src/cf-wrangler/build.ts (exported as runCfWranglerBuild) runs the Build Output Specification path used by wrangler build --experimental-new-config --experimental-cf-build-output, producing .cloudflare/output/v0. src/cf-wrangler/args.ts (exported as parseCfWranglerArgs, parseCfWranglerBuildArgs, and ArgParseError) does the strict argv parse. The "unknown subcommand" error doubles as a feature-detection signal for the parent CLI.

Conventions (Wrangler-Specific)

  • No console.* — use logger singleton
  • No __dirname / __filename — use getBasePath()
  • No global fetch — use undici's fetch
  • Route Cloudflare v4 API calls through the existing cfetch helpers such as fetchResult, fetchListResult, and fetchPagedListResult when possible; do not use global or undici fetch directly. Prefer these helpers over adding or passing the cloudflare package solely for a simple request, and use the Cloudflare TypeScript SDK when its generated API surface or behavior is materially useful.
  • telemetryMessage values for UserError-compatible errors must be static, safe labels. Do not use telemetryMessage: true unless the user-facing message cannot include user input, file paths, resource names, IDs, secret names, raw API messages, or command input. Even when safe, telemetryMessage: true is usually less useful because user-facing copy is harder to group and parse than a stable telemetry label.
  • Format telemetryMessage values as lower-case phrases: <service or area> <command or sub-area> <failure>, for example kv namespace binding not found in config, r2 object put file not found, or pages deploy project name missing.
  • Keep the service/area first and the failure last so telemetry groups consistently. Prefer stable categories over user-facing copy; telemetry labels should not change just because CLI wording changes.

Build

  • tsup: single entry src/cli.ts → wrangler-dist/cli.js
  • package.json main points at wrangler-dist/cli.js
  • Custom embedWorkersPlugin() bundles Worker templates via esbuild for tests

Testing

  • Pool: "forks" (not threads) — heavy global mocking
  • runWrangler(cmd) calls main() in-process (no subprocess)
  • MSW for API mocking — pre-built handlers per API domain in src/__tests__/helpers/msw/
  • Shared helpers: runInTempDir(), mockAccountId(), mockApiToken(), mockConfirm(), mockPrompt(), mockSelect(), captureRequestsFrom()
  • Unit timeout: 50s, retry: 0. Note: wrangler's vitest.config.mts does NOT use mergeConfig with vitest.shared.ts, so shared defaults (timeouts, retry, etc.) are not inherited — they must be set explicitly in the wrangler config.
  • E2E timeout: 90s, bail: 1, singleThread
  • globals: true for vitest globals
  • Output normalization via normalizeString() pipeline

Anti-Patterns

  • Test files use .test.ts (not .spec.ts)
  • Never import expect from vitest — use test context ({ expect }) => {}
    • When adding expect as a parameter to helper functions, check ALL call sites (e.g., across deployments.test.ts, versions.test.ts)

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.