golf

golf is a command for Claude Code from cameronfreer/lean4-skills. It costs 17 tokens per session (2,670 once invoked), scanned A, original, MIT.

A Lean 4 proof-improvement command for shortening and clarifying mathematical proofs that already compile. Lean 4 is a programming language and checker used to write machine-verified mathematics.

In plain words
What is it for?
Use it to improve an entire Lean project, a file, or a proof at a specific line. It can preview possible changes or search for alternative library lemmas.
Why use it?
It helps remove unnecessary steps and reduce the effort needed to understand or check a proof, while preserving correctness.

Command for Claude Code

Written for Claude Code: user-invocable in frontmatter. Also seen: mentions subagents.

Part of the lean4 plugin — 1 skill, 12 commands, 4 agents, 3 hooks shipped together

Good fit Use it to improve an entire Lean project, a file, or a proof at a specific line. It can preview possible changes or search for alternative library lemmas.

Compare 6 commands from other repositories ↓
Install with agentmods
npx agentmods add commands/cameronfreer/lean4-skills/golf
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.

Clone the repo
git clone --depth 1 https://github.com/cameronfreer/lean4-skills

Made for: Claude Code.

Or install lean4, the plugin that ships this one along with the rest of its 1 skill, 12 commands, 4 agents, 3 hooks.

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 golf

README.md
[![agentmods](https://agentmods.dev/badge/commands/cameronfreer/lean4-skills/golf/github.svg)](https://agentmods.dev/commands/cameronfreer/lean4-skills/golf)
Your own site
<a href="https://agentmods.dev/commands/cameronfreer/lean4-skills/golf"><img src="https://agentmods.dev/badge/commands/cameronfreer/lean4-skills/golf/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 golf

Your own site · 80×15
<a href="https://agentmods.dev/commands/cameronfreer/lean4-skills/golf"><img src="https://agentmods.dev/badge/commands/cameronfreer/lean4-skills/golf.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 17 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,670 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. 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.00017 $0.02670
Opus 5.5 $0.00007 $0.01068
Sonnet 5.5 $0.00003 $0.00534
Haiku 4.5 $0.00002 $0.00267

Measured 2mo ago against content hash e1cf40c32480, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

golf 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 2mo 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.

Origin

Copies of this mod

2 near-identical copies found in the catalogue:

  • golf — 94% identical, 26 lines differ
  • golf — 89% identical, 0 lines differ
plugins/lean4/commands/golf.md · 167 lines

How it starts

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

Lean4 Golf

Improve Lean proofs that already compile. Score candidates by: correctness → directness → clarity/inference burden → performance/determinism → length. Length is still a core goal, but a tiebreaker among acceptable proofs.

Prerequisite: Code must compile. Verify code compiles first (lean_diagnostic_messages(file) or lake env lean <path/to/File.lean> from project root; lake build for project-wide).

Usage

/lean4:golf                     # Golf entire project
/lean4:golf File.lean           # Golf specific file
/lean4:golf File.lean:42        # Golf proof at specific line
/lean4:golf --dry-run           # Show opportunities without applying
/lean4:golf --search=full          # Include lemma replacement pass
/lean4:golf --max-delegates=3    # Override default 2 concurrent subagents

Inputs

Arg Required Description
target No File or file:line to golf
--dry-run No Preview only, no changes
--search No off, quick (default), or full — LSP lemma replacement pass
--max-delegates No 2 — max concurrent golfer subagents (preflight must pass first)

Actions

  1. Verify Build - Ensure code compiles before optimizing
  2. Find Patterns - Detect golfable patterns (in policy order: directness → structural → conditional):
    lean4-skills-find-golfable [file] --filter-false-positives
    
    For direct-proof discovery when --search is enabled or syntactic pass stalls:
    lean4-skills-find-exact-candidates [file]
    
  3. Exact-Collapse Pass (bounded) — For apply/exact chain anchors from lean4-skills-find-golfable:
    • Mechanical (≤30 anchors/file): Construct collapsed exact from tactic structure → lean_multi_attempt + lean_diagnostic_messages baseline check (no new diagnostics, no sorry increase). Accept if the replacement is more direct or clearer. Reject if it introduces heavier automation (simpa, rwa, broad simp) to replace an explicit proof, if term length exceeds ~80 chars, if dot-chain depth > 2, or if it removes meaningful intermediate names. A 1-line saving that raises inference burden is not a win.
    • Exploratory (when --search≠off; consumes --search budget): On remaining single-goal anchors, build candidate exact terms from chain lemmas + local hypotheses + dot-notation rewrites → lean_multi_attempt + diagnostics check. Probe caps are phase-local: quick ≤5 probes/file; full ≤15 probes/file; ≤2 probes/anchor. Time budget is shared with lemma replacement (step 4): quick 30s total, full 60s total across both phases.
    • Skip: calc, cases/induction, multi-goal branches, blocks >7 lines, semicolon-heavy (>3), blocks with have/refine. constructor chains are handled by the existing instant-win rule, not this pass.
  4. Lemma Replacement (if --search=quick or full):
    • Run LSP searches per candidate; test with lean_multi_attempt
    • quick: 1 search, ≤2 candidates; full: 2 searches, ≤3 candidates; ≤3 search calls; uses remaining shared time budget
    • Accept the best passing replacement by the scoring order below
    • If a replacement would require a statement change → reject the candidate, keep the existing proof, and report the proposed change for explicit approval (golf never changes statements; an unsuitable candidate is not evidence the statement is wrong); if it needs a multi-file or strategy-level refactor → hand off to /lean4:refactor by returning the proposal to the parent (no cross-file edits here); hand off to axiom-eliminator only for axiom/assumption hygiene
  5. Verify Safety - Check usage before inlining:
    lean4-skills-analyze-let-usage [file] --line [line]
    
  6. Apply - Make changes with lean_diagnostic_messages after each; lake build for final verification
  7. Report - Show savings and saturation status

Read the full file on GitHub · 167 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. 2mo ago Changed e1cf40c32480
  2. 2mo ago Changed · -1 lines 2f617471743a
  3. 3mo ago First seen · 168 lines · 17 tokens per session scan A 44b854a0d2a5

Subscribe to this mod's changes

golf is a command published in the GitHub repository cameronfreer/lean4-skills (509 stars, last pushed 23d ago), licensed MIT. It adds 17 tokens to every session and 2,670 once invoked, about $0.0001 per session on Opus 5.5. 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

golf compared with commands from other repositories

golf next to 6 commands from other repositories
ModTypeStarsLast pushLicenceScanTokensWorks with
golfcameronfreer/lean4-skillsCommand50923d agoMITA17Claude Code
difffa-mc/vibe-cadingCommand81mo agoAGPL-3.0A14Claude Code
arg-diagramMasqiller/ARG-RESEARCHER-V4.1Command66mo agoMITA14Claude Code
plotzhouziyue233/great-econometricsCommand97mo agononeA44Claude Code
graphite-morphology-classifyDaxxSec/cognitropy-labCommand15mo agononeA0Claude Code
checklistgithub/spec-kitCommand153ktodayMITA13Claude Code
clarifygithub/spec-kitCommand153ktodayMITA27Claude Code