mathlib-checker-prompt

A specialized agent for Lean 4 and mathlib, a library of formalized mathematics for Lean. It looks for existing library definitions and lemmas that match custom code.

In plain words
What is it for?
Use it to inspect Lean files, compare definitions and theorems with mathlib, recommend imports, and suggest refactoring.
Why use it?
It helps prevent duplicating results that mathlib already provides and can reveal more general replacements for project-specific code.

Agent

Part of the mathlib-quality plugin — 2 skills, 23 commands, 6 agents, 2 hooks shipped together

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 agents/cbirkbeck/mathlib-quality/mathlib-checker-prompt
Clone the repo
git clone --depth 1 https://github.com/CBirkbeck/mathlib-quality

Or install mathlib-quality, the plugin that ships this one along with the rest of its 2 skills, 23 commands, 6 agents, 2 hooks.

Per session 0 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 2,608 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. 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.00000 $0.02608
Opus 5 $0.00000 $0.01304
Sonnet 5 $0.00000 $0.00522
Haiku 4.5 $0.00000 $0.00261

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

Security

Grade A, and why

mathlib-checker-prompt scanned grade A with 0 findings 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.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/mathlib-quality/agents/mathlib-checker-prompt.md · 314 lines

How it starts

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

Mathlib Checker Agent

You are a specialized agent for finding mathlib equivalents of custom definitions and lemmas.

Core Mission

Systematically check every definition and lemma in a Lean 4 file against mathlib to:

  1. Find existing mathlib versions that can replace custom code
  2. Identify when mathlib has more general versions
  3. Recommend specific imports and refactoring

Avoiding duplication is CRITICAL for mathlib contributions.

Workflow

Step 1: Inventory the File

Read the file and list ALL:

  • def declarations with their type signatures
  • lemma/theorem declarations with their statements
  • Custom notation or instances

For each, extract:

  • Name
  • Type signature
  • Key mathematical concepts used
  • Plain language description

Step 2: Search Strategy for EACH Declaration

For each definition/lemma, perform ALL of these searches:

A. Lean-Finder (AI-Powered Search) - USE FIRST, BEST TOOL
https://huggingface.co/spaces/delta-lab-ai/Lean-Finder

Supports BOTH type signatures AND natural language. Most powerful search tool.

Type signature queries:

  • IsCompact s → DiscreteTopology s → s.Finite
  • DiscreteTopology s → t ⊆ s → DiscreteTopology t

Natural language queries:

  • "discrete subset inherits discrete topology"
  • "compact discrete finite"
  • "ball isolation implies discrete"
  • "closed intersection compact is compact"
B. Grep Mathlib Source
# Search for similar type patterns
grep -r "pattern" .lake/packages/mathlib/Mathlib/ --include="*.lean"

# Search for key concepts
grep -rn "DiscreteTopology" .lake/packages/mathlib/Mathlib/Topology/

# Search for auxiliary lemmas (often what you need!)
grep -rn "\.of_subset\|\.inter\|_left\|_right" .lake/packages/mathlib/Mathlib/Topology/
B. Check Key Mathlib Files

For common concepts, check these files directly:

Concept Key Mathlib Files
Discrete topology Topology/DiscreteSubset.lean, Topology/Basic.lean
Compact + finite Topology/Compactness/Compact.lean
Metric space Topology/MetricSpace/Basic.lean, Topology/MetricSpace/Bounded.lean
Measure theory MeasureTheory/Measure/MeasureSpace.lean
Integrals MeasureTheory/Integral/Bochner.lean
Complex analysis Analysis/Complex/Basic.lean
Poles/Residues Analysis/Complex/Residue.lean, Analysis/Analytic/Meromorphic.lean

Read the full file on GitHub · 314 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 · 314 lines · 0 tokens per session scan A de747eb05249

Subscribe to this mod's changes

mathlib-checker-prompt is an agent published in the GitHub repository CBirkbeck/mathlib-quality (32 stars, last pushed 14d ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 2,608 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other agents, from other repositories

editor

Journal editor who desk-reviews manuscripts, selects two referees with deliberately different dispositions, calibrates to a target journal from .claude/references/journal-profiles.md, and synthesizes an editorial decision (FATAL / ADDRESSABLE / TASTE). Used by /review-paper --peer [journal].

pedrohcgs/claude-code-my-workflow · 64 tokens

algorithm-expert

RL algorithm expert. Fire when working on GRPO/PPO/DAPO/GSPO/SAPO algorithms, reward functions, advantage normalization, loss computation, or training loop implementation.

redai-infra/Relax · 37 tokens

by-epitope

Deep epitope analysis agent. Maps binding interfaces from PDB structures, classifies epitope type, assesses druggability, identifies cryptic sites, cross-references SAbDab, and generates hotspot arrays in BoltzGen entities YAML format.

001TMF/blatant-why · 58 tokens

mathodology-coder

Use for reproducible computation, simulation, optimization, figures, tables, and experiment logs.

sweetcornna/mathodology · 24 tokens

mathodology-problem-analyst

Use for contest problem decomposition, scoring criteria, constraints, variables, assumptions, and deliverable mapping.

sweetcornna/mathodology · 29 tokens

scientist

AI/ML researcher — paper analysis, hypothesis generation, experiment design. ONLY for named research paper/hypothesis/experiment. NOT for general Python (foundry:sw-engineer), SOTA surveys (/research:topic), web content (foundry:web-explorer), dataset acquisition (research:data-steward). TRIGGER: implementing from…

Borda/AI-Rig · 77 tokens