heap-seance: Command for Claude Code

.claude/commands/leak-scan.md

leak-scan is a command for Claude Code from SegfaultSorcerer/heap-seance. It costs 60 tokens per session (1,225 once invoked), scanned A, original, Apache-2.0.

A cautious command for looking for possible memory leaks in a running Java program. A memory leak is a problem where objects that are no longer needed remain in memory, which can cause slowdowns or out-of-memory errors.

In plain words
What is it for?
Use it when a Java process has growing memory use, heap pressure, frequent garbage collection or an OutOfMemoryError. You can identify the process by its numeric process ID or by a name pattern.
Why use it?
It provides a structured comparison of Java objects across three memory samples. It asks you to repeat the suspected action between samples so the scan can detect objects that keep accumulating.

Command for Claude Code

Written for Claude Code: allowed-tools in frontmatter.

This is SegfaultSorcerer/heap-seance's own configuration. It tells Claude Code how to work on heap-seance itself, so it is not a mod to install elsewhere. Copy it as a starting point and replace the rules that are about this project. Everything heap-seance configures →

Reuse

Borrowing it

Nothing to install: this file belongs to SegfaultSorcerer/heap-seance. Take a copy, put it at the same path in your own repository, and replace the rules that are about this project with yours.

Copy the file
curl -O https://raw.githubusercontent.com/SegfaultSorcerer/heap-seance/main/.claude/commands/leak-scan.md
Clone the repo
git clone --depth 1 https://github.com/SegfaultSorcerer/heap-seance

Made for: Claude Code.

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 leak-scan

README.md
[![agentmods](https://agentmods.dev/badge/commands/segfaultsorcerer/heap-seance/leak-scan/github.svg)](https://agentmods.dev/commands/segfaultsorcerer/heap-seance/leak-scan)
Your own site
<a href="https://agentmods.dev/commands/segfaultsorcerer/heap-seance/leak-scan"><img src="https://agentmods.dev/badge/commands/segfaultsorcerer/heap-seance/leak-scan/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 leak-scan

Your own site · 80×15
<a href="https://agentmods.dev/commands/segfaultsorcerer/heap-seance/leak-scan"><img src="https://agentmods.dev/badge/commands/segfaultsorcerer/heap-seance/leak-scan.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 60 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 1,225 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.00060 $0.01225
Opus 5 $0.00030 $0.00613
Sonnet 5 $0.00012 $0.00245
Haiku 4.5 $0.00006 $0.00122

Measured 9d ago against content hash 593f40a978b4, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-09, from the pricing page.

Security

Grade A, and why

leak-scan 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 9d 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.

.claude/commands/leak-scan.md · 95 lines

How it starts

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

Run a conservative Java leak scan for $ARGUMENTS.

Interpret $ARGUMENTS as either a PID (integer) or a process name/pattern (string).

Step 1: Resolve target process

  • If $ARGUMENTS is an integer, use it directly as PID.
  • If $ARGUMENTS is empty, call java_list_processes() and list all discovered JVMs so the user can choose. Do not pick one silently.
  • If $ARGUMENTS is a string, call java_list_processes() and match by substring against each process display field (case-insensitive). If exactly one process matches, use it. If multiple match, list them and ask the user to narrow down. If none match, report this and stop.

Step 2: Collect 3 histogram samples

Call java_class_histogram(pid, live_only=true) three times. Between each sample, ask the user to perform the suspected leaking action in their application (e.g., open/close a view, send requests, load/discard data) and confirm when done. This is critical — without exercising the app between snapshots, leaks stay invisible because no new objects are created along the leaking path.

Prompt the user like this:

  • After sample 1: "Histogram sample 1 collected. Please perform the action you suspect is leaking (e.g., open/close views, trigger requests), then let me know when you're done."
  • After sample 2: "Histogram sample 2 collected. Please repeat the same action once more, then confirm."
  • After sample 3: proceed to Step 3.

Why 3 samples: detecting monotonic growth requires at least 3 data points. The live_only=true flag triggers a GC before each snapshot, so only reachable objects are counted — this filters out garbage that would skew the signal.

Step 3: Collect GC pressure snapshot

Call java_gc_snapshot(pid, interval_s=2, samples=6).

This samples jstat -gcutil over ~12 seconds to capture old-gen utilization trend and Full GC activity.

Step 4: Evaluate signals

Two independent signals determine whether escalation is warranted:

Monotonic growth candidate: a class whose retained bytes are non-decreasing across all 3 histogram samples AND whose total growth is >= 1,000,000 bytes. Classes that shrink between any two samples are not candidates — the threshold filters noise from normal allocation churn.

Read the full file on GitHub · 95 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. 9d ago First seen · 95 lines · 60 tokens per session scan A 593f40a978b4

Subscribe to this mod's changes

leak-scan is a command published in the GitHub repository SegfaultSorcerer/heap-seance (4 stars, last pushed 5mo ago), licensed Apache-2.0. It adds 60 tokens to every session and 1,225 once invoked, about $0.0003 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-31.