golf

golf is a command for coding agents from frenzymath/Archon. It costs 17 tokens per session (2,663 once invoked), scanned A, a copy of golf, Apache-2.0.

A Lean 4 proof-improvement command for code that already compiles. It compares alternative proofs for correctness, clarity, performance, directness, and shorter length.

In plain words
What is it for?
Use it on a whole project, file, or specific line to find shorter or clearer proofs, preview changes, or search for replacement lemmas.
Why use it?
It helps reduce unnecessary proof steps while keeping the proof valid and understandable.

Command

Part of the lean4 plugin — 1 skill, 11 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/frenzymath/archon/golf
Clone the repo
git clone --depth 1 https://github.com/frenzymath/Archon

Or install lean4, the plugin that ships this one along with the rest of its 1 skill, 11 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/frenzymath/archon/golf.svg)](https://agentmods.dev/commands/frenzymath/archon/golf)
Your own site
<a href="https://agentmods.dev/commands/frenzymath/archon/golf"><img src="https://agentmods.dev/badge/commands/frenzymath/archon/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,663 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin 94% copy Near-identical to another mod 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.02663
Opus 5 $0.00009 $0.01332
Sonnet 5 $0.00003 $0.00533
Haiku 4.5 $0.00002 $0.00266

Measured 4d ago against content hash 12d757354633, 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 4d 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

This is a copy

94% identical to golf — 11 lines differ, which has more behind it and is treated as the original. This page carries a canonical link to it rather than competing with it.

src/archon/.archon-src/skills/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_PYTHON_BIN:-python3} "$LEAN4_SCRIPTS/find_golfable.py" [file] --filter-false-positives
    
    For direct-proof discovery when --search is enabled or syntactic pass stalls:
    ${LEAN4_PYTHON_BIN:-python3} "$LEAN4_SCRIPTS/find_exact_candidates.py" [file]
    
  3. Exact-Collapse Pass (bounded) — For apply/exact chain anchors from $LEAN4_SCRIPTS/find_golfable.py:
    • 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_PYTHON_BIN:-python3} "$LEAN4_SCRIPTS/analyze_let_usage.py" [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. 4d ago First seen · 167 lines · 17 tokens per session scan A 12d757354633

Subscribe to this mod's changes

golf is a command published in the GitHub repository frenzymath/Archon (213 stars, last pushed 18d ago), licensed Apache-2.0. It adds 17 tokens to every session and 2,663 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. It is 94% identical to golf, differing in 11 lines, and is treated as a copy.