leanforge-mcp: Instructions file for Claude Code

CLAUDE.md

leanforge-mcp CLAUDE.md is an instructions file for Claude Code from sandraschi/leanforge-mcp. It costs 900 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 for Claude Code

Written for Claude Code: the file is CLAUDE.md. Also seen: mentions CLAUDE.md; mentions subagents; mentions Claude Code.

This is sandraschi/leanforge-mcp's own configuration. It tells Claude Code how to work on leanforge-mcp itself, so it is not a mod to install elsewhere. Copy it as a starting point and replace the rules that are about this project. Everything leanforge-mcp configures →

Reuse

Borrowing it

Nothing to install: this file belongs to sandraschi/leanforge-mcp. Take a copy, put it at the same path in your own repository, and replace the rules that are about this project with yours.

Copy the file
curl -O https://raw.githubusercontent.com/sandraschi/leanforge-mcp/main/CLAUDE.md
Clone the repo
git clone --depth 1 https://github.com/sandraschi/leanforge-mcp

Made for: Claude Code.

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/github.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/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for leanforge-mcp CLAUDE.md

Your own site · 80×15
<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="Reviewed on agentmods" width="80" height="20"></a>
Per session 900 This file is loaded in full into every session.
When invoked 900 The same file — it is already loaded in full.
Security scan A 1 finding. A grade says what 26 rules found in the file — not that it is safe.
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.1 $0.00900 $0.00900
Opus 5.5 $0.00360 $0.00360
Sonnet 5.5 $0.00180 $0.00180
Haiku 4.5 $0.00090 $0.00090

Measured 9d ago against content hash ff022703c643, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, 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 9d 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 · 112 lines

How it starts

The opening of the file, as written. The whole thing — 112 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\leanforge_mcp\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)
  → {"success": true, "job_id": "uuid", "status": "queued"}

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

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

verify_proof(lean_source)
  → {"success": true, "proven": bool, "verified": bool} (needs Lean >= 4.35.0 workspace, else supported:false)

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

leanforge_shutdown()
  → {"success": true} then the process exits (use before restarts)

Read the full file on GitHub · 112 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. 9d ago Changed · +6 lines · +89 tokens per session ff022703c643
  2. 1mo 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 (3 stars, last pushed 4d ago), licensed MIT. It adds 900 tokens to every session, about $0.0036 per session on Opus 5.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.

Related

Other instructions, from other repositories