Building a C compiler with a team of parallel Claudes

13 min readadvanced
--
View Original

Overview

Nicholas Carlini from Anthropic's Safeguards team describes how he built a 100,000-line Rust-based C compiler using 16 parallel Claude agent instances working autonomously on a shared codebase. The compiler can build a bootable Linux 6.9 kernel on x86, ARM, and RISC-V, and was produced over nearly 2,000 Claude Code sessions at a cost of $20,000. The article focuses on the design of harnesses for long-running autonomous agent teams, including testing strategies, parallelization techniques, and the practical limits of this approach.

What You'll Learn

1

How to design harnesses for long-running autonomous LLM agent teams that can work without human oversight

2

How to structure work so multiple AI agents can make progress in parallel on a shared codebase using git-based synchronization

3

Why writing high-quality tests is critical for autonomous agent workflows and how to design test harnesses specifically for LLMs

4

How to use a known-good compiler oracle technique to enable parallel debugging of a single monolithic task like kernel compilation

5

When agent teams hit their ceiling and what limitations to expect from fully autonomous LLM development

Prerequisites & Requirements

  • Understanding of compiler architecture concepts (parsing, code generation, SSA IR, optimization passes)
  • Familiarity with git workflows including branching, merging, and conflict resolution
  • Experience with Docker containers for isolated development environments
  • Understanding of LLM agent scaffolding concepts and Claude Code
  • Experience with CI/CD pipelines and automated testing infrastructure(optional)

Key Questions Answered

How can multiple Claude AI agents work in parallel on the same codebase?
A bare git repo is created with Docker containers for each agent. Each agent clones a local copy to /workspace and pushes to /upstream when done. Task locking is achieved by writing text files to a current_tasks/ directory — git's synchronization forces the second agent claiming the same task to pick a different one. Agents pull, merge, push changes, and remove locks between tasks.
How do you keep autonomous AI agents running continuously without human intervention?
A simple bash loop runs Claude Code indefinitely with the --dangerously-skip-permissions flag, feeding it an agent prompt from a markdown file. When Claude finishes one task, the loop immediately spawns a new session. The agent prompt instructs Claude to break problems into small pieces, track progress, figure out what to work on next, and keep going until the work is complete.
How much does it cost to build a C compiler using AI agents?
The project consumed 2 billion input tokens and generated 140 million output tokens across nearly 2,000 Claude Code sessions over two weeks, totaling just under $20,000 in API costs. This produced a 100,000-line Rust-based C compiler capable of compiling Linux 6.9 on x86, ARM, and RISC-V architectures.
How do you prevent parallel AI agents from duplicating each other's work?
A file-based locking mechanism uses a current_tasks/ directory where each agent claims tasks by writing text files. Git synchronization ensures that if two agents try to claim the same task, the second one must pick a different task. For monolithic tasks like kernel compilation, a known-good compiler oracle (GCC) is used to randomly split files, letting each agent debug different files in parallel.
What are the limitations of AI-generated compilers compared to human-written ones?
The AI-generated compiler lacks a 16-bit x86 code generator needed for real mode booting, doesn't have its own assembler and linker, can't compile all projects as a drop-in GCC replacement, produces less efficient code than GCC even with optimizations disabled, and the Rust code quality is reasonable but below expert level. New features frequently broke existing functionality.
How should you design test suites specifically for autonomous AI agent development?
Tests should avoid printing thousands of useless bytes that pollute the context window. Log important information to files with ERROR on the same line as the reason so grep finds it. Pre-compute aggregate summary statistics. Include a --fast option running a deterministic 1-10% random sample per agent but random across VMs so all files get covered while each agent can quickly identify regressions.
What specialized roles can parallel AI agents take on in a development team?
Beyond solving the main problem, specialized agents can be assigned roles including: coalescing duplicate code that LLMs frequently produce, improving compiler performance, optimizing generated code output, critiquing project design from a language expert's perspective and making structural improvements, and maintaining documentation. This specialization leverages parallelism beyond just splitting the primary task.
How did Claude's compiler capabilities evolve across model generations?
Previous Opus 4 models could barely produce a functional compiler. Opus 4.5 was the first to cross the threshold of producing a compiler that could pass large test suites, but couldn't compile real large projects. Opus 4.6 pushed further, producing a 100,000-line compiler that can build Linux 6.9, compile QEMU, FFmpeg, SQLite, PostgreSQL, Redis, and achieve a 99% pass rate on GCC torture tests.

Key Statistics & Figures

Number of parallel agents
16
Claude instances working simultaneously on the shared codebase
Total Claude Code sessions
~2,000
Over the entire project duration of approximately two weeks
Total API cost
$20,000
Just under $20,000 for the entire project
Input tokens consumed
2 billion
Total input tokens across all sessions
Output tokens generated
140 million
Total output tokens across all sessions
Compiler codebase size
100,000 lines
Rust-based C compiler produced by the agent team
Test suite pass rate
99%
On most compiler test suites including the GCC torture test suite
Target architectures supported
3
x86, ARM, and RISC-V
Linux kernel version compiled
6.9
Bootable Linux kernel built by the AI-generated compiler

