Clank is an agent-oriented programming language where AST JSON is canonical. Submit programs as JSON, receive structured compiler feedback with machine-actionable repairs.
Clank treats the compiler as a repair engine. When errors occur, it provides ranked repair candidates with machine-applicable patches.
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 }" }
}]
} 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"]
}]
} 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" },
...
}
}]
} 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');
}
}"
}
} Traditional compilers are designed for humans. Clank is designed for the way agents actually work.
Machine-actionable repairs mean agents spend fewer cycles guessing at fixes
Catch bugs at compile time with types like Int{x > 0}
JSON in, JSON out. No parsing errors, no ambiguous syntax
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."
"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."
"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."
"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."
See how Clank helps agents write correct code
{ "kind": "ident", "name": "helo" } {
"title": "Rename 'helo' to 'hello'",
"confidence": "high",
"edits": [{
"op": "rename_symbol",
"old_name": "helo",
"new_name": "hello"
}]
} "message": "Cannot assign to immutable 'x'"
"code": "E2013" {
"title": "Make 'x' mutable",
"safety": "behavior_preserving",
"edits": [{
"op": "replace_node",
"new_node": { "mutable": true, ... }
}]
} 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