Agent skill

Lean4 Memories

by benchflow-ai in benchflow-ai/skillsbench

This skill should be used when working on Lean 4 formalization projects to maintain persistent memory of successful proof patterns, failed approaches, project conventions, and user preferences…

Apache-2.0Auto-check passedAgent Workflows

Install Lean4 Memories

skills CLI
$ npx skills add benchflow-ai/skillsbench --skill lean4-memories -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install benchflow-ai/skillsbench lean4-memories --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/benchflow-ai/skillsbench.git skills-src && mkdir -p .claude/skills && cp -r skills-src/tasks/lean4-proof/environment/skills/lean4-memories .claude/skills/lean4-memories && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
lean4-memories
GitHub stars
1.8k
Token cost
~3.2k tokens
SKILL.md length
934 words
Files
3 (incl. scripts, references)
Skills in repo
189
Repo updated
First seen
Licence
Apache-2.0

At a glance

This skill should be used when working on Lean 4 formalization projects to maintain persistent memory of successful proof patterns, failed approaches, project conventions, and user preferences…

  • Works in 3 steps: Project path - Prevents cross-project… → Skill context - Memories tagged with… → Entity type - Structured by pattern type…
  • Tasks that involve Agent memory
  • SKILL.md covers Overview, When to Use This Skill, How Memory Integration Works and Memory Workflows, plus 9 more sections
  • Runs Python scripts from its folder

What it does

Lean4 Memories is an agent skill from benchflow-ai/skillsbench. This skill should be used when working on Lean 4 formalization projects to maintain persistent memory of successful proof patterns, failed approaches, project conventions, and user preferences across sessions using MCP memory server integration

Its SKILL.md is about 3.2k tokens, which your agent loads only when the skill is triggered. The skill folder holds 4 other files, including scripts and reference files (for example `references/memory-patterns.md` and `scripts/memory_helper.py`).

It sits in Agent Workflows, covering Agent memory. It works with Model Context Protocol. The repository describes itself as: SkillsBench evaluates how well skills work and how effective agents are at using them. The licence is Apache-2.0.

When your agent uses it

  • Tasks that involve Agent memory

Example prompts

  • “/lean4-memories”

Requirements

  • Python 3

Workflow steps

3 steps, taken from the first numbered list in SKILL.md.

  1. Project path - Prevents cross-project contamination
  2. Skill context - Memories tagged with lean4-memories
  3. Entity type - Structured by pattern type (ProofPattern, FailedApproach, etc.)

What it can do on your machine

Read from SKILL.md and the folder at commit 9a1f4dd. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    Ships 1 file in scripts/ (Python), which the agent can run.

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    Links to these hosts (documentation or services it may open):

    • modelcontextprotocol.io

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Lean4 Memories loads about 3.2k tokens when it runs, and up to ~7.6k if it reads all its reference files. Until then it costs about 65 tokens; SKILL.md has 934 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~65
When it runs · the whole SKILL.md, loaded when a task matches
~3.2k
With references · SKILL.md plus every file in references/, read only if the agent opens them
~7.6k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); the scripts in this folder are not scanned.

SKILL.md

The full file from benchflow-ai/skillsbench at commit 9a1f4dd, republished under its Apache-2.0 licence (© benchflow-ai). 934 words, ~3,187 tokens.

Download SKILL.mdSave it as .claude/skills/lean4-memories/SKILL.md (or your agent's skills folder). This skill also uses 2 other files; get the full folder from GitHub.
name
lean4-memories
description
This skill should be used when working on Lean 4 formalization projects to maintain persistent memory of successful proof patterns, failed approaches, project conventions, and user preferences across sessions using MCP memory server integration

Lean 4 Memories

Overview

This skill enables persistent learning and knowledge accumulation across Lean 4 formalization sessions by leveraging MCP (Model Context Protocol) memory servers. It transforms stateless proof assistance into a learning system that remembers successful patterns, avoids known dead-ends, and adapts to project-specific conventions.

Core principle: Learn from each proof session and apply accumulated knowledge to accelerate future work.

When to Use This Skill

This skill applies when working on Lean 4 formalization projects, especially:

  • Multi-session projects - Long-running formalizations spanning days/weeks/months
  • Repeated proof patterns - Similar theorems requiring similar approaches
  • Complex proofs - Theorems with multiple attempted approaches
  • Team projects - Shared knowledge across multiple developers
  • Learning workflows - Building up domain-specific proof expertise

Especially important when:

  • Starting a new session on an existing project
  • Encountering a proof pattern similar to previous work
  • Trying an approach that previously failed
  • Needing to recall project-specific conventions
  • Building on successful proof strategies from earlier sessions

How Memory Integration Works

Memory Scoping

All memories are scoped by:

  1. Project path - Prevents cross-project contamination
  2. Skill context - Memories tagged with lean4-memories
  3. Entity type - Structured by pattern type (ProofPattern, FailedApproach, etc.)

Example scoping:

Project: /Users/freer/work/exch-repos/exchangeability-cursor
Skill: lean4-memories
Entity: ProofPattern:condExp_unique_pattern
Memory Types

1. ProofPattern - Successful proof strategies

Store when: Proof completes successfully after exploration
Retrieve when: Similar goal pattern detected

2. FailedApproach - Known dead-ends to avoid

Store when: Approach attempted but failed/looped/errored
Retrieve when: About to try similar approach

3. ProjectConvention - Code style and patterns

Store when: Consistent pattern observed (naming, structure, tactics)
Retrieve when: Creating new definitions/theorems

4. UserPreference - Workflow customization

Store when: User expresses preference (verbose output, specific tools, etc.)
Retrieve when: Choosing between options

5. TheoremDependency - Relationships between theorems

Store when: One theorem proves useful for proving another
Retrieve when: Looking for helper lemmas

Memory Workflows

Storing Memories

After successful proof:

lean
-- Just proved: exchangeable_iff_fullyExchangeable
-- Store the successful pattern

Store:

  • Goal pattern: exchangeable X ↔ fullyExchangeable X
  • Successful tactics: [apply measure_eq_of_fin_marginals_eq, intro, simp]
  • Helper lemmas used: [prefixCylinder_measurable, isPiSystem_prefixCylinders]
  • Difficulty: medium (54 lines)
  • Confidence: high (proof clean, no warnings)

After failed approach:

lean
-- Attempted: simp only [condExp_indicator, mul_comm]
-- Result: infinite loop, build timeout

Store:

  • Failed tactic: simp only [condExp_indicator, mul_comm]
  • Error: "infinite simp loop"
  • Context: conditional expectation with indicator
  • Recommendation: "Use simp only [condExp_indicator] without mul_comm"

Project conventions observed:

lean
-- Pattern: All measure theory proofs start with haveI
haveI : MeasurableSpace Ω := inferInstance

Store:

  • Convention: "Measure theory proofs require explicit MeasurableSpace instance"
  • Pattern: haveI : MeasurableSpace Ω
  • Frequency: 15 occurrences
  • Files: DeFinetti/ViaL2.lean, Core.lean, Contractability.lean
Retrieving Memories

Starting new proof session:

  1. Load project-specific conventions
  2. Retrieve similar proof patterns from past work
  3. Surface any known issues with current file/module

Encountering similar goal:

⊢ condExp μ m X =ᵐ[μ] condExp μ m Y

Memory retrieved: "Similar goals proved using condExp_unique"
Pattern: "Show ae_eq, verify measurability, apply condExp_unique"
Success rate: 3/3 in this project

Before trying a tactic:

About to: simp only [condExp_indicator, mul_comm]

Memory retrieved: ⚠️ WARNING - This combination causes infinite loop
Failed in: ViaL2.lean:2830 (2025-10-17)
Alternative: Use simp only [condExp_indicator], then ring

Integration with lean4-theorem-proving Skill

The lean4-memories skill complements (doesn't replace) lean4-theorem-proving:

lean4-theorem-proving provides:

  • General Lean 4 workflows (4-Phase approach)
  • mathlib search and tactics reference
  • Automation scripts
  • Domain-specific knowledge (measure theory, probability)

lean4-memories adds:

  • Project-specific learned patterns
  • History of what worked/failed in this project
  • Accumulated domain expertise from your proofs
  • Personalized workflow preferences

Use together:

  1. lean4-theorem-proving guides general workflow
  2. lean4-memories provides project-specific context
  3. Memories inform tactics choices from lean4-theorem-proving

Memory Operations

Storing a Successful Proof Pattern

After completing a proof, store the pattern using MCP memory:

What to capture:

  • Goal pattern - Type/structure of goal (equality, exists, forall, etc.)
  • Tactics sequence - Tactics that worked, in order
  • Helper lemmas - Key lemmas applied
  • Difficulty - Lines of proof, complexity estimate
  • Confidence - Clean proof vs sorries/warnings
  • Context - File, module, theorem name

When to store:

  • Proof completed successfully (no sorries)
  • Non-trivial (>10 lines or required exploration)
  • Likely to be useful again (similar theorems expected)

Storage format:

Entity type: ProofPattern
Name: {descriptive_name}
Attributes:
  - project: {absolute_path}
  - goal_pattern: {pattern_description}
  - tactics: [list, of, tactics]
  - helper_lemmas: [lemma1, lemma2]
  - difficulty: {small|medium|large}
  - confidence: {0.0-1.0}
  - file: {filename}
  - timestamp: {date}
Storing a Failed Approach

When an approach fails (error, loop, timeout), store to avoid repeating:

What to capture:

  • Failed tactic - Exact tactic/sequence that failed
  • Error type - Loop, timeout, type error, etc.
  • Context - What was being proved
  • Alternative - What worked instead (if known)

When to store:

  • Infinite simp loops
  • Tactics causing build timeouts
  • Type mismatches from subtle issues
  • Approaches that seemed promising but didn't work

Storage format:

Entity type: FailedApproach
Name: {descriptive_name}
Attributes:
  - project: {absolute_path}
  - failed_tactic: {tactic_text}
  - error: {error_description}
  - context: {what_was_being_proved}
  - alternative: {what_worked}
  - timestamp: {date}
Show full SKILL.md (385 more words)Show less
Storing Project Conventions

Track consistent patterns that emerge:

What to capture:

  • Naming conventions - h_ for hypotheses, have_ for results
  • Proof structure - Standard opening moves (haveI, intro patterns)
  • Import patterns - Commonly used imports
  • Tactic preferences - measurability vs explicit proofs

When to store:

  • Pattern observed 3+ times consistently
  • Convention affects multiple files
  • Style guide established
Retrieving Memories

Before starting proof:

1. Query for similar goal patterns
2. Surface successful tactics for this pattern
3. Check for known issues with current context
4. Suggest helper lemmas from similar proofs

During proof:

1. Before each major tactic, check for known failures
2. When stuck, retrieve alternative approaches
3. Suggest next tactics based on past success

Query patterns:

# Find similar proofs
search_entities(
  query="condExp equality goal",
  filters={"project": current_project, "entity_type": "ProofPattern"}
)

# Check for failures
search_entities(
  query="simp only condExp_indicator",
  filters={"project": current_project, "entity_type": "FailedApproach"}
)

# Get conventions
search_entities(
  query="naming conventions measure theory",
  filters={"project": current_project, "entity_type": "ProjectConvention"}
)

Best Practices

Memory Quality

DO store:

  • ✅ Successful non-trivial proofs (>10 lines)
  • ✅ Failed approaches that wasted significant time
  • ✅ Consistent patterns observed multiple times
  • ✅ Project-specific insights

DON'T store:

  • ❌ Trivial proofs (rfl, simp, exact)
  • ❌ One-off tactics unlikely to recur
  • ❌ General Lean knowledge (already in training/mathlib)
  • ❌ Temporary workarounds
Memory Hygiene

Confidence scoring:

  • High (0.8-1.0) - Clean proof, no warnings, well-tested
  • Medium (0.5-0.8) - Works but has minor issues
  • Low (0.0-0.5) - Hacky solution, needs refinement

Aging:

  • Recent memories (same session) = higher relevance
  • Older memories = verify still applicable
  • Patterns from many sessions = high confidence

Pruning:

  • Remove memories for deleted theorems
  • Update when better approach found
  • Mark as outdated if project evolves
User Control

Users can:

  • Toggle lean4-memories skill on/off independently
  • Clear project-specific memories
  • Review stored memories
  • Adjust confidence thresholds
  • Export/import memories for sharing

Example Workflow

Session 1: First proof

lean
-- Proving: measure_eq_of_fin_marginals_eq
-- No memories yet, explore from scratch
-- [After 30 minutes of exploration]
-- ✅ Success with π-system uniqueness approach

Store: ProofPattern "pi_system_uniqueness"
  - Works for: measure equality via finite marginals
  - Tactics: [isPiSystem, generateFrom_eq, measure_eq_on_piSystem]
  - Confidence: 0.9

Session 2: Similar theorem (weeks later)

lean
-- Proving: fullyExchangeable_via_pathLaw
-- Goal: Show two measures equal
-- System: "Similar to measure_eq_of_fin_marginals_eq"
--         Retrieve memory: pi_system_uniqueness pattern
--         Suggestion: "Try isPiSystem approach?"

-- ✅ Success in 5 minutes using remembered pattern

Session 3: Avoiding failure

lean
-- Proving: condIndep_of_condExp_eq
-- About to: simp only [condExp_indicator, mul_comm]
-- ⚠️ Memory: This causes infinite loop (stored Session 1)
--          Alternative: simp only [condExp_indicator], then ring

-- Avoid 20-minute debugging session by using memory

Configuration

Memory Server Setup

Ensure MCP memory server is configured:

json
// In Claude Desktop config
{
  "mcpServers": {
    "memory": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-memory"]
    }
  }
}
Project-Specific Settings

Memories are automatically scoped by project path. To work across multiple projects:

Same formalization, different repos:

# Link memories using project aliases
# (Future enhancement - not yet implemented)

Sharing memories with team:

# Export/import functionality
# (Future enhancement - not yet implemented)

Integration with Automation Scripts

Memories enhance script usage:

proof_templates.sh:

  • Retrieve project-specific template preferences
  • Include common proof patterns in scaffolding

suggest_tactics.sh:

  • Prioritize tactics that succeeded in this project
  • Warn about tactics with known issues

sorry_analyzer.py:

  • Link sorries to similar completed proofs
  • Suggest approaches based on memory

Limitations and Caveats

What memories DON'T replace:

  • Mathematical understanding
  • Lean type system knowledge
  • mathlib API documentation
  • Formal verification principles

Potential issues:

  • Stale memories if project evolves significantly
  • Over-fitting to specific project patterns
  • Memory bloat if not maintained
  • Cross-project contamination if scoping fails

Mitigation:

  • Regular review of stored memories
  • Confidence scoring and aging
  • Strict project-path scoping
  • User control over memory operations

Future Enhancements

Planned features:

  • Memory visualization dashboard
  • Pattern mining across projects
  • Collaborative memory sharing
  • Automated memory pruning
  • Integration with git history
  • Cross-project pattern detection (with user consent)

See Also

© benchflow-ai, Apache-2.0. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

SKILL.md and 2 other files (scripts, references) in tasks/lean4-proof/environment/skills/lean4-memories of benchflow-ai/skillsbench.

  • SKILL.md
  • references/memory-patterns.md
  • scripts/memory_helper.py

Open the folder on GitHubat commit 9a1f4dd

Compare with similar skills

Lean4 Memories next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Lean4 Memories compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Lean4 Memories this skillbenchflow-ai/skillsbench1.8k—~3.2kAutomated safety check: PassApache-2.0
MemPalace Memory SearchMemPalace/mempalace59k—~1.4kAutomated safety check: PassMIT
MemPalace Setup and OperationMemPalace/mempalace59k—~2.2kAutomated safety check: PassMIT
agentmemory Setup and Diagnosticsrohitg00/agentmemory29k—~1kAutomated safety check: NotesApache-2.0
Claude-Mem Install for Grok Botthedotmack/claude-mem99k—~440Automated safety check: PassApache-2.0
Qmdbreferrari/obsidian-mind5k—~1.7kAutomated safety check: PassMIT

Similar skills

  • MemPalace Memory Search

    MemPalace/mempalace

    Mines project files and conversation exports into a local, searchable memory palace and recalls past work by semantic search through the mempalace CLI.

    59k GitHub stars~1.4k tokensUpdated today
    Agent WorkflowsAuto-check passed
  • Installs and configures MemPalace as a private local palace, a shared-brain hub or a client of an existing hub, including MCP registration and version-correct initialization.

    59k GitHub stars~2.2k tokensUpdated today
    Agent WorkflowsAuto-check passed
  • Sets up and troubleshoots a local agentmemory install, covering the MCP connection, environment variables, ports, authentication and optional feature flags.

    29k GitHub stars~1k tokensUpdated today
    Agent WorkflowsAuto-check: notes
  • Claude-Mem Install for Grok Bot

    thedotmack/claude-mem

    Use this when setting up claude-mem on Grok Bot: local worker plus CMEM Pro observer (default), optional host-login observer, or remote cmem.ai. No Cursor…

    99k GitHub stars~440 tokensUpdated today
    Agent WorkflowsAuto-check passed
  • Qmd

    breferrari/obsidian-mind

    Search the vault using QMD semantic search. An agent skill from breferrari/obsidian-mind.

    5k GitHub stars~1.7k tokensUpdated 3 days ago
    Agent WorkflowsAuto-check passed
  • Agent Memory

    tigerless-labs/agent-memory

    Read and write the shared long-term memory store. An agent skill from tigerless-labs/agent-memory.

    3.4k GitHub stars~1.3k tokensUpdated today
    Agent WorkflowsAuto-check passed

More from benchflow-ai/skillsbench

All 189 skills in this repo
  • Senior Data Engineer

    benchflow-ai/skillsbench

    World-class data engineering skill for building scalable data pipelines, ETL/ELT systems, real-time streaming, and data infrastructure.

    1.8k GitHub stars~5.9k tokensUpdated 2 mo ago
    Auto-check passed
  • Ac Branch Pi Model

    benchflow-ai/skillsbench

    AC branch pi-model power flow equations (P/Q and |S|) with transformer tap ratio and phase shift, matching acopf-math-model.md and MATPOWER branch fields.

    1.8k GitHub stars~1.1k tokensUpdated 2 mo ago
    Auto-check passed
  • Civ6lib

    benchflow-ai/skillsbench

    Civilization 6 district mechanics library. An agent skill from benchflow-ai/skillsbench.

    1.8k GitHub stars~1.7k tokensUpdated 2 mo ago
    Auto-check passed
  • D3 Visualization

    benchflow-ai/skillsbench

    Build deterministic, verifiable data visualizations with D3.js (v6).

    1.8k GitHub stars~1.5k tokensUpdated 2 mo ago
    Auto-check passed
  • Dc Power Flow

    benchflow-ai/skillsbench

    DC power flow analysis for power systems. An agent skill from benchflow-ai/skillsbench.

    1.8k GitHub stars~717 tokensUpdated 2 mo ago
    Auto-check passed
  • Energy Calculator

    benchflow-ai/skillsbench

    Calculate per-second RMS energy from audio files. An agent skill from benchflow-ai/skillsbench.

    1.8k GitHub stars~437 tokensUpdated 2 mo ago
    Auto-check passed

Categories

Questions about Lean4 Memories

What does Lean4 Memories do?

This skill should be used when working on Lean 4 formalization projects to maintain persistent memory of successful proof patterns, failed approaches, project conventions, and user preferences…. Lean4 Memories is an agent skill from benchflow-ai/skillsbench.

When should I use Lean4 Memories?

Lean4 Memories fits situations like: tasks that involve Agent memory.

How do I install Lean4 Memories in Claude Code?

Run `npx skills add benchflow-ai/skillsbench --skill lean4-memories -a claude-code`. Or copy the skill folder (tasks/lean4-proof/environment/skills/lean4-memories in benchflow-ai/skillsbench) into .claude/skills/lean4-memories in your project. Claude Code loads it when a task matches its description.

How do I install Lean4 Memories in Codex?

Run `npx skills add benchflow-ai/skillsbench --skill lean4-memories -a codex`. Or copy the skill folder (tasks/lean4-proof/environment/skills/lean4-memories in benchflow-ai/skillsbench) into .agents/skills/lean4-memories in your project. Codex loads it when a task matches its description.

Can I use Lean4 Memories in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add benchflow-ai/skillsbench --skill lean4-memories -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/lean4-memories, .gemini/skills/lean4-memories, .github/skills/lean4-memories and .opencode/skills/lean4-memories in your project.

What does Lean4 Memories need to run?

Going by SKILL.md and its folder, Lean4 Memories needs Python for the scripts in its folder. Our summary lists: Python 3.

Does Lean4 Memories access the network?

SKILL.md names 1 domain. As links in the text: modelcontextprotocol.io. This is read from the text; nothing was executed.

Is Lean4 Memories safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. The check reads SKILL.md only: the scripts in the folder are not scanned, so read them before running anything.

What licence does Lean4 Memories use?

Lean4 Memories is published under the Apache-2.0 licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Lean4 Memories use?

About 3.2k tokens (SKILL.md is roughly 13k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full. Its references folder adds about 4.4k tokens, read only when the agent opens those files.

What are the alternatives to Lean4 Memories?

Skills that share tags, products or a category with Lean4 Memories: MemPalace Memory Search (MemPalace/mempalace, 59k stars), MemPalace Setup and Operation (MemPalace/mempalace, 59k stars), agentmemory Setup and Diagnostics (rohitg00/agentmemory, 29k stars) and Claude-Mem Install for Grok Bot (thedotmack/claude-mem, 99k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Lean4 Memories?

benchflow-ai (a GitHub organization) maintains it in benchflow-ai/skillsbench, which has 1,835 GitHub stars. The repository holds 189 skills in this directory. The repository was last updated on July 23, 2026.

Source: benchflow-ai/skillsbench on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.