agentleFS
CloudflareKnown publishercloudflare/cloudflared/AGENTS.md

cloudflared

AGENTS.md16k starsChanged 3 months agoApache-2.0View on GitHub

Cloudflare's command-line tool and networking daemon written in Go. Production-grade tunneling and network connectivity services used by millions of developers and organizations worldwide. Notes on linting: - .golangci.yaml is configured with new-from-rev and whole-files: true. Touching a file triggers linting of the ENTIRE file, not just the changed hunks. Expect to fix pre-existing issues in files you modify, or add targeted // nolint: <linter> comments with a short justification. - Prefer defer func() { _ = resource.Close() }() over defer…

Trending

More talk lately.about the whole repository

Dec 2025: 1 mentionJan 2026: 0 mentionsFeb 2026: 1 mentionMar 2026: 1 mentionApr 2026: 0 mentionsMay 2026: 1 mentionJun 2026: 2 mentionsJul 2026: 0 mentionsAug 2026: 1 mentionSep 2026: 3 mentionsOct 2026: 6 mentionsNov 2026: 0 mentions
Dec 2025Jun 2026Nov 2026
Mentions a month of the cloudflare/cloudflared repository that our weekly crawl found. There is no adoption data for this file yet.

Who's talking about cloudflare/cloudflared

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

See all 42

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

On GitHub · 35

30 more on GitHub

On Bluesky · 4

On Hacker News · 3

  • 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.

The file

Show its rules and text

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

39 rules. About 1 is common, 21 are distinctive, and 17 are very specific to this project.

  • ≈1

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈21

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 17

    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:

    Prefer defer func() { _ = resource.Close() }() over defer resource.Close() for io.Closer values whose error truly does not matter — this …

    line 69
  2. Distinctive:

    Use meaningful package names that reflect functionality

    line 77
  3. Very specific:

    Avoid generic names like util, common, helper

    line 79
  4. Distinctive:

    Always handle errors explicitly, never ignore them

    line 114
  5. Very specific:

    Use fmt.Errorf for error wrapping

    line 115
  6. Distinctive:

    Create meaningful error messages with context

    line 116
  7. Distinctive:

    Use error variables for common errors

    line 117
  8. Very specific:

    Use github.com/rs/zerolog for structured logging

    line 128
  9. Distinctive:

    Use appropriate log levels (Debug, Info, Warn, Error)

    line 130
  10. Very specific:

    Use github.com/stretchr/testify for assertions

    line 141
  11. Very specific:

    Test files end with _test.go

    line 142
  12. Distinctive:

    Use table-driven tests for multiple scenarios

    line 143
  13. Very specific:

    Always use t.Parallel() for parallel-safe tests

    line 144
  14. Distinctive:

    Use meaningful test names that describe behavior

    line 145
  15. Distinctive:

    Keep interfaces small and focused

    line 175
  16. Distinctive:

    Use descriptive names for complex types

    line 176
  17. Very specific:

    Always accept context.Context as first parameter for long-running operations

    line 193
  18. Distinctive:

    Use channels for goroutine communication

    line 199
  19. Very specific:

    Prefer sync.RWMutex for read-heavy workloads

    line 201
  20. Very specific:

    Do NOT reach for the package-private getCurvePreferences helper.

    line 213
  21. Distinctive:

    Use structured configuration with validation

    line 229
  22. Distinctive:

    Use OpenTelemetry for distributed tracing

    line 236
  23. Very specific:

    Run make test lint before any commit

    line 243
  24. Very specific:

    Use github.com/rs/zerolog for all logging

    line 245
  25. Very specific:

    Add t.Parallel() to all parallel-safe tests

    line 246
  26. Distinctive:

    Follow the import grouping conventions

    line 247
  27. Distinctive:

    Use meaningful variable and function names

    line 248
  28. Distinctive:

    If you are asked to remove a flag or similar user-visible interface without a prior notice, do not proceed without explicit confirmation.

    line 274
  29. Very specific:

    Use generic package names (util, helper, common)

    line 280
  30. Very specific:

    Commit code that fails make test lint

    line 281
  31. Very specific:

    Use fmt.Print* instead of structured logging

    line 282
  32. Common:

    Commit secrets, credentials, or sensitive data

    line 283
  33. Distinctive:

    Use deprecated or unsafe Go patterns

    line 284
  34. Distinctive:

    Remove existing tests unless they're genuinely invalid

    line 286
  35. Very specific:

    Use Go modules (go.mod) exclusively

    line 290
  36. Distinctive:

    Keep dependencies up-to-date and secure

    line 295
  37. Distinctive:

    Prefer standard library when possible

    line 296
  38. Distinctive:

    Graceful shutdown: Always implement proper cleanup

    line 311
  39. Distinctive:

    Logging consistency: Use structured logging throughout

    line 315

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

