Logo
FrontierNews.ai

Cloudflare's Engineering Codex: How One Company Built an AI Rulebook That Blocks 16,000 Bad Code Merges

Cloudflare has built an internal system called the Codex that lets AI agents enforce engineering standards across the company's codebase. Over four months, the system flagged nearly 250,000 violations of Cloudflare's engineering rules and blocked 16,000 code merges from being completed. The Codex represents a shift in how large organizations manage technical quality: instead of relying on human reviewers to catch every mistake, the company created a shared source of engineering guidance that both people and AI agents can understand and apply automatically.

What Problem Does the Codex Solve?

Before building the Codex, Cloudflare's engineering guidance lived scattered across many places: formal documentation, repository files, chat threads, and the personal knowledge of individual engineers. This fragmentation created real problems. Engineers spent significant time searching for answers instead of solving the problems they were hired to tackle. Even when they found guidance, they couldn't always tell if it was current, authoritative, or relevant to their specific situation. As Cloudflare grew, this model became unsustainable. No single engineer could read every standard, and code reviewers couldn't reliably check every requirement.

The company also faced institutional knowledge loss when people moved between teams, and inconsistent enforcement of standards led to drift between projects. Cloudflare needed a way to make its engineering standards machine-readable and automatically enforceable.

How Does the Codex Actually Work?

The Codex is organized into distinct domains covering different engineering areas: architectural matters like frontend and control plane systems, cross-cutting concerns such as security and reliability, and language-specific standards for TypeScript and Rust. Each domain has an owner responsible for the content and quality of the standards in that area.

Standards are written in a Request for Comments (RFC) format, a formal structure borrowed from internet standards development. Requirements use specific keywords defined by RFC 2119: "SHOULD" for recommendations and "MUST" for hard requirements. When an engineer proposes a new standard, it goes through multiple rounds of feedback from an increasingly broad group of reviewers before the domain owner gives final approval.

Once approved, the RFC becomes part of the Codex and is published to an internal website. Cloudflare then converts the human-readable RFCs into a structured JSON format that AI agents can understand and apply. This conversion step is critical: instead of feeding the entire Codex to a language model (LLM) as raw text, which would overwhelm the model's context window, Cloudflare extracts just the key statements and enriches them with metadata that helps agents find the most relevant rules.

How Are the Codex Standards Enforced?

Three AI agents currently use the Codex to review different parts of the engineering lifecycle. The AI code reviewer evaluates merge requests across multiple dimensions, including whether the code complies with Codex standards. The spec reviewer agent checks technical designs against the same standards before implementation begins. A third agent reviews incident reports.

The distinction between "SHOULD" and "MUST" statements determines how strictly the system enforces each rule. Findings from approved RFCs are non-blocking recommendations that don't prevent code from being merged. Once an RFC is promoted to "enforced" status, violations of "MUST" requirements cause the reviewer to withhold approval or block the merge entirely, depending on severity.

Since the Codex launched earlier this year, the AI code reviewer has flagged close to 230,000 violations. Of those, almost 16,000 referred to "MUST" statements on enforced RFCs and actually blocked merges. The spec reviewer agent has evaluated close to 600 technical designs against Codex standards before implementation began.

Ways to Speed Up Code Review and Reduce Friction

Cloudflare recognized that waiting for the AI code reviewer to complete its analysis added delay to the development process. A single review run usually takes a couple of minutes due to the complexity of the system. To reduce friction, the company implemented multiple approaches:

  • Custom Linter Packages: For language-specific Codex requirements that can be verified mechanically, Cloudflare created custom linter configuration packages aligned with the Codex specification. These surface problems in milliseconds rather than minutes. TypeScript was the first language to receive Codex linter support, using oxlint for performant execution. A Rust linter is currently under development, with Go planned to follow.
  • Local CLI Tool: To eliminate the continuous integration (CI) leg from the review cycle, Cloudflare made it possible to run the AI code reviewer locally through a command-line interface (CLI). Engineers can run the same agents on their machine before pushing code, getting feedback instantly without waiting for CI to complete.
  • Separate Enforcement Promotion: Approved RFCs produce non-blocking findings, but they only block merges after explicit promotion to "enforced" status. This separate step gives teams time to absorb new requirements and accommodates cases where enforcement needs additional work.

What Does This Mean for Other Companies?

Cloudflare's approach reveals a broader shift in how large organizations manage technical quality at scale. As companies grow, human code review becomes a bottleneck. The Codex model suggests that the future of engineering standards enforcement involves three components: a centralized, machine-readable source of truth; AI agents that can retrieve and apply those standards at the point of work; and multiple enforcement mechanisms (blocking, non-blocking, local, and CI-based) that meet engineers where they work.

The system also demonstrates how to structure AI agents for enterprise use. Rather than giving agents a massive corpus of text to search through, Cloudflare extracted and compacted the key statements into JSON with metadata that supports "lazy discovery and progressive disclosure." This keeps the model's context window manageable and improves the quality of the agent's responses.

The Codex is not a finished product. Cloudflare plans to include additional metadata for even tighter scoping, such as indicators for which software development lifecycle (SDLC) stage a statement applies to, whether that's design, implementation, or runtime. As the company continues to refine the system, it will likely become a template for how other organizations structure AI-assisted engineering governance.