Don't Hope AI Code Is Correct.
Know It.

You use AI to write code. How do you know it's correct?

Invar makes AI prove its code is correct through contracts, verification, and mechanical checks.

The Four Laws

These laws shape how AI writes and organizes code

1

Separation

Pure logic (Core) and I/O (Shell) must be physically separate

2

Contract First

Define boundaries (@pre/@post) before implementation

3

Context Economy

Read map → signatures → implementation (only if needed)

4

Verify Immediately

Run invar guard && pytest after every change

The Workflow: ICIDIV

AI follows this workflow for every task

I
Intent
C
Contract
I
Inspect
D
Design
I
Implement
V
Verify

Example — You: "Add a function to calculate discounted price"

IntentCore function (pure logic, no I/O)
Contract@pre: price > 0, discount ∈ [0,1]. @post: result ≥ 0
Inspectinvar sig — check existing patterns
DesignFile size OK, no extraction needed
ImplementWrite code with contracts and doctest
Verifyinvar guard && pytest — all pass
@pre(lambda price, discount: price > 0 and 0 <= discount <= 1) @post(lambda result: result >= 0) def discounted_price(price: float, discount: float) -> float: """ >>> discounted_price(100, 0.2) 80.0 """ return price * (1 - discount)

Why This Works

Contracts are written by AI, not by you. You don't review every one.

🎯 Constraints Produce Quality

Without constraints, AI writes code that "looks right." With constraints, AI must think through boundaries before writing — this thinking process itself reduces bugs.

🔄 Verification Feedback Loop

AI can't ignore edge cases because Guard catches them. Violations are fixed before you even notice.

See It In Action

Three commands to get started

$ pip install python-invar
Successfully installed python-invar
$ invar init
Created INVAR.md, CLAUDE.md, .pre-commit-config.yaml
$ invar guard
Code Health: 100% ████████████████████

Quick Start

1

Install

pip install python-invar
2

Initialize

invar init
3

Use AI

AI follows INVAR.md

Configure Your AI Tool

Claude Code
Automatic
Cursor
Rules → INVAR.md
Others
System prompt