/knowledge-graph:kg-extractfrom knowledge-graph
Maps codebase architecture into the knowledge graph by creating subsystem and component nodes with precise gists that enable skip decisions. Useful for navigating large projects and understanding file responsibilities without reading them.
Ships in knowledge-graph. 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.
Extract builds a two-tier navigation index in the project graph. The goal is precise: let future sessions answer "should I read this file?" without opening it.
Filenames and directory listings tell you what exists. The KG tells you what each piece handles and — equally important — what it doesn't, so skip decisions are reliable.
Directory-scale orientation. Answers: "which part of the codebase?"
kg_put_node(session_id, level="project", id="auth-subsystem",
gist="JWT issue/verify + refresh flow. No user lookup, no permissions — those are in user-subsystem.",
touches=["src/auth/"])
File-cluster-scale. Answers: "which file within that area?" One node covers 1–5 tightly related files that always change together.
kg_put_node(session_id, level="project", id="auth-token-signing",
gist="Signs/verifies JWTs only. Key rotation logic here, not in middleware.",
touches=["src/auth/jwt.ts", "src/auth/keys.ts"])
Component nodes are never created upfront in bulk — only when you actually explore that area during a task. They accumulate naturally as the codebase is worked on.
| Type | Tier | What it represents |
|---|---|---|
subsystem | 1 | Major bounded area (auth, payments, ingestion pipeline) |
component | 2 | Specific file cluster with a single clear responsibility |
resource | — | External state: database, cache, queue, third-party API |
entry | — | Invocation surface: HTTP route group, CLI command, cron, event |
contract | — | Shared interface: API schema, event type, shared types package |
The skip signal comes from knowing what's not here, not just what is.
| Pattern | Example |
|---|---|
| scope + explicit exclusion | "Stripe webhook ingestion — signature validation + idempotency. No business logic." |
| what it owns vs. delegates | "Rate limiting middleware. Reads Redis counters; does not write them — see rate-counter component." |
| surprising non-obvious fact | "Config parser runs at import time — any module reading config must import this first or gets stale values." |
Bad gist: "Authentication module" — tells you nothing about whether to open the file.
Good gist: "JWT issue/verify only — stateless, no DB calls, no session state" — skip decision made.
A touch that names a whole file saves a search; a touch that names a line range saves the read itself. When a specific block is what matters, point at it — with a short semantic anchor so the pointer survives line drift:
touches=["src/auth/jwt.ts:88-120 (rotation schedule)", "config/prod.yaml:30-40 (upstream block)"]
Whole-file touches are right for component nodes (the cluster is the unit); ranged pointers are right for knowledge nodes about one specific spot. Never point edges at file paths — edges relate concepts; touches locate them.
| Edge | Meaning |
|---|---|
calls | Runtime dependency (A uses B) |
persists | Reads/writes a resource |
serves | Handles an entry point |
exposes | Provides a contract |
consumes | Depends on a contract |
configures | Config artifact affects behavior |
guards | Middleware/validation wrapping another component |
kg_progress(session_id, task_id="extract")
Glob("**/package.json") # or pyproject.toml, go.mod, Cargo.toml
Glob("src/*") # top-level shape only
Glob("**/README*")
Identify: main directories, entry points, config files, key abstractions.
Map the 5–10 subsystems. Fast, coarse. Connect them to resources and entries.
kg_put_node(session_id, level="project", id="api-subsystem",
gist="HTTP layer: routing, validation, response shaping. No business logic.",
touches=["src/api/"])
kg_put_node(session_id, level="project", id="postgres-db",
gist="Primary store. Schema via Alembic migrations.", touches=["migrations/"])
kg_put_edge(session_id, level="project", from="api-subsystem", to="postgres-db",
rel="persists", notes=["via domain-subsystem ORM calls"])
Save progress:
kg_progress(session_id, task_id="extract", state={
"tier1_done": true,
"subsystems": ["api", "domain", "data", "auth"],
"last_updated": "2026-05-01"
})
When you open files in an area, add a component node for the file cluster. Do not create component nodes for areas you haven't touched.
kg_put_node(session_id, level="project", id="auth-token-signing",
gist="Signs/verifies JWTs. Key rotation here. Middleware is separate.",
touches=["src/auth/jwt.ts", "src/auth/keys.ts"])
kg_put_edge(session_id, level="project", from="auth-subsystem", to="auth-token-signing",
rel="contains")
Good: First session on a new codebase · after major refactor · user asks to map it
Bad: Mid-task (just add component nodes for what you're actually touching) · graph near token limit · project is small enough to Glob in one pass
# Tier 1 — Subsystems
kg_put_node(session_id, level="project", id="api-subsystem",
gist="FastAPI routes + request validation. No business logic — delegates everything to domain.",
touches=["src/api/"])
kg_put_node(session_id, level="project", id="domain-subsystem",
gist="Business rules + orchestration. Framework-free. Entry point for all logic.",
touches=["src/domain/"])
kg_put_node(session_id, level="project", id="data-subsystem",
gist="SQLAlchemy models + async sessions. Schema owned here via Alembic.",
touches=["src/data/", "migrations/"])
kg_put_node(session_id, level="project", id="postgres-db", gist="Primary store.")
kg_put_node(session_id, level="project", id="redis-cache", gist="Session store + rate limit counters.")
kg_put_edge(session_id, level="project", from="api-subsystem", to="domain-subsystem", rel="calls")
kg_put_edge(session_id, level="project", from="domain-subsystem", to="data-subsystem", rel="calls")
kg_put_edge(session_id, level="project", from="data-subsystem", to="postgres-db", rel="persists")
kg_put_edge(session_id, level="project", from="api-subsystem", to="redis-cache",
rel="persists", notes=["rate limiting only"])
# Tier 2 — Components (added later, as files are explored)
kg_put_node(session_id, level="project", id="auth-middleware",
gist="Validates JWT on every request. Injects user_id into request state. Does NOT issue tokens.",
touches=["src/api/middleware/auth.py"])
kg_put_edge(session_id, level="project", from="auth-middleware", to="api-subsystem", rel="guards")
What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub mironmax/kg-memory --plugin knowledge-graph5 skills in this plugin
/kg-coreKnowledge Graph — persistent, granular, evolving memory.
Part of memory arrives preloaded: a "KG MEMORY PRELOADED" block carrying the
session_id and most important portion of memory.
Then the full read is on you: kg_read(cwd="<project root>") comes
before any work, whatever the task. Full read still brings up only most important memories.
Recall: if a gist points in the right direction, read the full node;
Search for more — in a rich graph the fact you need is often buried
under fresher work; search reaches every tier.
Capture: at the moment of learning, once the dots connect.
One lesson, one node: the gist states the lesson so it holds beyond
the case that taught it; each note tells one case of this lesson — a
failure that taught or confirmed it, what happened, where.
Before writing, walk back through the session: each point where another
choice would have changed the outcome is a lesson — rarely just one.
A failure met again sharpens its lesson and adds a note.
Name: the id names the SUBJECT in 3-5 words, never a container
("…-lessons", "…-log"); ids are load-bearing in search.
Connect rather than duplicate; a new lesson still earns its own node.
Endorse with kg_useful — the nodes that helped, judged at wrap-up against
results, and the ones that were MISSING when they should have been there,
sent the moment the gap shows. That credit keeps a node alive, and a miss
is the only signal that corrects a wrong archival.
Mechanics live in the kg_* tool descriptions; operations in /kg-ops.
/kg-maintainKnowledge graph maintenance — a bounded, resumable pass that pays down the
graph's DEBT line (rendered after HEALTH in every kg_read). Run it when
invoked, when DEBT shows HIGH, or as a dispatched maintenance subagent.
The same work also arrives in a smaller shape: a CHORE, one category and
one or two named targets, dispatched by the server while someone is
working. Chores carry their own runbook in their prompt — this skill is
the full pass, and the place the chore memory is described.
Always-on reactive triggers (no pass needed, act mid-conversation):
User correction → update the stale node before continuing.
Node just proved useful → add one edge to current context.
Gist feels vague after using it → sharpen while context is live.
Just saved a node → check: duplicate? adjacent nodes need updating?
Archival is automatic and reversible — leave archived nodes alone.
Deletion is a last resort, only for the factually wrong and unfixable.
/kg-opsOperations runbook for kg-memory, the `kg` command and its plugins: install
and first run (kg setup, kg doctor), updates (kg update), server lifecycle
(kg start/stop/restart/logs), autostart via systemd, connecting Claude
Desktop/Cowork, Codex CLI, Antigravity, maintenance chores and
their runner, configuration, the quota-gauge
status line (reading your own 5h/7d limits), backup and restore, and
troubleshooting (tools offline, -32000 errors, stale data, Desktop issues).
Use when something needs setting up, breaks, or the user asks to manage the
memory server or "read the docs and do what's needed".
/kg-scoutMine Claude Code, Codex and Antigravity conversation history for patterns and insights worth preserving