Agent slash commands
This project ships several Claude Code slash commands that drive the graph commands as their tools:
/codespine-interview— read-only; interviews you to scope a measurable optimization target and grounds each candidate in the graph./codespine-optimize— finds and applies one verified-safe optimization./codespine-name-communities— names theclustercommunities by what each one does, reading members from the graph and writing the labels back — no API key.
Because the agent runtime is Claude Code itself, there is nothing to configure beyond installing the commands and pointing them at a graph — the model, the API key, and the provider all come from Claude Code, as the next section explains.
Configuration with Claude
The agent has no configuration of its own — no model selection, API key,
provider, or .env file. That falls out of where it runs: the runtime is
Claude Code . Claude Code supplies the model and
the tool-calling loop; these slash commands and the codespine-query skill only
tell it what to do and which graph queries to reach for. There is no separate
agent process to host and no provider to point at.
So “configuring” the agent comes down to two things — making those instructions visible to Claude Code, and giving them a graph to query:
- The command and skill files must live in the project’s
.claude/. They are authored underdotclaude_folder/and mirrored into.claude/— the commands under.claude/commands/, thecodespine-queryskill under.claude/skills/. The next section covers installing them. - A loaded graph must exist at the default database
./.codespine/graph.kuzu. If it does not, both commands build it first withnpx codespine extract . --semanticfollowed bynpx codespine load. The--semanticflag is required: the agent relies on the caller and heritage edges that only a semantic extraction emits.
Installing the commands
The commands are already committed in this repository’s .claude/. For another
project, install them with one command from that project’s root:
npx codespine installThis copies the slash commands and the codespine-query skill into the
project’s .claude/ — see install (pass --force to
refresh existing copies). Inside this repository’s own checkout you can instead
run npm run symlink:dotclaude, or copy the files under dotclaude_folder/ by
hand. If Claude Code reports “/codespine-optimize is not a known command,” the
files have not been installed.
/codespine-interview
A read-only optimization analyst. Its job is not to change code — it interviews you, narrows a vague wish (“optimize this”) into one or more concrete, measurable, well-scoped tasks, and grounds each candidate in the graph so it points at real symbols. It finishes by presenting tasks; it never applies them.
/codespine-interview
/codespine-interview the JSON serialisation pathAn optional argument is treated as a starting hint (a dimension, subsystem, or named symbol) to steer the interview.
What “optimize” means
“Optimize” is multi-dimensional, so the command establishes the dimension rather than guessing. It walks you through five steps, one focused round of questions at a time:
- Dimension — execution time / latency, memory, infrastructure cost (including LLM tokens), network, scalability, maintainability, bundle size, energy.
- Business concern — the pain point, not the metric (“cloud bill too high”, “search feels slow”).
- Measurable target — a baseline and a target (
800ms → 300ms,10M → 2M tokens/day). If it cannot be measured, it cannot be optimized. - Scope — which part of the system, down to a specific module or symbol.
- Constraints — what must be preserved (functionality, security, API contract, UX, accuracy).
What the graph can and cannot ground
The graph is a static model: it knows symbols, callers, references, and dead
code, but holds no runtime telemetry (latency, CPU, memory, cost, frequency).
So the command is decisive for maintainability / dead-code work
(dead-exports is a direct source of candidates) and for
structural risk / coupling (rank centrality with
references, who-calls,
blast-radius, neighbors). For
runtime dimensions it can only show where a hot path lives structurally — you
must supply the measurement and baseline. It says so plainly rather than inventing
numbers.
Each drafted task is self-contained and shaped to hand to /codespine-optimize,
with a title, dimension and scope, target (real node ids and paths), measurable
goal, constraints, graph evidence, and an estimated risk argued from blast radius
and coupling. The command ends by telling you to run
/codespine-optimize "<task>" yourself with whichever task you choose.
Full definition:
dotclaude_folder/commands/codespine-interview.md.
/codespine-optimize
An autonomous TypeScript optimization agent that uses the graph as its eyes — resolved symbols and types, so its answers about callers, references, and dead code are precise where text search is not.
/codespine-optimize
/codespine-optimize Inline the single-use helper formatRow in src/report.tsWith no argument it runs the default mission: find one genuinely dead exported symbol, prove it has zero inbound references, and remove it safely. With an argument, it treats that text as the task.
The method
The command drives a find → confirm → edit → verify → keep/revert loop:
- Find a candidate —
dead-exports(dead code is the safest win) orfindto locate a named target. - Confirm the blast radius — before any change it confirms safety with
references(andwho-calls/blast-radiuswhen useful). A symbol is safe to remove only when it has zero inbound references. - Read the exact text so the edit matches the file precisely.
- Make exactly one edit.
- Verify, then keep or revert — runs
verify, one gate that runs the type-check and the test suite.ok: true→ the edit stands;ok: false→ it reverts immediately withgit restore <file>and tries a different edit or abandons the change. It never leaves a failing verify behind. - Measure the impact (optional) — when the task targets a runtime metric and a
workload exists, it can report a
benchmarkdelta. This is advisory — a noisy median, never a guarantee, and never allowed to override the hardverifyresult. - Stop and summarize — the file changed, the symbol removed, and why it was
safe. It states plainly how the edit was verified: type-checked and tested
only when
behaviorVerifiedwastrue; type-check-only (degraded) is reported as not behaviourally verified.
Rules it follows
- Node ids come from
findanddead-exportsoutput; it never invents them. - It acts autonomously — it does not ask you questions mid-run.
- It prefers removing genuinely dead exports or behavior-preserving simplifications, and never changes observable behavior.
- Run it on a clean git tree so a revert restores a known-good state and
git diffshows exactly what it kept. - At most one verified edit per run.
Full definition:
dotclaude_folder/commands/codespine-optimize.md.
/codespine-name-communities
Names the code communities that cluster has already
detected. Detection is the algorithm’s job; naming is a language task, and this
command hands it to the agent — no API call and no key, because the runtime is
Claude Code itself: it reads each community’s members and writes a label back.
/codespine-name-communities
/codespine-name-communities ./.codespine/project_01An optional argument is the output folder holding the graph (default
./.codespine); it is passed through as -o to every command.
The method
A dump → name → apply loop over two cluster subcommands:
- Dump the detected communities and their members with
cluster communities --json—{ index, currentLabel, size, members }, largest first. (If none exist yet, it runsclusterfirst.) - Name each community from its members — a concise noun phrase for its
responsibility (“Citation rendering”), not its location (
utils · citation). It leaves a community alone when the structural label is already a good name. - Apply the names with
cluster rename --labels <file>, which writesmetadata.communityLabeland the clustering manifest. Thewebviewlegend and reports then show them unchanged.
Because the labels are keyed by community index, it names after detection and
without re-detecting in between; a later cluster run resets
the labels to the structural baseline.
Full definition:
dotclaude_folder/commands/codespine-name-communities.md.
The codespine-query skill
Alongside these commands, install ships a skill,
codespine-query. Where the commands are missions (optimize, interview), the
skill is a reflex: it tells the agent to reach for the graph — not grep /
glob — whenever a question is about code structure or impact, and which command
answers it.
| Question | Command |
|---|---|
| Who calls this function? | who-calls |
| What does this function call? | calls |
| What breaks if I change this? | blast-radius |
| What uses this symbol or type? | references |
| Which exports are unused? | dead-exports |
| What is this connected to? | neighbors |
It also encodes the two ground rules every query here follows: resolve a name to a
node id with find --json first (never hand-write ids), and
consume the --json output rather than the human-readable table. So an agent in
any session — not only a /codespine-* run — uses the graph as its eyes for
impact and dependency questions.
Full definition:
dotclaude_folder/skills/codespine-query/SKILL.md.
See also
- The pipeline — running the agent on its first verified edit.
verify— the keep/revert gate the optimizer relies on.dead-exports— the safest starting point for both commands.