Cloudflared

Cloudflare's command-line tool and networking daemon written in Go. Production-grade tunneling and network connectivity services used by millions of developers and organizations worldwide.

Essential Commands

Build & Test (Always run before commits)

# Full development check (run before any commit)
make test lint

# Build for current platform
make cloudflared

# Run all unit tests with coverage
make test
make cover

# Run specific test
go test -run TestFunctionName ./path/to/package

# Run tests with race detection
go test -race ./...

Platform-Specific Builds

# Linux
TARGET_OS=linux TARGET_ARCH=amd64 make cloudflared

# Windows
TARGET_OS=windows TARGET_ARCH=amd64 make cloudflared

# macOS ARM64
TARGET_OS=darwin TARGET_ARCH=arm64 make cloudflared

# FIPS compliant build
FIPS=true make cloudflared

Code Quality & Formatting

# Run linter (38+ enabled linters)
make lint

# Auto-fix formatting
make fmt
gofmt -w .
goimports -w .

# Security scanning
make vet

# Component tests (Python integration tests)
cd component-tests && python -m pytest test_file.py::test_function_name

Notes on linting:

  • .golangci.yaml is configured with new-from-rev and whole-files: true. Touching a file triggers linting of the ENTIRE file, not just the changed hunks. Expect to fix pre-existing issues in files you modify, or add targeted // nolint: <linter> comments with a short justification.
  • Prefer defer func() { _ = resource.Close() }() over defer resource.Close() for io.Closer values whose error truly does not matter — this satisfies errcheck without hiding real failures elsewhere.

Project Knowledge

Package Structure

  • Use meaningful package names that reflect functionality
  • Package names should be lowercase, single words when possible
  • Avoid generic names like util, common, helper

Well-known shared packages

  • crypto/: Single source of truth for TLS curve preferences and other cryptographic primitives shared by every edge-facing transport. Import as cfdcrypto "github.com/cloudflare/cloudflared/crypto" to avoid colliding with the standard library's crypto package. Do NOT duplicate TLS curve or cipher selection logic in other packages.
  • tlsconfig/: Builds the base *tls.Config used for edge connections (CreateTunnelConfig) and loads origin/CA pools. Curve selection is intentionally NOT set here; it is applied per-connection from the crypto/ package so the same config can be cloned and reused across protocols.
  • features/: Runtime feature flags including PostQuantumMode (PostQuantumPrefer = default, PostQuantumStrict = --post-quantum).
  • fips/: Build-tag driven FIPS detection. Only fips.IsFipsEnabled() is exposed; never branch on fipsEnabled inside a function if the two branches return the same value.

Function and Method Guidelines

// Good: Clear purpose, proper error handling
func (c *Connection) HandleRequest(ctx context.Context, req *http.Request) error {
    if req == nil {
        return errors.New("request cannot be nil")
    }
    // Implementation...
    return nil
}

Error Handling

  • Always handle errors explicitly, never ignore them
  • Use fmt.Errorf for error wrapping
  • Create meaningful error messages with context
  • Use error variables for common errors
// Good error handling patterns
if err != nil {
    return fmt.Errorf("failed to process connection: %w", err)
}

Logging Standards

  • Use github.com/rs/zerolog for structured logging
  • Include relevant context fields
  • Use appropriate log levels (Debug, Info, Warn, Error)
logger.Info().
    Str("tunnelID", tunnel.ID).
    Int("connIndex", connIndex).
    Msg("Connection established")

Testing Patterns

  • Use github.com/stretchr/testify for assertions
  • Test files end with _test.go
  • Use table-driven tests for multiple scenarios
  • Always use t.Parallel() for parallel-safe tests
  • Use meaningful test names that describe behavior
func TestMetricsListenerCreation(t *testing.T) {
    t.Parallel()
    // Test implementation
    assert.Equal(t, expected, actual)
    require.NoError(t, err)
}

Constants and Variables

const (
    MaxGracePeriod       = time.Minute * 3
    MaxConcurrentStreams = math.MaxUint32
    LogFieldConnIndex    = "connIndex"
)

var (
    // Group related variables
    switchingProtocolText = fmt.Sprintf("%d %s", http.StatusSwitchingProtocols, http.StatusText(http.StatusSwitchingProtocols))
    flushableContentTypes = []string{sseContentType, grpcContentType, sseJsonContentType}
)

Type Definitions

  • Define interfaces close to their usage
  • Keep interfaces small and focused
  • Use descriptive names for complex types
type TunnelConnection interface {
    Serve(ctx context.Context) error
}

type TunnelProperties struct {
    Credentials    Credentials
    QuickTunnelUrl string
}

Key Architectural Patterns

Context Usage

  • Always accept context.Context as first parameter for long-running operations
  • Respect context cancellation in loops and blocking operations
  • Pass context through call chains

