golf

golf is a command for coding agents from cameronfreer/lean4-skills. It costs 17 tokens per session (2,592 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

Part of the lean4 plugin — 1 skill, 12 commands, 4 agents, 3 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 commands/cameronfreer/lean4-skills/golf
Clone the repo
git clone --depth 1 https://github.com/cameronfreer/lean4-skills

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.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.svg" alt="Measured on agentmods" 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,592 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.00017 $0.02592
Opus 5 $0.00009 $0.01296
Sonnet 5 $0.00003 $0.00518
Haiku 4.5 $0.00002 $0.00259

Measured today against content hash 2f617471743a, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, 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 today.

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

1 near-identical copy found in the catalogue:

  • golf — 94% identical, 24 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
    • Hand off to axiom-eliminator if replacement needs statement changes or multi-file refactor
  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. today Changed · -1 lines 2f617471743a
  2. 5d 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 (428 stars, last pushed today), licensed MIT. It adds 17 tokens to every session and 2,592 once invoked, about $0.0001 per session on Opus 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.