Technologies & Tools

Some links below are affiliate links. We may earn a commission if you make a purchase.

AI Agent Framework
Claude Code
Primary agent interface for autonomous code generation and modification
AI Model
Claude Opus 4.6
LLM powering the agent team that wrote the compiler
Programming Language
Rust
Implementation language for the C compiler
Compiler
Gcc
Used as a known-good oracle for comparison and for 16-bit x86 bootstrapping
Containerization
Docker
Isolated containers for each parallel agent instance
Version Control
Git
Synchronization mechanism between parallel agents and task locking
Operating System
Linux
Target compilation — Linux 6.9 kernel used as the primary benchmark
Scripting
Bash
Agent loop harness for continuous autonomous operation
Emulator
Qemu
One of the real-world projects successfully compiled by the AI-generated compiler
Multimedia Framework
Ffmpeg
One of the real-world projects successfully compiled by the AI-generated compiler
Database
Sqlite
One of the real-world projects successfully compiled by the AI-generated compiler
Database
Postgresql
One of the real-world projects successfully compiled by the AI-generated compiler
Database
Redis
One of the real-world projects successfully compiled by the AI-generated compiler

Key Actionable Insights

1
Design your test harness output specifically for LLM consumption, not human consumption. Minimize verbose output that pollutes the context window, log detailed information to files with easily greppable error patterns (e.g., ERROR on the same line as the reason), and pre-compute aggregate statistics so the agent doesn't waste tokens re-computing them.
LLMs have context window limitations and time blindness, so the testing infrastructure needs to be optimized for machine processing rather than human readability.
2
Use a known-good oracle to decompose monolithic tasks into parallelizable subtasks. When agents get stuck on a single large task (like compiling a kernel), use a reference implementation to randomly assign portions of work, allowing each agent to isolate and fix different bugs independently.
Without this technique, all 16 agents hit the same bug, fixed it independently, and overwrote each other's changes, making parallelism useless for monolithic tasks.
3
Implement file-based task locking through git synchronization to prevent duplicate work across parallel agents. Each agent claims a task by writing a file to a shared directory, and git's merge semantics naturally resolve conflicts when two agents attempt the same task.
This approach is deliberately bare-bones and avoids complex orchestration agents or communication protocols, relying instead on git's existing synchronization guarantees.
4
Have autonomous agents maintain extensive README and progress files that are updated frequently, so each new agent session (which starts with no context) can quickly orient itself on the project's current state and determine what to work on next.
Each agent is dropped into a fresh container with no prior context, so self-maintained documentation becomes the primary mechanism for knowledge transfer between sessions.
5
Build a CI pipeline with strict regression enforcement as the project matures. Near the end of the project, Claude frequently broke existing functionality when implementing new features, so stricter automated testing that prevents commits from breaking existing code became essential.
This is especially important for autonomous agents that lack the intuition a human developer has about which changes might cause regressions in seemingly unrelated areas.
6
Assign specialized roles to different parallel agents rather than having all agents work on the same primary task. Dedicate specific agents to code deduplication, performance optimization, code quality review, and documentation to maintain overall project health.
LLM-written code frequently re-implements existing functionality, making a dedicated deduplication agent particularly valuable in multi-agent workflows.

Common Pitfalls

1
All parallel agents converging on the same bug in a monolithic task, fixing it independently, and then overwriting each other's changes. When compiling the Linux kernel, having 16 agents running provided no benefit because each was stuck solving the identical problem.
The fix was to use a known-good compiler oracle (GCC) to randomly split compilation work, enabling each agent to debug different files in parallel.
2
Allowing test output to pollute the LLM's context window with thousands of useless bytes, causing the agent to lose focus or waste tokens processing irrelevant information. Agents that run unrestricted test suites can spend hours running tests instead of making progress due to time blindness.
Include a --fast option that runs a deterministic random sample (1-10%) per agent, and log detailed results to files rather than printing to stdout.
3
New features frequently breaking existing functionality in the compiler, causing regression cycles where agents fix one thing and break another. This became especially problematic near the end of the project as the codebase grew to 100,000 lines.
Building a CI pipeline with strict regression enforcement that prevents commits from breaking existing code is essential for autonomous agent workflows.
4
LLM-written code frequently re-implementing existing functionality rather than reusing what already exists. Without oversight, agents create duplicate implementations of the same logic across different parts of the codebase.
Dedicate a specialized agent specifically to finding and coalescing duplicate code to maintain codebase health.
5
Assuming that passing tests means the job is done when working with autonomous agents. Deploying software that no human has personally verified carries real security and quality risks that automated tests alone cannot catch.
The author, with a background in penetration testing, highlights this as a fundamental concern with fully autonomous development workflows.

Related Concepts

Llm Agent Scaffolding
Multi-agent Systems
Compiler Design And Implementation
Ssa Intermediate Representation
Autonomous Software Development
Git-based Synchronization
Docker Containerization
CI/CD Pipelines
Delta Debugging
Test-driven Development For AI Agents
Code Generation
X86/Arm/Risc-v Architectures
Gcc Torture Test Suite
Clean-room Implementation
Task Parallelization Strategies