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

Every other Coax-implementation OpenAgents book (eight of the nine books; the ninth, Reverse Engineering Claude Code, is a companion TypeScript codebase study) is written in Coax and assumes Parts I–III of this one. See the OpenAgents books for the whole library and the order to read it in.

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, the initial native LP64 profile of tagged unions, optionals and handled direct Results, exhaustive selection, fixed arrays, writable and read-only 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 in an application or reusable library, including direct build and binding code. Each recorded consumer uses an identified source or generated interface described below. Tests, examples and fixtures do not count as adoption. 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.

Status describes the chapter's named teaching profile. An implemented chapter can also explain a planned extension: chapters 5 and 7 teach the initial native LP64 sums, direct Results, optionals and cleanup while naming their remaining containment, generic, effect and target limits. Chapter counts therefore measure recorded teaching coverage. They do not measure completion of the language specification, a whole product or every target.

Recorded direct consumers

These are selected source-to-consumer relationships, not an exhaustive usage inventory. Adding one records use; it does not extend qualified_targets or turn a library's bounded profile into the full chapter goal.

ChapterSource and direct use outside this book
8. Generics`coax/lib/bounded.coax` supplies fixed-storage Bounded values to `psionic/lib/shadow.coax`'s model registry and `metaverse/fairy-forest/forest.coax`'s blooms. It does not supply owning containers.
17. GPU programsThe iOS app's `generate.sh` emits its component and composition shaders as Metal with coax metal. This is the existing graphics shader path; it does not qualify every GPU profile in the chapter.
19. Builds`coax/build.sh`, `coax/web/tool.sh`, `coax/web/wasm.sh` and `coax/web/serve.sh` are invoked directly by `apps/openagents-ios/generate.sh`, `apps/openagents-desktop/build.sh`, `apps/openagents-desktop/install.sh`, `apps/openagents-web/build.sh` and `gamebuilder/web/build.sh`. build.coax and live hot reload remain planned.
25. Voice`metaverse/platform/voice.c` directly calls the generated C interfaces of metaverse/voice.coax, voice-wire.coax, voice-floor.coax and voice-meter.coax. The chapter's smaller ch25_* examples remain teaching programs.
26. Libraries`coax/lib/sequence.coax` is loaded by `metaverse/gpu/everglade-pass.coax` to reverse diagnostic digits and by `psionic/lib/serve-engine.coax` to swap bytes during HTTP buffer rotation. These are synchronous caller-owned operations.
29. Frames`metaverse-engine/cam/spacecam.coax` uses typed world points and a floating origin; `panda-fk-types.coax` and `panda-fk-math.coax` use typed world positions and affine offsets. The chapter identifies the remaining untyped transforms, joints and spacecraft states.
30. Clocks`coax/lib/clock.coax` is loaded directly by `metaverse-engine/space/ephemeris.coax` for typed UTC/TAI/TT/TDB instants. Compiler-enforced clock effects and task @rate remain planned.
41. Budgets`coax/web/wasm.sh`'s per-step cache and report driver are invoked by `apps/openagents-web/build.sh`, `gamebuilder/web/build.sh`, `coax/native/generate.sh` and `metaverse/gpu/everglade-pass.coax`. R22's general startup and kernel budgets remain planned.

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.

Completion route

The current route through chapters 1–28 and chapter 29's affine section is usable now. Completing the rest proceeds through the existing roadmap and chapter gates. The order below is a priority order; a slice can proceed when its own prerequisites and consumer are ready.

  1. Keep the current guide complete for its bounded profile. Reconcile chapters 5–10, 17, 22 and 27 with delivered language and compiler changes; retain exact examples, diagnostics and the limits in chapter 23. Keep source, target evidence and direct adoption separate in the registry and the paths through all nine books.
  2. Finish shared application contracts. Close the roadmap's remaining R0 device, frame-tail, development-loop and independent-review gates. Chapters 6, 7, 15, 20 and 24 now join handled Results, the real file adapter and System One/Lab request ownership. Their bounded native profile and component adoption are distinct from whole-desktop/device readiness; see the request closure qualification. Its cache/origin and final query scopes have zero survivors; the v6 native, fixedpoint, authored and actual-cost gates pass. Whole-desktop E0381 and normal release/cache gates retain their separate scope. Extend chapter 17 only with named GPU resource, layout and artifact evidence. The shipped bounded generics, modules and borrow diagnostics remain the starting point.
  3. Build physical-world facilities through the shared consumers. Complete chapters 29–37 in their dependency order, using the Metaverse realm, Psionic's Panda loop and the spacecraft scenario. Frames and clocks lead to bounded control, strict integrators and replay, then model import, stamps, supervision, faults and provenance. Chapters 38 and 39 become worked capstones when those consumers meet their gates; the same facilities support the OpenAgents Metaverse Engine's physics and space chapters.
  4. Give one solver the compute forms. Complete chapters 40–43 through the Metaverse Engine's solver state and Psionic's existing compute consumers: two layouts and batch sizes first, then measured compilation/cache budgets, graph and buffer ownership, and independently checked derivatives.
  5. Finish the supported toolchain on measured evidence. Chapter 44 needs a clean bootstrap of real applications and an explicit trust boundary. Chapters 45 and 46 need a useful unchanged-layout experiment before transactional migration. Chapter 47 remains conditional on a measured backend bottleneck. These tracks can overlap earlier work under the roadmap's dependency rules.

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 write current Coax, build a playable realm, run an original model, train a small model or sign and verify a Nostr event, see Paths through all nine books.