leanforge-mcp CLAUDE.md

leanforge-mcp CLAUDE.md is an instructions file for coding agents from sandraschi/leanforge-mcp. It costs 811 tokens per session, scanned A, original, MIT.

Repository instructions for leanforge-mcp, a server that helps find formal proofs in Lean 4, a programming language for writing machine-checked mathematics. It explains the project and how its main files should be changed.

In plain words
What is it for?
Use it when changing the proof-search agent or its Lean client, especially to understand the agent loop, compiler feedback, file locations, and project constraints.
Why use it?
It gives coding agents the rules and background needed to work safely in this repository, including how compiler errors guide proof attempts. It also explains that unfinished proofs marked with `sorry` are not accepted.

Instructions file

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add instructions/sandraschi/leanforge-mcp/claude-md
Clone the repo
git clone --depth 1 https://github.com/sandraschi/leanforge-mcp

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for leanforge-mcp CLAUDE.md

README.md
[![agentmods](https://agentmods.dev/badge/instructions/sandraschi/leanforge-mcp/claude-md.svg)](https://agentmods.dev/instructions/sandraschi/leanforge-mcp/claude-md)
Your own site
<a href="https://agentmods.dev/instructions/sandraschi/leanforge-mcp/claude-md"><img src="https://agentmods.dev/badge/instructions/sandraschi/leanforge-mcp/claude-md.svg" alt="Measured on agentmods" height="20"></a>
Per session 811 This file is loaded in full into every session.
When invoked 811 The same file — it is already loaded in full.
Security scan A 1 finding. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00811 $0.00811
Opus 5 $0.00405 $0.00405
Sonnet 5 $0.00162 $0.00162
Haiku 4.5 $0.00081 $0.00081

Measured 3d ago against content hash 000970cbafcb, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

leanforge-mcp CLAUDE.md scanned grade A with 1 finding against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 3d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Runs shell commandslowCapability

Expected in a hook, worth knowing in a rule or an instructions file.

stdin=asyncio.subprocess.PIPE,
CLAUDE.md · 106 lines

How it starts

The opening of the file, as written. The whole thing — 106 lines — stays where its author put it; the contents beside it link to each section on GitHub.

CLAUDE.md -- leanforge-mcp

Claude Desktop / Claude Code notes for working in this repo.

What this repo does

leanforge-mcp is a FastMCP server wrapping a Lean 4 formal proof search pipeline. An agent submits a theorem; the server runs N parallel subagents each looping: LLM proposes a proof edit → Lean compiler checks → error feeds back → repeat. First subagent to produce a sorry-free compile wins.

Key concepts

  • sorry in Lean = "trust me, skip this proof" -- invalid until all sorry replaced
  • The Lean compiler is the oracle -- its error messages ARE the training signal
  • Mathlib has ~150k theorems; LLMs know it well from training data
  • import Mathlib at top of file gives access to all of it

When working on agent.py

Core loop in src\core\agent.py. The LLM's job each turn:

  1. Read current .lean file
  2. Read last compiler error (if any)
  3. Propose a search-replace edit filling sorry
  4. Never change the theorem statement

Lean 4 compiler error format:

error: unknown tactic 'magic'
  at Proof.lean:7:4

Feed the full error string back verbatim. LLM uses it to self-correct.

When working on lean_client.py

proc = await asyncio.create_subprocess_exec(
    str(lean_path), "--stdin",
    stdin=asyncio.subprocess.PIPE,
    stdout=asyncio.subprocess.PIPE,
    stderr=asyncio.subprocess.PIPE,
)
stdout, stderr = await asyncio.wait_for(
    proc.communicate(input=lean_source.encode()), timeout=30
)

Check proc.returncode == 0 AND no sorry in source for a proven result.

MCP tool quick reference

submit_theorem(statement, hints?, tier=1, parallel_agents=4, max_turns=100)
  → {"job_id": "uuid", "status": "queued"}

get_proof_status(job_id)
  → {"status": "running|complete|failed", "proof": "...", "turns_used": int}

validate_lean(lean_source)
  → {"success": bool, "errors": [...]}

get_mathlib_search(query)
  → {"results": [{"name": "...", "statement": "..."}]}

Typical escalation for hard problems

# Start cheap local
submit_theorem(statement="...", tier=1, max_turns=100)

# If stalled, escalate
submit_theorem(statement="...", tier=2, max_turns=200)

# Hard open problem
submit_theorem(statement="...", tier=3, max_turns=500)
# At $50/M output -- budget carefully

Read the full file on GitHub · 106 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 3d ago First seen · 106 lines · 811 tokens per session scan A 000970cbafcb

Subscribe to this mod's changes

leanforge-mcp CLAUDE.md is an instructions file published in the GitHub repository sandraschi/leanforge-mcp (0 stars, last pushed 3d ago), licensed MIT. It adds 811 tokens to every session, about $0.0041 per session on Opus 5. A static security scan graded it A with 1 finding (runs shell commands). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.