/microscope:optimize-code [profile-id | recording-file] [cpu|wall|alloc|lock|latency|waiting|memory|heap]from microscope
Takes a Jeffrey profile (JFR, flamegraph, trace) and maps hot frames to source code, then recommends and applies minimal performance fixes verified by re-profiling.
Ships in microscope. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
The analysis tools read a profile; this skill is what happens after. It takes the measured call trees, finds the code behind the heaviest frames in the checkout you are sitting in, and proposes the smallest change that would reduce the measured cost — then, only when asked, makes it and checks that it helped.
Requested scope: $ARGUMENTS — substituted by Claude Code; where a client does not substitute it,
take the same scope from the request itself. A profile id or a recording file, then optionally one
area (cpu, wall, alloc, lock, latency, waiting, memory, heap). Empty means the
profile the conversation is about (or the most recently modified one in profiles_list) and whatever evidence
it actually carries.
Tool names below omit the prefix your client puts in front of them — mcp__plugin_microscope_jeffrey__ in Claude Code with the microscope plugin, mcp__jeffrey__ in Codex or wherever the server is registered by hand as jeffrey, mcp_jeffrey_ in Gemini CLI; the rest of the name is exact camelCase.
Two phases with a stop between them — recommend, then change — because an edit made before the recommendation has been read cannot be reviewed on its own terms. Track progress:
- [ ] 1. Profile resolved, commit compared with HEAD
- [ ] 2. Evidence chosen by the user from what the profile carries — asked, not assumed
- [ ] 3. Each source read the way its own document says
- [ ] 4. Every code finding tied to a frame and to source that was actually read
- [ ] 5. Recommendation written, code and configuration findings kept apart — STOP
- [ ] 6. Accepted edits made, built, tested, re-profiled where possible
Started from Implement fixes — another skill's analysis handed over the profile id and its findings, each with its frame or setting, its figures and its link. Resolve the commit (step 1), skip choosing the evidence (step 2: the user already chose it there), and start at reading the source for those findings. The gate in step 5 stays: nothing is edited before the user picks.
Start from profiles_list, or recordings_analyzeFile when the user named a file (the
analyze-jfr skill covers that path). Then profiles_get and read recordingCommit:
git rev-parse HEAD — say so in one line and continue; when recordingDirty is true, add
that the build had uncommitted changes, so a line may not be where the checkout has it;null — say the commit is unknown, not that it matched. Importing with recordings_analyzeFile
and its commit argument fixes that for a recording made here; -Dgit.commit=<sha> on the
profiled JVM fixes it for one made anywhere (recordingCommitSource then reads SYSTEM_PROPERTY).When the code being advised on is not this checkout but one open in the reader's IntelliJ,
ide_windows reports the branch and HEAD commit of every open window and marks which of them is on
the commit the recording was built from — the same check, for the tree the reader is actually
looking at.
Ask what the profile carries before asking anything else. One call to profiles_summary says
which areas this profile can answer at all — its investigationAreas lists each area with its
availability, its weight and, when the evidence points there, suggested with the evidence
(a fired rule, the dominant kind of sample). Analysing every family unconditionally is a fishing
expedition: it costs a dozen calls and buries the two findings that matter under twelve that do not.
If the user named an area — in the scope argument or in the request — do that one and skip the
menu. Otherwise ask. Put the AVAILABLE areas to the user the way analyze-jfr does — as one
AskUserQuestion with a multi-select question per group in Claude Code, a table elsewhere — each
with its weight and what it would lead to in the code, the suggested ones marked with their
evidence, and the NOT_RECORDED ones named in one line with their remedy. Then stop until the
user picks. Do not export anything first to make the menu look better informed.
The weight is what an area puts into this conversation: MEDIUM a short chain of dashboard calls
with compact answers, HEAVY a Markdown export of tens of thousands of characters per group,
which is also what makes step 4 slower. A pick is worked in the order given, sending the area's
nextTools unchanged; an area nobody picked is not analysed, and belongs under not assessed
only if the user's question needed it.
| Group | Event type (first present wins) | Export options |
|---|---|---|
cpu | jdk.ExecutionSample, else jdk.CPUTimeSample | defaults |
wall | profiler.WallClockSample | defaults |
alloc | jdk.ObjectAllocationSample, else jdk.ObjectAllocationInNewTLAB, else jdk.ObjectAllocationOutsideTLAB | useWeight: true (bytes, not call count) |
lock | jdk.JavaMonitorEnter, else jdk.JavaMonitorWait, else jdk.ThreadPark | useWeight: true (nanoseconds blocked) |
Report a notRecorded group rather than analysing it, with the async-profiler option that would
capture it next time: event=ctimer (cpu), wall=10ms, alloc=512k, lock=10ms.
A flamegraph is not the only evidence, and for several real problems it is the wrong one: a thread blocked on a lock or a socket is not on-CPU, so it is never sampled and the graph reports the application as idle rather than as waiting. Each row below says what the evidence proves and how it gets you to a line of code, because a finding that cannot reach source is not something this skill can act on.
| Area | Start with | How it reaches source |
|---|---|---|
latency | traces_overview, then traces_operations; traces_notifications first when any is CRITICAL or HIGH | traces_slowestTraces → traces_traceExport → traces_spanFlamegraphExport, which gives frames for one span — continue from step 4 with that export rather than the whole-recording one |
latency, per population | traces_attributeKeys → traces_attributeValues | A value whose p95 stands apart names the population; traces_attributeSearch gives its traces, and one of them exports to frames |
waiting, locks | blocking_overview → blocking_monitors | The monitor class names the lock; find the synchronized block or Lock in the checkout. blocking_pinnedThreads points at a synchronized block on a carrier thread |
waiting, I/O | io_overview (SOCKET, FILE) → io_endpoints → io_slowest | The target names the dependency or file; the fix is at the calling code — fewer round trips, batching, caching, or not waiting |
memory | memory_allocations | The types ranked here are the other axis from the allocation flamegraph; take a type back to the alloc export to find the site |
heap, a dump | heap_getLeakSuspects | Each suspect carries its class, its gcRootPath (the fields from a root, or the thread and stackFrame that hold it) and its accumulationPoint: the class and field name the holder. Find where that collection is filled and nothing takes from it — the change bounds it, evicts, or lets go of the reference. One dump shows a state, not a trend: say whether the finding is a leak or a large working set, and heap_diff against an earlier dump when it matters |
| database | jdbc_overview → jdbc_statementGroup | code_callSites with the statement's event type and your framePrefixes names the lines that issue it (ownPath: your database wrapper, then its callers) and how often one request does — repeatedPerTrace is the N+1 shape. jdbc_pools is a configuration finding, not a code one — see step 5 |
| HTTP, gRPC | http_overview / grpc_overview (direction: SERVER or CLIENT) | An inbound endpoint is your handler; an outbound call is a dependency, and the change is at the call site |
| when, not where | timeline_hotWindows | Not a finding on its own. It gives startEpochMs/endEpochMs to scope an export to, which is what makes a burst visible that a whole-recording graph averages away |
Two that shape a recommendation without being one: profiles_samplerHealth, because a recording
that dropped a large share of its samples understates its own hot paths and every percentage below
inherits that; and jvm_flags plus jvm_container, because a tuning claim is only worth making
against the values the JVM really ran with.
With this checkout open, rank before you export. For each flamegraph group the user picked,
code_hotspots with the group's event type, its options and your framePrefixes (see Your own
code) ranks this repository's methods by the cost charged to them — each sample goes to the deepest
frame of yours on its stack — with the lines it was taken on and delegatedTo, the frames below it
the cost went into. That is what step 4 needs, in a few kilobytes rather than an export's tens of
thousands. Export the tree only when a path matters — a method reached from several callers,
orchestration whose children you have to walk.
One export per flamegraph group the user picked, whole recording, default threshold. Every export
opens with its own reading instructions and an analysis section written for that event type — what
counts as a hotspot, what the frame tags mean, what to skip. That document governs, not generic
flamegraph lore. Lower thresholdPct only to chase one specific path deeper.
One picked group: call flamegraph_export here, so the document is in front of you for step 4 and
for the user's follow-up questions. Several picked groups: send each to a jfr-analyst
agent — microscope:jfr-analyst from the Claude Code plugin, or the Codex custom agent from
codex/agents/jfr-analyst.toml — one delegation per group, all in a single message so they run
at once. Each returns the hot frames with their shares; several raw exports would otherwise crowd
out the source reading that step 4 depends on. An export the client saved to a file the analyst cannot
open comes back under Saved, not read, with its call: read those files here. Without an agent, export
the picked groups here one after another. A group the user did not pick is not exported, and is not delegated either.
When the recommendation is written, offer at most two further areas the evidence points at — each with its tag — rather than analysing them.
For each method a finding will name, code_method with its class, method and your framePrefixes
is one call for what grep and an export only approximate: its callers, the nearest of your methods
above a library one, the lines inside it the samples landed on, the exceptions thrown under it and
the traced requests that run it — every figure keyed by the source name, with matchedFrames
listing the lambda bodies and nested classes merged into it.
The export has call paths and numbers; a frame carries a line only when every sample at it agreed on
one, so treat a printed line as a place to start reading and its absence as no information. Map the
heaviest frames to the checkout with Read, Grep and Glob — or, when the reader has IntelliJ open
with the Jeffrey plugin, ask it: ide_resolve returns the file and line for a class and method and
flags a position that is decompiled, imprecise, or in a file edited since the recording. It is worth
a call for anything a grep would get wrong — a nested class, a Kotlin facade, an inherited or
overloaded method — and for library code, where ide_source reads what is not in this repository at
all. It does not move the reader's editor; ide_open does, so save that for when they ask to be
shown something.
Hold to these rules — they are what separates a recommendation from a guess:
total, self, the percentage) from the export,
so the reader can check the claim against the profile.self ≈ total) from orchestration (self << total): recommend changes
to the former, walk into the latter.Write the recommendation in this shape — it is the report skill's shape, with the code findings
carrying the recommendation the analysis stage left out:
capabilityGaps from profiles_summary that touched the question belong here, as not
assessed, never as a negative result.### <file>: <method> section each: the cause, why it is hot according
to the profile (the frame and its share, the operation and its p95, the monitor and its blocked
time — whichever measured it), and the proposed change in prose — minimal, behaviour-preserving,
reviewable on its own. No diffs in this phase.profiles_samplerHealth), a rule that fired rather than a figure that was measured.Then ask which findings to apply, and wait for the answer. This is the gate. In Claude Code ask
with AskUserQuestion, one multi-select option per finding (its one-line title, the edit or setting
it leads to in the description), when there are at most four; with more, list them numbered and let
the user name the ones to apply.
A finding that reaches neither source nor a setting is not a finding yet. Say what it measured and what would be needed to act on it, rather than inventing a change to attach to it.
For each accepted finding:
recordings_analyzeFile the new recording (with commit and dirty, so the profile says
which source it measured), and put it against the one the finding came from: compare_methods
with the methods you changed, the same event type and your framePrefixes, answers for exactly
those methods and lists unlistedMovers — a cost the change pushed somewhere else. A flamegraph
comparison needs the same group with the same parameters — keep threshold and options
identical, or a difference in pruning will read as a change that is not there.total share: a change cannot save more time than the frame used.profile-run skill records the changed code, and compare-jfr puts the new
profile against the one the finding came from.heap_diff (the earlier dump as the baseline): the
suspect's class should stop growing. A build and green tests do not show that.The order matters here more than anywhere else, because the wrong first question wastes the whole
investigation. A CRITICAL or HIGH notification is the application's own account of what went
wrong and comes before any frame: traces_notifications usually names the cause a span tree only
shows the cost of. Then the population before the exemplar — traces_operations for where the
wall-clock went, or traces_attributeValues when one tenant or customer is slow and the rest is
fine — and only then one trace, its span tree, and the frames inside the slow span.
Two traps worth naming. A request that is slow while every statement is fast is waiting for a
connection: that is jdbc_pools, it appears nowhere else, and no change to a query will fix it. And
an outbound call that is slow belongs to a dependency — the local change is to call it less often,
batch it, cache it or stop waiting for it, not to optimise code you do not own.
Jeffrey never reads this repository, so it is told which code is the application's own: the root
packages of the source tree you are in, passed as framePrefixes. Work them out once and reuse them
for every call:
Glob for **/src/main/java/**/*.java and **/src/main/kotlin/**/*.kt and take the shortest
package roots shared by the files (usually two or three segments: com.acme.orders.). Fall back to
the groupId in pom.xml or the group in build.gradle(.kts). In a multi-module repository
where the question is about one service, take that module's packages and the shared ones it uses.com.acme. does not also match com.acmecorp..java., org.springframework.):
library and JDK work is already charged to the own method that called it. What a library costs on
its own is read from flamegraph_export.com.acme.orders." — so the user can correct you before
anything depends on it. code_hotspots called without them answers with the profile's busiest
non-library packages as suggestedFramePrefixes; one that differs from yours means the profile is
of another application, or the code was shaded or relocated.A frame comes back by its runtime name, and source and runtime spell code differently: a lambda body
runs as Outer#lambda$method$1, a nested class is Outer$Inner at runtime and Outer.Inner in
source, a Kotlin top-level function lives on FileKt, a Kotlin lambda or coroutine is a class named
after its function (Outer$method$1). code_method takes the source spelling and lists every runtime
name it merged in matchedFrames — read them before you name a line of source for a figure. A row of
code_hotspots or code_callSites, and each of compare_methods' unlistedMovers, carries its
reference in that spelling: pass it on as it is, never the row's runtime methodName. A hotspot that
is your own wrapper — a database client, an HTTP helper, a generic executor — is charged everything
below it, so the change is rarely in it: its calledFrom names the code of yours in another class that
asked for the cost (the repository method behind a query, the service behind a call), and that is where
a fix lands. Name both. A method compare_methods answers NOT_SEEN lists
nearestReferences — most often the same method with its nested class or package spelled out
(com.acme.Checkout.PriceCalculator#formatLine for Checkout#formatLine). A NOT_SEEN method has
no figures: if the answer's first nextTools entry is compare_methods, make that call before you
read, report or compare any figure of that method. It respells the methods Jeffrey can match without
doubt. Never stand in an unlistedMovers row for a listed method: its charged cost leaves out the
own methods it calls, so it hides the very change a diff added below it. With no such entry, the
candidates are ambiguous or live in another class; check their classes in the source before you pass
one yourself.
Whenever a reply names something Microscope can open — the profile, a flamegraph, an operation, a
trace, an endpoint, a statement group, a GC, JIT or thread page, a heap class or object, a
differential, a catalogue row, a ledger entry — make the name a Markdown link marked with ↗:
[trace 7e34c5994dc96208 ↗](<its uiLink>), and in a table a column of [↗ open](<its uiLink>).
Every link carries the mark — every profile named too, the analysed one and its baseline alike, and
a page named in passing ("the exceptions page"), a profile named under Not assessed or Open
leads, and a figure's source given as the page it was read off ([slowest traces ↗](<its uiLink>)) — the
links most often left bare: [checkout candidate ↗](<its uiLink>) — and never the bare URL. The ↗ is what makes it a link the
user sees: a terminal that renders links shows the text alone, clickable, with the URL behind it,
and an unmarked name reads as plain words. That holds in every reply, not only in a written report:
a finding, a ranked list, a follow-up offer, a sentence in passing. Before you send a reply, check
it: every ]( closes a link text that holds ↗.
uiLink — a trace, an
operation, an exemplar — links with that one; otherwise the answer's uiLink is the page that
shows the row. Quote the uiLinkNote beside it when there is one.profiles_viewLink, one cheap call; the profile itself → profiles_link.[GC page ↗](<its uiLink>) — and
a tool stays in backticks beside it, plain. A tool you did not call — a follow-up on offer, a check under
Not assessed — is named that way and not linked at all: `jvm_safepoints` alone, never
[`jvm_safepoints`](<a link>) and never the profile's own link in place of a page you have no link for.flamegraph_list reports no graphable event types → a heap dump, or a recording without
samples; there is nothing to advise on from a flamegraph. For a heap dump, the analyze-heap
skill applies.HEAD and the user does not want to switch → analyse anyway,
and say in the summary that every file reference was checked against a different commit than
the one profiled.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
profiling, performance-optimization, jfr, flamegraph, code-change
npx claudepluginhub petrbouda/jeffrey --plugin microscope13 skills in this plugin
/analyze-connectorFinds and analyses JVM recordings that live on the connector (the recording volume on an Azure file share, or in a local directory) rather than in a file the user has — the JFR recordings, heap dumps, application logs, GC logs and crash files a deployed application produced. Use whenever the user asks about what an environment recorded or wrote rather than about a file they have: production, staging, a named service, "the last hour", "since the deploy", "what the connector has", "why was prod slow this morning", "why did the pod's JVM die", "the exceptions in the service log". It locates the session, asks which interval matters, pulls in that part of the recording — or the one file that matters — and hands off to analyze-jfr or analyze-heap, or reads the log itself. For a recording file already on this machine, analyze-jfr applies directly./analyze-exceptionsAnalyses the exceptions an application threw in a Jeffrey profile and traces each one to the code in the current repository that caused it — separates the application's throws (libraries included, so timeouts and connection resets stay) from the JVM's own class-loading and linking noise, finds where the application's code entered each throw, reads that source and recommends the smallest fix. Use whenever the user asks to analyse the exceptions or errors of an application, service or recording, why an application throws so much, what an exception storm or a burst of timeouts in a profile is caused by, whether exceptions are used as control flow, or names an exception class seen in a JFR recording or Microscope's Exceptions page./analyze-heapAnalyses a heap dump held by a running Jeffrey Microscope — what is holding the memory, what is leaking, which class loader survived a redeploy, where the waste is — starting from the catalogue or from a .hprof file Jeffrey has not seen yet. Use whenever the user asks what is holding memory, why the heap keeps growing, why the JVM ran out of memory, what is leaking, or mentions retained size, a dominator tree, GC roots, a heap dump or an .hprof file./analyze-jfrAnalyses a JVM profile held by a running Jeffrey Microscope — CPU, wall-clock, allocation, lock contention, trace latency, and the machine underneath: garbage collection, safepoints, JIT compilation, threads, native memory, the container and the JVM's configuration. Starts from the catalogue or from a .jfr file Jeffrey has not seen yet. Use whenever the user asks why something is slow, where the time goes, what is allocating, why GC pauses are long, what is pausing the JVM, what the JIT compiler or deoptimisation is doing, which threads are burning CPU, why memory grows outside the heap, whether the container is throttling, what a JFR recording or flamegraph shows, or mentions a Jeffrey profile, a .jfr file or async-profiler output. For a heap dump or .hprof file, analyze-heap applies instead./code-insightAnswers questions about the code in the current repository from a Jeffrey profile, asked by the names in the source - whether a method or class is hot, who calls it at runtime, which of its lines the time goes to, what it calls into, which exceptions are thrown under it, which requests run it, which of the repository's own methods a profile's cost is charged to, which lines issue a SQL statement or call and how often one request does (N+1), and what the application did at runtime - its operations, statements, attributes and own events - tied back to the code. Use whenever the user asks about the runtime behaviour of code they are reading or editing - "is this method hot", "who calls this in production", "what does this class cost", "which endpoint runs this", "where does our code spend its time", "which line issues this query", "is there an N+1", "what does this service actually do at runtime" - and a profile of that code exists or can be recorded./compare-jfrCompares two JVM profiles held by a running Jeffrey Microscope — a before and an after — using differential flamegraphs, to answer whether a change made the application slower, faster, or allocate more. Use whenever the user asks if a change regressed performance, what got slower or faster between two runs, to compare two recordings, benchmarks or branches, or mentions a baseline, a before/after or a performance regression. For a single profile, analyze-jfr applies instead; for a heap dump, analyze-heap.Other plugins' skills for the same job