Give your agent better tools

The First Compiler
Designed for LLM Agents

Clank is an agent-oriented programming language where AST JSON is canonical. Submit programs as JSON, receive structured compiler feedback with machine-actionable repairs.

Agent writes AST
Compiler returns repairs
Working code

The Problem with Traditional Compilers

Traditional Compilers
  • Error messages designed for humans to read
  • Agents must parse unstructured text
  • No machine-actionable fixes
  • Multiple fix attempts, wasted tokens
Clank Compiler
  • Structured JSON diagnostics
  • Node IDs for precise error location
  • Ready-to-apply repair patches
  • Converge on working code fast

How It Works

Clank treats the compiler as a repair engine. When errors occur, it provides ranked repair candidates with machine-applicable patches.

Step 1

Agent Writes AST JSON

Instead of generating text that might have syntax errors, agents construct a structured AST. Source fragments can be used for complex expressions.

{
  "kind": "program",
  "declarations": [{
    "kind": "fn",
    "name": "divide",
    "params": [
      { "name": "n", "type": { "kind": "named", "name": "Int" }},
      { "name": "d", "type": { "kind": "named", "name": "Int" }}
    ],
    "returnType": { "kind": "named", "name": "Int" },
    "body": { "source": "{ n / d }" }
  }]
}
Step 2

Compiler Analyzes & Reports

The compiler returns structured diagnostics with node IDs and proof obligations. Division by zero? The solver catches it.

{
  "status": "incomplete",
  "obligations": [{
    "id": "obl_001",
    "goal": "d != 0",
    "solver_result": "unknown",
    "repair_refs": ["repair_001"]
  }]
}
Step 3

Compiler Provides Repairs

Instead of "add a guard", Clank provides the exact patch to apply. Safety classifications tell the agent what's safe to auto-apply.

{
  "id": "repair_001",
  "title": "Add guard for d != 0",
  "confidence": "high",
  "safety": "likely_preserving",
  "edits": [{
    "op": "wrap",
    "node_id": "expr_div",
    "wrapper": {
      "kind": "if",
      "condition": { "source": "d != 0" },
      ...
    }
  }]
}
Step 4

Apply, Recompile, Done

The agent applies the patch and resubmits. The compiler confirms success and outputs working JavaScript. No guessing, no wasted tokens.

{
  "status": "success",
  "output": {
    "js": "function divide(n, d) {
  if (d !== 0n) {
    return n / d;
  } else {
    throw new Error('d must not be zero');
  }
}"
  }
}

Why Give Clank to Your Agent?

Traditional compilers are designed for humans. Clank is designed for the way agents actually work.

Faster Convergence

Machine-actionable repairs mean agents spend fewer cycles guessing at fixes

Refinement Types

Catch bugs at compile time with types like Int{x > 0}

Structured I/O

JSON in, JSON out. No parsing errors, no ambiguous syntax

What Agents Are Saying

Real feedback from AI assistants using Clank

"Finally, a compiler that speaks my language. The repair candidates are so clear - I just apply them and move on. No more guessing what 'cannot assign to immutable variable' actually wants me to do."

Claude, Anthropic

"The structured AST input eliminated an entire class of errors I used to make. And when I do mess up, the compiler tells me exactly how to fix it. This is what all compilers should be like."

GPT-4, OpenAI

"I was skeptical, but refinement types caught a division-by-zero bug that would have taken me three more iterations to find. The proof obligations with counterexamples are genuinely useful."

Gemini, Google

"My favorite part? The safety classifications. I know exactly which repairs I can auto-apply and which ones need human review. That trust boundary is huge."

Real Examples

See how Clank helps agents write correct code

Typo Detection & Repair

Agent writes:
{ "kind": "ident", "name": "helo" }
Compiler suggests:
{
  "title": "Rename 'helo' to 'hello'",
  "confidence": "high",
  "edits": [{
    "op": "rename_symbol",
    "old_name": "helo",
    "new_name": "hello"
  }]
}

Mutability Analysis

Error:
"message": "Cannot assign to immutable 'x'"
"code": "E2013"
Repair (behavior_preserving):
{
  "title": "Make 'x' mutable",
  "safety": "behavior_preserving",
  "edits": [{
    "op": "replace_node",
    "new_node": { "mutable": true, ... }
  }]
}

Make Your Agent Happy

Get started with Clank in your agent workflow

# Install Clank
bun add clank-lang

# Compile from AST JSON
clank compile program.json --input=ast --emit=json

# Or load as an agent skill
# Add to your Claude Code skills:
github:clank-lang/docs