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 Six Laws

Research-validated principles for AI code generation

1

Separation

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

2

Contract Complete

Define COMPLETE boundaries that uniquely determine implementation

3

Context Economy

Read map → signatures → implementation (only if needed)

4

Decompose First

Break complex tasks into sub-functions before implementing

5

Verify Reflectively

If fail: Reflect (why?) → Fix → Verify again

6

Integrate Fully

Verify all feature paths connect; local correctness ≠ global correctness

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 — Smart Guard runs static + doctests
@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.

Three Verification Levels

Choose depth based on your needs

$ invar guard --quick # STATIC: rules only
✓ Static analysis passed
$ invar guard # STANDARD: rules + doctests (default)
✓ Static analysis passed
✓ Doctests passed
$ invar guard --prove # PROVE: + CrossHair verification
✓ Static analysis passed
✓ Doctests passed
✓ CrossHair verified

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