For the complete documentation index, see llms.txt. Markdown versions of documentation pages are available by appending .md to page URLs.
Skip to content

The Coax Programming Language

A draft book, begun October 2026.

This is a book about Coax, the language OpenAgents uses for code that has to be fast and has to be right: the Verse engine and the world it runs, the iPhone app's home screen and Grid, and the money rules in its bitcoin wallet. Coax descends from Jonathan Blow's Jai. It compiles to plain C you can read, it checks arithmetic and array bounds while you develop, and it lets you write checks that the compiler runs for you.

The Introduction explains why Coax exists. If you'd rather start typing, go straight to Chapter 1.

Who this book is for

We assume you've programmed before, in any language. You don't need to know C, though it helps in a few places, and when it does we'll say so. If you know C, C++, Rust or Jai, you'll find notes along the way that compare Coax with what you already know, and two appendices written just for you (Jai, C++).

The book is also written to be read by agents. Most Coax in OpenAgents is written by models, and they read this book the way a new teammate would. That's one reason every error code has an entry in Appendix B, and every rule comes with the reason for it.

How to use this book

Read it in order the first time. Each chapter builds on the ones before, and the early chapters introduce ideas lightly that later chapters cover in depth.

Part I gets you running. Chapter 1 builds the compiler and a first program. Chapter 2 is a small project, an ASCII Mandelbrot renderer, that touches most of the everyday language at once. Chapters 3 and 4 then go back over the basics properly and show how to read the compiler's errors.

Part II covers the language itself: structs and enums, memory, errors and cleanup, generics, compile-time execution, organizing a program into source units and modules, writing checks, and debugging and measuring cost. Part III is about data layout, jobs, asynchronous lifetimes, determinism and the GPU. Part IV is about how Coax fits into OpenAgents: the protocol boundary, builds and hot reload, interop with C, C++ and Swift, targets, tooling for agents, and what verification does and doesn't establish. Part V turns those pieces into larger programs: a runnable protocol-to-native capstone, a voice system built from small checked policies and native boundaries, and small consumers of shared libraries (caller-owned buffers, protocol fixtures and a tiny Psionic CPU operation). Part VI opens up the compiler and ends with the road ahead.

Parts VII–IX describe roadmap work, one chapter per roadmap phase. Most of it doesn't run in coax0 yet: each planned chapter is an outline that says what the phase adds, which program uses it first and what "done" means. Chapter 29 is partly implemented: its affine points and vectors in declared frames run today, in a checked tutorial section. Part VII covers the physical world: units and frames, clocks, bounded control, strict math and integrators, replay, robot models, sensors and actuators, fault scenarios and parameter provenance, then a simulated robot and a freighter scenario built from them. Part VIII covers simulation compute: logical tensors, compile and startup budgets, device graphs and kernel derivatives. Part IX covers the rest of the toolchain: self-hosting, procedure-body replacement, resident compilation and new backends.

The selected library index names reusable entry points, native link inputs and their lifetime/error limits. Chapter 26 supplies small offline consumers.

The best way to learn is to type the examples in and run them. Change them, break them on purpose, and read what the compiler says.

What runs today and what doesn't

Coax is young. Its first compiler, coax0, compiles a real but limited subset of the language: procedures, integers and floats, strings, structs, enums, fixed arrays and views, defer, compile-time #run and #assert, checks with #test and #forall, logical modules and explicit exports, generic procedures and fixed-storage struct templates over type and length parameters with built-in constraints, nominal scalar quantities, affine points and vectors in declared frames, and a C boundary. User-defined constraints, owning containers and other later features remain planned. The generated current status records the bounded implemented subset separately from the full design.

Runnable sections show current source and output. Planned sections are marked separately; when a chapter describes something coax0 cannot compile yet, it uses a note like this:

Note: This feature is planned and not available in coax0. The syntax shown follows the Coax specification and may change before it's built.

Code in planned sections has not been compiled. The runnable examples are checked against the current compiler; elided and illustrative fragments need the surrounding program described in their chapter.

When the book and the compiler disagree, reproduce the case and check the implemented subset and its conformance tests. Either the book or the compiler can have a bug. The specification, coax/spec.md, is the design of record; planned features are not claims about the current compiler.

Chapter status

The chapter registry records every chapter's number, title, status, profile, dependencies and three separate facts:

  • Implemented source (source): the code the chapter shows or runs.

  • Qualified targets (qualified_targets): the targets, such as cpu, cuda, metal or wasm, with recorded evidence for the chapter's profile. Source that might compile for a target doesn't qualify it.

  • Adoption (adopted_by): code outside the book that uses the chapter's code today. An empty list means no adoption is recorded.

A chapter's status is one of implemented, partly implemented, design draft or planned. A planned chapter starts with the planned note shown above, and a partly implemented chapter with **Status: partly implemented.**; the contents and the list below label both. python3 coax/book/check-structure.py fails when a status marker, a contents label, the list below or the registry disagree.

Promoting a draft to a teaching chapter

A design draft or planned chapter becomes a teaching chapter only when it has all four of the following:

  1. A worked calculation or trace. A small input whose result the chapter works out by hand, step by step, before the program runs.

  2. Runnable source. The code and an example in examples/, with an exact transcript that the book's checks compare in debug and release.

  3. A deliberately broken case and its diagnostic. An input or an edit that the code refuses, with the exact error or refusal shown and its exit status checked.

  4. An independent check. A result computed another way, such as a separate oracle, a reference implementation or a hand-derived value, that the checks compare with the code's result.

When all four exist, update the chapter's status in the same commit in four places: the chapter's status marker, its entry in chapters.json, its label in the contents and its label in the list below. The registry check fails when they disagree. Chapter 29's affine section is an example: a hand calculation, examples/ch29_frames.coax, a refused program with E0834, and a #test that compares the result with plain arithmetic.

Where the examples live

Every program the book runs is a file in examples/, next to its exact output in a .out file. The script check-examples.sh in this folder compiles and runs each one and compares the output in debug and release modes. It also runs authored checks, library/host examples and local link checks. Selected source-linked listings are compared with their example files; excerpts and illustrative fragments are not all standalone programs. Programs shown only being compiled have no .out file. Deliberate traps have explicit .status files; mode-specific output or status uses .release.out and .release.status. A matching error message with the wrong exit status is a failure. See Chapter 23 for the limits.

Commands assume you're at the root of the openagents repository, and coax means coax/bin/coax. Chapter 1 shows how to build it and put it on your path.

Contents at a glance

To find a route through the three books (write current Coax, build a playable realm, run an original model or train a small model), see Paths through the books.

Last updated