Skills DirectorySkills Directory
SkillsLearnSecurityCategoriesDocsCommunityBlog
Sign InSubmit Skill
Skills Directory

Security-tested agent skills for Claude, coding agents, and AI workflows.

Directory

  • Browse Skills
  • All Skills A–Z
  • Claude Skills
  • Claude Code Skills
  • Agent Skills
  • Categories
  • Submit a Skill

Learn

  • Learn Hub
  • Install Claude Skills
  • Write SKILL.md
  • Skills vs MCP
  • Directories Compared

Security

  • Security
  • Methodology
  • Secure Claude Skills
  • Security Badges

Company

  • About
  • Community
  • Blog
  • API Docs
  • Advertise

2026 Skills Directory. All rights reserved.

Back to skills

Lean4 Theorem Value Access

ASecurity

Fix missing theorem proof terms when analyzing Lean 4 environments via importModules. Use when: (1) ConstantInfo.value? returns none for theorems despite TheoremVal.value being Expr, (2) building code graph / dependency extractor for Lean 4 and getting 0 proof dependency edges, (3) Lean 4.30+ project where theorem proofs appear missing from loaded environment, (4) analyzing Mathlib or any Lean 4 project and proof terms are empty. Root cause: breaking change in Lean 4.30 — value? treats theore...

36 stars
0 votes
0 copies
0 views
Added 9/20/2026
data

Works with

claude code

Security Analysis

A100/100

Scanned 9/20/2026

Install to Claude Code

$npx -y skills add Disentinel/grafema --skill lean4-theorem-value-access --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Lean4 Theorem Value Access?

Add the live security badge to your README — it updates automatically with every re-scan.

