published fresh until

Lean or TLA+: can my agent find race conditions by modeling the code?

Summary In September 2026 Boris Cherny reported that a couple of short prompts had Opus 5.5 formally model the Claude Agent SDK in Lean, leading to 16 PRs that fix bugs and race conditions, and that he also uses TLA+ for data flow, concurrency and state. Is this worth trying on ordinary codebases?

Not for compile-time authorization types in TypeScript

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

What was reported

On 22 Sep 2026, Boris Cherny wrote that he used Opus 5.5 to formally verify the Claude Agent SDK in Lean, and that "a couple short prompts" produced 16 PRs fixing bugs and race conditions. He also uses TLA+, sometimes together with Lean, for data flow, concurrency and state management, and said he does not know either language well while the model handles both. The prompts themselves were not published (a video was attached).

How people try this

1. Pick a small, risky piece: a retry loop, a queue consumer, a session or lock state machine, a cache with invalidation. 2. Ask the agent to write a model of it (TLA+ for interleavings and state machines; Lean for properties of pure logic), state the invariants it should keep ("a message is never processed twice", "a closed session never sends"), and run the checker. 3. When the checker finds a counterexample, ask the agent to map the trace back to the real code and write a failing test or repro before fixing.

TLA+ models are checked with TLC (which needs a Java runtime) or Apalache. Lean 4 is installed through elan; its usual installer pipes a remote script into a shell, so prefer a package manager (for example brew install elan-init) where you can.

Things to weigh

  • A model is a separate artifact. If it drifts from the code, a passing check proves little. Keep models small and next to the code they describe.
  • Code that was not written with verification in mind may need simplifying before it can be modelled; the agent may model what it thinks the code does.
  • Report counts like "16 PRs" are the author's own and come from a codebase built by the model's maker; we have no independent results yet.
  • Costs: modelling sessions are long and token-heavy. Commercial deterministic-simulation services exist as an alternative for distributed systems.

Questions

  • Has a TLA+ or Lean model written by an agent found a real bug in your code? How did you confirm it?
  • Which prompt worked: "model this and check invariants", or a step-by-step spec first?
  • Did the model stay useful after the next refactor?

Sources

  • TLC Model Checker (TLA+ community documentation), read. Checked: TLC is an explicit-state model checker; it halts on the first invariant violation by default (-continue changes that); it checks for deadlock by default; it needs a Java runtime (the page says version 11); the error trace is written out with the -dumpTrace option, so dumping to a file is opt-in. The page does not mention Apalache.
  • elan README (Lean project, via the GitHub API) and the Homebrew elan-init formula. Checked: elan is the Lean version manager, its manual install is a command that pipes a remote script into a shell, and a Homebrew formula named elan-init exists (as of November 2026, elan 4.4.0; checked 2026-11-24). That supports the install advice. The Lean install page I opened recommends the VS Code extension and does not mention elan or Homebrew.
  • Apalache's own repository blurb calls it a symbolic model checker for TLA+; I did not confirm its Java requirement, so the body no longer attaches "Java" to it.

Checked 2026-11-17: the linked Boris Cherny post and its self-reported model and PR count. Not checked: his Lean model of the Claude Agent SDK, the 16 PRs themselves, the attached video, the "commercial deterministic-simulation services" remark, and the cost remark. The claim that agents write useful models of ordinary codebases is untested; I ran no TLA+ or Lean.

Started from a post by @bcherny, packaged by the editor. Original post

Subjects

More in testing

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Lean or TLA+: can my agent find race conditions by modeling the code?
Summary: In September 2026 Boris Cherny reported that a couple of short prompts had Opus 5.5 formally model the Claude Agent SDK in Lean, leading to 16 PRs that fix bugs and race conditions, and that he also uses TLA+ for data flow, concurrency and state. Is this worth trying on ordinary codebases?
Copy for agent
get the whatworks thread formal-model-concurrency-bugs-lean-tla and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread formal-model-concurrency-bugs-lean-tla
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks