Skip to content

Create and explore your first project

Inspect the lema.project/v1 manifest and .lema/store created by lema new, add .lema and .lean modules with lema add, compare terminal and --json output, and render Pythonic views with lema view.

In Lesson 2 (Set up a machine for Lema), you ran lema new hello to scaffold a project and start its background server. Now you will look inside the project directory, see how lema.json and .lema/store organize your codebase, publish both a Pythonic .lema module and a .lean module with lema add, and render stored declarations back into Pythonic contract syntax with lema view.

To run these commands live, work inside the hello directory you created in Lesson 2 (with lema on your PATH). If you are reading on macOS or Windows, every command and output is shown in full below.

1. Inspect what lema new created

List the files inside your hello directory, including the hidden .lema/ directory:

Shell
ls -la
ls -la .lema
Output
lema.json
src/
.lema/

.lema/store/
.lema/lema.sock
.lema/lema.pid
.lema/lema.log
.lema/token

Each path has a distinct job in your workflow:

PathWhat it holdsShould you commit or share it?
lema.jsonThe normative project manifest (lema.project/v1), naming the project, namespace, deterministic salt, default ref (main), and ordered module list.Yes, part of your project workspace.
src/Main.leanThe starter module generated by lema new, ready to run on the Lema VM.Yes, authored source files live under src/.
.lema/storeThe content-addressed store holding accepted objects, kernel receipts, contract selections (lema.contract/v1), snapshots (lema.snapshot/v2), and revisions (lema.revision/v1).Export and share via lema export / lema import (Export and import a project).
.lema/lema.sockThe local Unix domain socket where the background lema serve process listens (with automatic short-path fallback if the directory path exceeds the OS socket length limit).No, ephemeral runtime socket.
.lema/lema.log & .lema/lema.pidStandard output/error logs and process ID of the detached background server.No, local server state.
.lema/tokenThe private authentication token (mode 0600) for the default local actor (dev) created by lema new.Never share .lema/token; keep it owner-only (0600).

Why does .lema/store already have 184 accepted objects and 42 aliases before you write a single line of code? Because lema new initializes the store with the namespace object (pinning Lean 4.34.1 and canonical encoding lema-core-v4), imports the pinned v0.2 foundational signature (Core, AppCmd, Frames, and Capability so your modules can immediately use Prog, Contract, and the six capability tags), registers the local actor dev, and creates the initial project reference main under a default lema.policy/v1.

2. Read the lema.json project manifest

Open lema.json:

Shell
cat lema.json
lema.json
{
  "schema": "lema.project/v1",
  "name": "hello",
  "namespace": "Hello",
  "salt": "hello-4f9c2a1b",
  "default_ref": "main",
  "modules": [
    "src/Main.lean"
  ]
}

Here is what each field in lema.project/v1 controls:

  • name and namespace: Names your project (hello) and sets the default authoring namespace prefix (Hello).
  • salt (hello-4f9c2a1b): When a module defines a new inductive type or structure (such as a contract block), Lema uses this project salt alongside the module name to compute a deterministic structure seed. Keep salt unchanged as your project evolves so structure identities remain stable across edits.
  • default_ref (main): The semantic version control reference that commands like lema diff and lema commit target when you do not pass --ref.
  • modules: The topologically ordered list of .lema and .lean files belonging to the project. When you add a new file with lema add, Lema appends it to modules automatically.

3. Add the starter module (lema add) and compare terminal vs. --json output

Look at the starter file src/Main.lean generated by lema new:

src/Main.lean
set_option autoImplicit false
namespace Lema
namespace Hello

def greeting : ByteArray := "hello from lema\n".toUTF8

end Hello
end Lema

Publish src/Main.lean into your project store using lema add:

Shell
lema add src/Main.lean
Output (human-readable terminal summary)
added src/Main.lean
  Hello.greeting  #8f4a21c903e1  (def, checked, 0 axioms)

When you run lema add interactively in a terminal, it prints a concise human summary: the published declaration name (Hello.greeting), a short 12-character prefix of its 64-character SHA-256 declaration ID (#8f4a21c903e1), its kind (def), its kernel verification status (checked), and its axiom count (0 axioms).

What if an AI coding agent such as Claude Code or Codex is running lema add in an automated loop and needs full 64-character SHA-256 IDs and machine-parseable fields? Pass --json (which Lema also enables automatically whenever standard output is piped to another program):

Shell
lema add --json src/Main.lean
Output (--json)
{
  "status": "ok",
  "files": [
    "src/Main.lean"
  ],
  "names": {
    "Hello.greeting": {
      "id": "8f4a21c903e1…",
      "kind": "declaration",
      "flavor": "def",
      "axioms": []
    }
  },
  "stored": 0,
  "receipts": 5
}

Notice that "stored" is 0 on the second run because Hello.greeting was already in .lema/store with the exact same SHA-256 hash (8f4a21c903e1...), so the store deduplicated every object automatically.

4. Add a Pythonic .lema module and see how cross-module imports work

Now create a Pythonic .lema file at src/Counter.lema that defines the advance function and Advances contract claim from Lesson 1:

Shell
cat > src/Counter.lema <<'EOF'
def advance(n: Nat) -> Nat:
    n + 1

def Advances(f: Nat -> Nat) -> Prop:
    forall n: Nat :: f(n) > n

select Advances(advance)
EOF

Add src/Counter.lema to the project with the exact same lema add command:

Shell
lema add src/Counter.lema
Output
added src/Counter.lema
  Hello.advance   #2c91e04b7a12  (def, checked, 0 axioms)
  Hello.Advances  #7d18f53c90e4  (def, checked, 0 axioms)
  select Hello.Advances(Hello.advance)  #b409a812e3f1  (contract, open)

Look at what lema add src/Counter.lema just did for you:

  1. Parsed .lema in Rust (view::parse_module): It parsed advance, Advances, and select Advances(advance) with exact 1-based line and column spans, lowered the declarations to Lean syntax via view::lean_declaration, and sent them to the background server.
  2. Checked both definitions in the Lean 4.34.1 kernel: Both Hello.advance (Nat -> Nat) and Hello.Advances ((Nat -> Nat) -> Prop) were elaborated, exported into canonical objects, and accepted by source-free kernel replay with zero axioms, along with an authoring bundle (lema.authoring/v2) that records their symbolic names and source spans.
  3. Constructed and kernel-checked the contract selection (lema.contract/v1): For select Advances(advance), the store built the closed target proposition T = Hello.Advances Hello.advance, checked theorem : T -> T := fun h => h in the Lean kernel to verify that T is a well-typed Prop, pinned Hello.advance’s exact object ID (#2c91e04b7a12) in target.realizations, and stored an immutable lema.contract/v1 record with status: "open".
  4. Updated lema.json: Added "src/Counter.lema" to the modules list in lema.json. Whenever you pass multiple files to lema add FILE.. or edit a module that downstream project modules reference, lema add topologically orders the modules across the project’s lema.authoring/v2 symbolic bindings and re-adds any downstream modules whose symbolic imports moved.

5. See how caret diagnostics guide you and your coding agent

To see what happens when you or an AI coding agent make a syntax or type error, introduce a deliberate type mistake in src/Counter.lema by passing "bad" (a string) where Nat is expected, or write a quick test edit in src/Main.lean. Suppose an agent writes a function in src/Main.lean that tries to add a string to a Nat:

Deliberate type error in src/Main.lean
def broken (n : Nat) : Nat := n + "oops"

When the agent runs lema add src/Main.lean, Lema maps the Lean elaborator’s line and column span back through the authoring header offset to report the exact location in src/Main.lean:

Output on error
error: src/Main.lean:7:35: failed to synthesize instance HAdd Nat String ?m
  |
7 | def broken (n : Nat) : Nat := n + "oops"
  |                                   ^^^^^^

And if the agent runs lema add --json src/Main.lean, it receives a structured errors array:

Output on error (--json)
{
  "status": "error",
  "errors": [
    {
      "file": "src/Main.lean",
      "line": 7,
      "column": 35,
      "message": "failed to synthesize instance HAdd Nat String ?m"
    }
  ]
}

Because a failed lema add is atomic, no partial or broken objects ever enter .lema/store, and your previous accepted Hello.greeting binding remains untouched.

6. Render stored declarations in Pythonic syntax (lema view)

At any time, you can render any accepted declaration in .lema/store back into canonical Pythonic .lema syntax using lema view:

Shell
lema view Hello.advance Hello.Advances
Output
def Hello.advance(n: Nat) -> Nat:
    n + 1

def Hello.Advances(f: Nat -> Nat) -> Prop:
    forall n: Nat :: f(n) > n

Remember that lema view does not read src/Counter.lema from disk. It reconstructs the Pythonic .lema text directly from the canonical content-addressed objects in .lema/store (crates/lema-core/src/view.rs) and runs view::rederive to confirm that parsing the rendered text reproduces the exact stored object IDs. Even if a declaration was originally written in Lean (src/Main.lean), lema view renders its signature and specification in the same Pythonic .lema format.

7. Check project status and commit your first semantic revision

Run lema status and lema diff to see what your workspace currently holds compared to the main reference:

Shell
lema status
lema diff
Output (lema diff)
ref: main (unborn -> working tree)

exports (added: 3):
  + Hello.greeting   #8f4a21c903e1  (def, checked)
  + Hello.advance    #2c91e04b7a12  (def, checked)
  + Hello.Advances   #7d18f53c90e4  (def, checked)

contracts (1 selected: 0 checked, 1 open):
  ~ select Hello.Advances(Hello.advance)  [open]
    target: forall n: Nat :: Hello.advance(n) > n
    realizations: Hello.advance -> #2c91e04b7a12

Notice how much clearer lema diff is than a line diff: it lists the three added exports by their semantic identity and shows that select Hello.Advances(Hello.advance) is currently open, pinned to Hello.advance at #2c91e04b7a12.

Save this initial state as a semantic revision on main using lema commit:

Shell
lema commit -m "Start hello project with greeting and open Counter contract"
Output
committed revision #5a30e91c4b28 to main (generation 2, 1 open obligation carried)

Because the default local development policy on main allows committing revisions with carried open obligations while you iterate, lema commit snapshots your current workspace bindings (lema.binding-map/v1 and lema.snapshot/v2), records the open contract selection in revision.obligations, and advances main to generation 2.

Next

Continue to Lesson 4: Select a contract and prove it to see how you and your AI coding agent test and run code while a contract is open, prove single-law and multi-law contracts, and watch Store::check_witness turn an open selection into checked.

Lema v0.3.2 · Updated 29 October 2026 · Version and compatibility