Security grade badge for Lean4 Theorem Value Access
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/disentinel-lean4-theorem-value-access/badge)](https://www.skillsdirectory.com/skills/disentinel-lean4-theorem-value-access)

More formats (shields.io, HTML) on the badges page.

Download Zip
Files
SKILL.md
---
name: lean4-theorem-value-access
description: |
  Fix missing theorem proof terms when analyzing Lean 4 environments via importModules.
  Use when: (1) ConstantInfo.value? returns none for theorems despite TheoremVal.value being Expr,
  (2) building code graph / dependency extractor for Lean 4 and getting 0 proof dependency edges,
  (3) Lean 4.30+ project where theorem proofs appear missing from loaded environment,
  (4) analyzing Mathlib or any Lean 4 project and proof terms are empty.
  Root cause: breaking change in Lean 4.30 — value? treats theorems as opaque by default.
author: Claude Code
version: 1.0.0
date: 2026-05-23
---

# Lean 4.30+ Theorem Value Access Breaking Change

## Problem
When loading a Lean 4 environment via `importModules` and iterating over constants,
`ConstantInfo.value?` returns `none` for ALL theorems, even though the proof terms
are present in the `.olean.private` files and loaded into memory.

## Context / Trigger Conditions
- Building a Lean 4 code analyzer, dependency extractor, or proof graph tool
- Using `importModules` to load an environment (e.g., Mathlib)
- `ci.value?` returns `none` for `.thmInfo` constants
- 0 proof dependency edges in output despite theorems existing
- Lean toolchain version is 4.30.0-rc1 or later

## Root Cause

**Breaking change between Lean 4.29.1 and 4.30.0-rc2** in `ConstantInfo.value?`:

```lean
-- Lean 4.29.1 (old behavior):
| .thmInfo  {value, ..}   => some value

-- Lean 4.30.0-rc2 (new behavior):
| .thmInfo  {value, ..}   => if allowOpaque then some value else none
```

In 4.30+, theorems are treated the same as `opaqueInfo` — their values are hidden
unless `allowOpaque := true` is explicitly passed. The default `allowOpaque = false`
causes `value?` to return `none` for all theorems.

The proof terms ARE loaded into memory (`.olean.private` files contain them, and
`importModules` loads at `OLeanLevel.private` by default). The data is there — the
accessor just hides it.

## Solution

**Option A: Pass `allowOpaque := true`** (simplest fix)
```lean
if let some val := ci.value? (allowOpaque := true) then
  -- val is the proof term
```

**Option B: Pattern match directly** (most reliable)
```lean
let valInfo := match ci with
  | .defnInfo v => some (v.value, "VALUE_USES")
  | .thmInfo v  => some (v.value, "PROOF_USES")
  | _           => none
if let some (val, edgeType) := valInfo then
  let deps := val.getUsedConstantsAsSet
  -- process deps
```

Option B is preferred for tools that need to distinguish definition bodies from
proof terms, since `allowOpaque := true` conflates theorems with opaque declarations.

## Verification

```lean
-- This should print true for theorems in Lean 4.30+:
let some ci := env.find? `SomeTheorem | ...
match ci with
| .thmInfo v =>
  eprintln s!"value? default: {ci.value?.isSome}"           -- false
  eprintln s!"value? opaque:  {(ci.value? (allowOpaque := true)).isSome}" -- true
  eprintln s!"direct access:  {v.value.getUsedConstants.size}"  -- >0
| _ => ...
```

## Related Facts

- `.olean` files have THREE levels: `.olean` (public), `.olean.server` (IDE), `.olean.private` (full proofs)
- `importModules` defaults to `OLeanLevel.private` — proofs are loaded
- `Expr.foldConsts` signature: `(e : Expr) (init : α) (f : Name → α → α) : α` — Name is first arg, accumulator second
- `Expr.getUsedConstantsAsSet` returns `NameSet` (= `Std.TreeSet Name`), NOT `NameHashSet` (= `HashSet Name`)
- `NameSet` doesn't have `.fold` — use `for dep in nameSet do` instead
- Mathlib scale: 354K declarations, 11.3M edges (including 4.4M PROOF_USES)

## Notes

- This change aligns with proof irrelevance: for type checking, proof content doesn't
  matter. Tools that DO need proofs (checkers, analyzers, graph builders) must opt in.
- The `value!` function also changed — it panics for theorems unless `allowOpaque := true`.
- `ConstantInfo.getUsedConstantsAsSet` (on ConstantInfo, not Expr) also uses `value?`
  internally, so it will miss proof dependencies too.

Attribution

DisentinelDisentinel
View sourceMore from Disentinel →
SSkills DirectorySkills Directory

Your tool, in front of Claude Code builders.

3 founder slots · $299/mo · GSC-verified traffic · sponsors can never buy grades.

See placements

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments (0)

No comments yet. Be the first to comment!

SSkills DirectorySkills Directory

Your tool, in front of Claude Code builders.

3 founder slots · $299/mo · GSC-verified traffic · sponsors can never buy grades.

See placements

Related Skills

Rank Tracker

This skill helps you track, analyze, and report on keyword ranking positions over time. It monitors both traditional SERP rankings and AI/GEO visibility to provide comprehensive search performance insights.

1821 votes

Youtube Competitor Analyzer

Find and analyze YouTube competitor channels using YouTube Data API v3. Discover competitors through keyword search, category matching, content similarity, and related channel discovery. Compare metrics, content strategies, and market positioning. Use when users want to (1) Find competitors for their YouTube channel, (2) Analyze competitor performance metrics, (3) Compare their channel against competitors, (4) Identify content gaps and opportunities, (5) Benchmark against similar creators, (6...

31 votes

Twitter Algorithm Optimizer

Analyze and optimize tweets for maximum reach using Twitter's open-source algorithm insights. Rewrite and edit user tweets to improve engagement and visibility based on how the recommendation system ranks content.

742580 votes

Weather Fetcher

Instructions for fetching current weather temperature data for Karachi, Pakistan from wttr.in API

655280 votes

Weather

Get current weather and forecasts (no API key required).

476190 votes
View all in data →