Concurrency

  • Use channels for goroutine communication
  • Protect shared state with mutexes
  • Prefer sync.RWMutex for read-heavy workloads
  • *tls.Config values stored in shared maps (e.g. TunnelConfig.EdgeTLSConfigs) must be Clone()d before mutating per-connection fields like CurvePreferences or NextProtos. Writing through the shared pointer races with concurrent connection attempts.

TLS & Post-Quantum key exchange

  • Per-connection TLS configuration for edge connections is built via cfdcrypto.TLSConfigWithCurvePreferences(tlsConfig, pqMode). It clones the provided *tls.Config and sets CurvePreferences based on pqMode, so callers never need to clone or mutate CurvePreferences themselves. Do NOT reach for the package-private getCurvePreferences helper; the exported TLSConfigWithCurvePreferences is the only supported entry point.
  • Two PQ modes are supported and apply identically to QUIC and HTTP/2:
    • PostQuantumPrefer (default): [X25519MLKEM768, P256Kyber768Draft00, CurveP256]
    • PostQuantumStrict (--post-quantum): [X25519MLKEM768, P256Kyber768Draft00]
  • FIPS and non-FIPS builds use the same curve list. Do NOT reintroduce a fipsEnabled branch in curve-selection code; if the two modes ever diverge, express the divergence inside crypto/ so call sites remain untouched.
  • HTTP/2 supports post-quantum handshakes. Never re-add a PostQuantumStrict-based rejection to H2 code paths, and never force --post-quantum to select QUIC-only in protocol selection.

Configuration

  • Use structured configuration with validation
  • Support both file-based and CLI flag configuration
  • Provide sensible defaults

Metrics and Observability

  • Instrument code with Prometheus metrics
  • Use OpenTelemetry for distributed tracing
  • Include structured logging with relevant context

Boundaries

✅ Always Do

  • Run make test lint before any commit
  • Handle all errors explicitly with proper context
  • Use github.com/rs/zerolog for all logging
  • Add t.Parallel() to all parallel-safe tests
  • Follow the import grouping conventions
  • Use meaningful variable and function names
  • Include context.Context for long-running operations
  • Close resources in defer statements

⚠️ Ask First Before

  • Adding new dependencies to go.mod
  • Modifying CI/CD configuration files
  • Changing build system or Makefile
  • Modifying component test infrastructure
  • Adding new linter rules or changing golangci-lint config
  • Making breaking changes to public APIs
  • Changing logging levels or structured logging fields

Breaking Change Policy

Removing or renaming a CLI flag, environment variable, configuration key, alias, or subcommand is a breaking change and requires advance notice:

  1. A new entry must be added to the Cloudflare Tunnel changelog and published in a release at least 3 months before the removal takes effect.
  2. The entry must name every affected flag/alias/env var, state the planned removal date or release, and describe the migration path.
  3. The actual removal PR must not be merged until that notice has shipped in a released version.

If you are asked to remove a flag or similar user-visible interface without a prior notice, do not proceed without explicit confirmation.

🚫 Never Do

  • Ignore errors without explicit handling (_ = err)
  • Use generic package names (util, helper, common)
  • Commit code that fails make test lint
  • Use fmt.Print* instead of structured logging
  • Commit secrets, credentials, or sensitive data
  • Use deprecated or unsafe Go patterns
  • Skip testing for new functionality
  • Remove existing tests unless they're genuinely invalid

Dependencies Management

  • Use Go modules (go.mod) exclusively
  • Resolve dependencies from the locked module graph with go mod download; do not vendor dependencies.
  • Builds, tests, vet, and lint use -mod=readonly; go.mod and go.sum must not drift in CI.
  • Linux CI uses Athens before public and direct module sources; macOS and Windows use the public proxy directly.
  • CI caches modules in $GOMODCACHE and compiled packages in $GOCACHE under .cache/go/ for Go-running jobs.
  • Keep dependencies up-to-date and secure
  • Prefer standard library when possible
  • Cloudflared uses a fork of quic-go always check release notes before bumping this dependency.

Security Considerations

  • FIPS compliance support available
  • Vulnerability scanning integrated in CI
  • Credential handling follows security best practices
  • Network security with TLS/QUIC protocols
  • Regular security audits and updates
  • Post quantum encryption

Common Patterns to Follow

  1. Graceful shutdown: Always implement proper cleanup
  2. Resource management: Close resources in defer statements
  3. Error propagation: Wrap errors with meaningful context
  4. Configuration validation: Validate inputs early
  5. Logging consistency: Use structured logging throughout
  6. Testing coverage: Aim for comprehensive test coverage
  7. Documentation: Comment exported functions and types

Remember: This is a mission-critical networking tool used in production by many organizations. Code quality, security, and reliability are paramount.

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.