explain-code
Skill0 starsChanged 53 days agoMITView on GitHub
Explains unfamiliar code the way a senior engineer walks a colleague through it — purpose, inputs, outputs, execution flow, dependencies, external services, data flow, failure modes, error handling, gotchas, improvements, tests, how to run and debug it, and a guided code tour, all grounded in the actual repository with file/line references and a clear split between confirmed, inferred and unknown. Draws architecture, sequence, data-flow, error-path and state diagrams; can produce a rendered visual HTML report (--visual) or a saved Markdown report with Mermaid (--save), a short version (--brief), a worked example that follows one concrete input through the code (--example), or explain what a change, branch or PR does (--diff). Works for any language, framework or architecture and any scope from a single function to an entire repository. Read-only — never modifies the code. Use when the user runs /explain-code or asks to explain, diagram, walk through, onboard onto, or understand how some code, feature, change or repository works, or "what happens when …". Not for reviewing whether a change is safe to ship — that belongs to a code-review skill.
- Reads credentials
51 other projects use a version of this.
Adopted by
Most recently taken up by
- netarz/gisoo-skills-registrytheir own version, first seen Nov 15, 2026
- jameswyse/skillstheir own version, first seen Nov 15, 2026
- bradydwardai/claude-skillstheir own version, first seen Nov 8, 2026
- renzrollon/interlocktheir own version, first seen Nov 5, 2026
- jorgenschaefer/skillstheir own version, first seen Nov 1, 2026
- sergerad/skillstheir own version, first seen Nov 1, 2026
Used with
Projects with it also use explore-codebase, write-tests and 10 more.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
srclightSkillexplore-codebase
This skill should be used when the user asks to "explore this codebase", "understand this project", "give me an overview", "how does this work", "onboard me", "walk me through the architecture", "map the codebase", or any request to understand a codebase's structure, architecture, or design.
Also in 3 projects that use this
SentrySkillwrite-tests
Write tests following project conventions. Use when adding new tests or modifying existing ones.
Also in 6 projects that use this
silvainfmSkillcopy-editing
When the user wants to edit, review, or improve existing marketing copy. Also use when the user mentions 'edit this copy,' 'review my copy,' 'copy feedback,' 'proofread,' 'polish this,' 'make this better,' or 'copy sweep.' This skill provides a systematic approach to editing marketing copy through multiple focused passes.
Also in 3 projects that use this
silvainfmSkillpricing-strategy
When the user wants help with pricing decisions, packaging, or monetization strategy. Also use when the user mentions 'pricing,' 'pricing tiers,' 'freemium,' 'free trial,' 'packaging,' 'price increase,' 'value metric,' 'Van Westendorp,' 'willingness to pay,' or 'monetization.' This skill covers pricing research, tier structure, and packaging strategy.
Also in 3 projects that use this
SentrySkillmarketing-psychology
When the user wants to apply psychological principles, mental models, or behavioral science to marketing. Also use when the user mentions 'psychology,' 'mental models,' 'cognitive bias,' 'persuasion,' 'behavioral science,' 'why people buy,' 'decision-making,' or 'consumer behavior.' This skill provides 70+ mental models organized for marketing application.
Also in 3 projects that use this
Google CloudSkillopen-pr
Commits local changes to a new Git branch and opens a GitHub pull request through the configured GitHub MCP server. Use when proposing code changes in a new pull request. Don't use for local-only commits without a remote GitHub repository.
Also in 3 projects that use this
- +1 more from getsentry
Other versions51 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 51
- AgnosticUI/agnosticui★ 832same name
- renzrollon/interlock★ 62same name
- Integralist/agent-skills★ 23same name
- zbruhnke/claude-code-starter★ 16same name
- rommelporras/kiro-config★ 13same name
- sidkh/skills★ 8same name
- bsene/skills★ 7same name
- holt-os/holt★ 7same name
- viknesh20-20/claude-code-tool-kit★ 7same name
- electronx/wiredkits-free★ 5same name
41 more not listed
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
The file
Show its rules and text
We split this skill into the rules it gives an agent
27 rules. 0 are common, 18 are distinctive, and 9 are very specific to this project.
0
Common
Most of the 43 edited versions we read keep these.
18
Distinctive
This author's own choices. Worth a look.
9
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 22
Read-only: Do not edit, create, refactor, reformat or delete files in the repository.
- Very specific: line 28
Never reveal secrets: If you meet credentials, tokens, keys, connection strings with passwords, or private certificates, say *that* they …
- Distinctive: line 33
Evidence over assumption: Do not claim a service, library or behavior is used just because it is in a manifest or has an SDK installed — …
- Distinctive: line 39
Don't ask what you can find out: Only ask the user a question when the scope is genuinely ambiguous *and* a wrong guess would waste …
- Very specific: line 45
Read these from $ARGUMENTS as flags *or* from plain wording.
- Distinctive: line 58
Not a review: If the user asks whether code or a change is correct, safe or ready to ship ("review my changes", "what did I miss?", "is …
- Distinctive: line 87
Use what the conversation already points at: a file the user opened, pasted code, a file or symbol mentioned earlier, an error message they …
- Distinctive: line 89
If nothing points anywhere, treat it as an entire-repository walkthrough.
- Very specific: line 90
If the snapshot shows uncommitted changes, add one line saying so and that --diff explains them.
- Distinctive: line 92
If there is no code to explain (empty directory, only docs/config), say what was found and stop.
- Distinctive: line 94
If "this function" can't be resolved to one symbol and several candidates are equally plausible, ask one short question listing them.
- Distinctive: line 130
Read the target, then follow references until the behavior is actually explained — not until the first file ends.
- Very specific: line 159
Stop tracing when further reading would not change the explanation.
- Very specific: line 164
Large repositories: don't read everything. Map the architecture, locate entry points, trace only the paths the question needs.
- Distinctive: line 172
Only when the code warrants it (checklists in the playbook):
- Distinctive: line 176
Potential security concern — requires verification: Don't overstate.
- Distinctive: line 182
Inferred findings need a way to check them: When a finding depends on something you couldn't confirm read-only (library semantics, runtime …
- Distinctive: line 189
Read references/diagrams.md.
- Distinctive: line 204
Read references/output-format.md before writing.
- Distinctive: line 213
Don't pad. When two sections would repeat each other for this scope, merge them and say so in the heading ("Outputs & Data Flow").
- Distinctive: line 224
Permalinks: when the snapshot provides a permalink template, code references link to the exact lines — rules in output-format.md (*Evidence …
- Very specific: line 238
Read the template. Fill every {{…}} placeholder.
- Very specific: line 246
Keep the template's styling.
- Very specific: line 249
If an
Artifacttool is available: delete both LOCAL-ONLY blocks (Artifacts supply the page skeleton and render Mermaid themselves), write … - Very specific: line 252
Otherwise: keep the LOCAL-ONLY blocks, write the file, and give the absolute path.
- Distinctive: line 289
No secret values anywhere — including report files?
- Distinctive: line 290
No generic textbook explanations?
“Common” is measured: kept by at least 6 in 10 of the 43 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
/explain-code — a senior engineer's walkthrough of unfamiliar code
Request: $ARGUMENTS
!python ${CLAUDE_SKILL_DIR}/scripts/repo_context.py || python3 ${CLAUDE_SKILL_DIR}/scripts/repo_context.py || echo "## Repository snapshot: unavailable (no Python found). Gather branch, commit, remote, uncommitted changes and top-level layout with read-only git and Glob."
Your job: help a developer understand code they have never seen, well enough to modify it tomorrow. Explain this code in this repository — not programming in general. Every important claim must trace back to a file and symbol the developer can open.
Accuracy beats sounding confident. If you did not read it, you do not know it.
Hard rules
- Read-only. Do not edit, create, refactor, reformat or delete files in the repository. Do
not install dependencies, change configuration, run migrations, start services, run tests, or
run anything that writes or has side effects. Reading, searching, and read-only git commands
are fine (the ones in
allowed-toolsrun without a prompt; anything else asks the user). The only file this skill ever writes is the report requested with--visualor--save, and it goes outside the repository unless the user gave a path (Step 7). - Never reveal secrets. If you meet credentials, tokens, keys, connection strings with
passwords, or private certificates, say that they exist and where (
.envdefinesSTRIPE_API_KEY), never their values — not in the chat, tables, code blocks or report files. This includes demo, seed and test credentials in READMEs or fixtures: point to where they are ("the seeded logins are listed inREADME.md") instead of repeating them. - Evidence over assumption. Do not claim a service, library or behavior is used just because it is in a manifest or has an SDK installed — show the call site. Never present an inference as a fact.
- No technology assumptions. Detect the language, framework, runtime, architecture and cloud from the repository. Use the project's own vocabulary (handler, controller, resolver, reducer, job, lambda, activity, DAG task, …).
- Don't ask what you can find out. Only ask the user a question when the scope is genuinely ambiguous and a wrong guess would waste significant effort. Otherwise pick the most reasonable interpretation, state it in one line at the top, and proceed.
Modes
Read these from $ARGUMENTS as flags or from plain wording. Modes combine
(--brief --visual, --visual --deep). With no mode, give the full walkthrough in the chat.
| Mode | Also triggered by | Effect |
--brief | "quick", "short", "tl;dr", "high level" | Short version (see Section sets in output-format.md). |
--deep | "in depth", "thoroughly", "everything" | Trace further (consumers, jobs, infra), all lenses, all sections plus Run & Debug and Glossary, more diagrams. |
--visual | "diagram", "visualize", "draw", "show me a picture", "HTML report" | Diagram-led HTML report (Step 7) + short chat summary. |
--save [path] | "save this", "write it to a file", "make a doc" | Markdown report with Mermaid diagrams (Step 7) + short chat summary. |
--diff [ref] | "explain this PR / branch / commit / my changes" | Explain what a change does and why (references/change-format.md). |
--example "<scenario>" | "what happens when …", "walk me through a request that …", "trace an example" | Follow one concrete input through the code with real values at each step (references/scenario-format.md). |
--for <audience> | "for a PM", "for a non-technical person", "for a reviewer" | Keep the facts, adjust vocabulary and depth. Non-technical: lead with the diagram and plain language, drop implementation detail, keep risks. |
Not a review. If the user asks whether code or a change is correct, safe or ready to ship
("review my changes", "what did I miss?", "is this safe to merge?"), that is a code review:
say so in one line, name a review skill from the available skills list if there is one (for
example /code-review), and stop, unless the user explicitly wants an explanation instead. --diff explains a change; it doesn't judge whether to merge it, though
its Risks section may point a reviewer at what to look at.
Workflow
Step 1 — Determine the scope
Classify the request into one scope and name the concrete target:
| Scope | Examples of what the user might say |
| Function / method / class | "this function", "parse_invoice", "the OrderService class" |
| File / module / package / component | "this file", "the auth package", "the Checkout component" |
| API endpoint | "POST /orders", "the upload API" |
| Feature / workflow | "how password reset works", "how X becomes Y end to end" |
| Service / integration | "the payment service", "how we talk to Salesforce" |
| Data flow | "how data gets from the API to the database", "where is X stored / sent" |
| Error flow | "what happens when the upstream times out", "this error flow" |
| Entire repository | "explain the entire repository", "onboard me" |
| Change | "explain this PR", "what does this branch change", "my uncommitted changes", --diff main |
| Scenario | "what happens when an expired token calls /orders", --example "PDF upload with no text" |
Tie-breaks: "how does X work" and "end to end" → feature/workflow. Use data flow only when the question is about where data goes or how it changes shape, not about behavior.
Resolving vague targets ("this", "this function", empty request):
- Use what the conversation already points at: a file the user opened, pasted code, a file or symbol mentioned earlier, an error message they shared, IDE selection context if provided.
- If nothing points anywhere, treat it as an entire-repository walkthrough.
- If the snapshot shows uncommitted changes, add one line saying so and that
--diffexplains them; don't switch to explaining the change unasked. - If there is no code to explain (empty directory, only docs/config), say what was found and stop; don't produce empty sections.
- If "this function" can't be resolved to one symbol and several candidates are equally plausible, ask one short question listing them.
For a change, read references/change-format.md now; it covers how to get the diff and how to structure the answer. For a scenario, read references/scenario-format.md now; the scope is whatever code that one input passes through.
State the resolved scope first, e.g. "Scope: the POST /v1/orders endpoint, traced from routing
to persistence and the outgoing webhook."
Step 2 — Orient in the repository (always, but proportionate)
The Repository snapshot above (captured when the skill started) already gives you the branch, commit, remote and permalink template, uncommitted changes, file counts, top-level layout, manifests, docs and CODEOWNERS. Don't re-run commands to get those facts. Then get just enough context to place the target:
- Stack: read the relevant manifests and build files the snapshot lists.
- Entry points and wiring: main files, route registrations, DI containers, handler configs, infrastructure definitions.
README,CLAUDE.md,AGENTS.md,docs/, ADRs if present.
Using docs: they are the fastest way in — they tell you where to look. They don't replace
reading the code: the main path in scope is always read in the implementation (Hard rule 3), and
that close reading is where most real findings come from. When docs and code agree, say so and
cite both ("matches docs/architecture.md"). When they disagree about anything a user, caller or
operator could observe (behavior, ordering, latency, errors, data written), write
"Documentation and implementation appear to differ." and describe what the code does.
Cosmetic drift (naming, a stale example) gets a one-line note, not the formal flag.
references/investigation-playbook.md has stack-detection signals and tracing techniques; read the parts you need when the stack is unfamiliar or the scope is larger than one file.
Step 3 — Trace the actual behavior
Read the target, then follow references until the behavior is actually explained — not until the first file ends. Follow, as relevant: imports, calls, inheritance and interface implementations, DI bindings, decorators/annotations/middleware, route tables, config keys and env vars, ORM models and repositories, event publishers and their consumers, queue/topic names, scheduled jobs, external service clients, auth guards.
entry (route / CLI command / event / cron / UI action)
↓ middleware, auth, validation
handler / controller / component
↓
service / domain logic
↓
data access / client
↓
database / queue / external APIAlso:
- Configuration: which config values and env vars change behavior on this path, and defaults.
- Tests: they reveal intended behavior, edge cases and business rules. Supporting evidence only; if they contradict the implementation, the implementation is what runs — say so.
- History (optional):
git log/git blameon a confusing section can explain why.
Line numbers must be exact. Take them from Read of a single file or Grep -n (a grep hit
is valid evidence for that line). Never cite lines from concatenated output (cat a b,
multi-file dumps), where numbering runs across files. Ranges (chat.py:252-295) are fine for
blocks. Re-check any line number you're unsure of before citing it.
Stop tracing when further reading would not change the explanation. When the trail leaves the
repository (a private package, another service, a generated client), record it as Unknown:
"charge() calls billing-sdk's Client.capture, whose implementation is not in this
repository, so the downstream behavior cannot be confirmed."
Large repositories: don't read everything. Map the architecture, locate entry points, trace
only the paths the question needs. For wide searches, delegate read-only discovery to an
Explore subagent and read the key files yourself. For an entire repository, give the
architecture first, then drill into the two to five subsystems that matter most, and say which
parts you did not examine.
Step 4 — Run the specialist lenses that apply
Only when the code warrants it (checklists in the playbook):
- AI / LLM — model calls, prompt construction, agents/tools, retrieval, embeddings.
- Security — authn/authz, input handling, injection, secrets, file handling, outbound requests, sensitive logging. Unconfirmed issues are labeled Potential security concern — requires verification. Don't overstate.
- Performance — N+1, unbounded reads, large payloads, blocking I/O on hot paths, missing pagination/caching, chatty external calls. Only meaningful concerns.
- Concurrency / async — shared state, races, ordering, idempotency, retries causing duplicates, resources (connections, locks, transactions) held across slow calls.
Inferred findings need a way to check them. When a finding depends on something you couldn't
confirm read-only (library semantics, runtime config, production data), label it Inferred and add
"To verify: <one concrete check>" — a test to write, a query to run, a log line to look for,
a doc page to read.
Step 5 — Plan the diagrams
Read references/diagrams.md. Diagram budget:
| Output | Diagrams |
Chat answer, --brief | 1 (the main flow) |
| Chat answer, default | 1–3 |
--visual / --save | 3–4 |
with --deep | up to 6 |
These are ceilings, not targets — draw a diagram only if it shows something prose can't. In a
--save report, the text version of the main flow doesn't count toward the budget. Every
node must be something you actually read. Text diagrams in the chat; Mermaid in report files.
Step 6 — Write the explanation
Read references/output-format.md before writing. It defines the sections, the evidence notation, which sections each mode and scope gets (Section sets), Run & Debug, the guided code tour and change recipes.
Explain first, critique second. For a "how does it work" question most of the words go to how it works; risks and improvements are concentrated in the failure, implementation-details and improvements sections, not sprinkled everywhere. For a "what could go wrong" or review-flavored question, lean the other way.
Don't pad. When two sections would repeat each other for this scope, merge them and say so in the heading ("Outputs & Data Flow"). A section that doesn't apply gets one line ("External services: none — pure computation.") or is dropped.
Step 7 — Write the report file (only for --visual or --save)
Location (both modes): the path the user gave, if any — that is the only case where the skill
writes inside the repository. Otherwise the session scratchpad directory if one is provided,
else <system temp>/explain-code/ (create it if needed). File name: <repo>-<scope-slug>.html
or .md. Never overwrite an existing file without asking.
Permalinks: when the snapshot provides a permalink template, code references link to the exact lines — rules in output-format.md (Evidence notation). In HTML they are generated by the page from one config block; in Markdown you write them for the main references only.
Size targets: --visual about 40–55 KB in total, --save about 20–40 KB. The masthead or
header Examined: line may list directories or counts ("12 files under backend/app/rag/")
instead of every file. Section titles may be renamed to fit the content (a merged "Outputs &
Data Flow", a centerpiece "How the scores work") as long as the order stays recognizable.
--save — Markdown, sections per Section sets, Mermaid diagrams (a text diagram may stay
for the main flow). Start with a header: scope, date, commit (from the snapshot, or "working
tree" if not a git repo).
--visual — HTML from assets/report-template.html:
- Read the template. Fill every
{{…}}placeholder. Add one<section id="…">per section in the--visualsection set, using the component patterns in the template's comment, then delete that comment. The diagrams carry the explanation and the prose stays short. - Diagrams go in
<pre class="mermaid">blocks (see the HTML escaping check in diagrams.md). Code references are<button class="ref" type="button">path:line</button>with a repository-relative path andlineorstart-end. Put the snapshot's permalink template (or"") and the paths with uncommitted changes into the#report-configblock; the page adds the link arrows itself. Never write permalink anchors by hand. - Keep the template's styling.
<title>: two to four words naming the subject ("Checkout Order Flow"). Stack chips: the 3–6 technologies that matter for this scope. - Deliver:
- If an
Artifacttool is available: delete bothLOCAL-ONLYblocks (Artifacts supply the page skeleton and render Mermaid themselves), write the file, check once that it contains no secret values, and publish it (Artifacts are private by default). Give the user the link. - Otherwise: keep the
LOCAL-ONLYblocks, write the file, and give the absolute path. Mention that it loads Mermaid and fonts from a CDN, so it needs internet to render.
- If an
Check the file before handing it over (both modes):
python ${CLAUDE_SKILL_DIR}/scripts/check_report.py <file> <Report check arguments from the
snapshot> — add --artifact before publishing an Artifact; use python3 if python isn't
available. It reports leftover placeholders, Mermaid
escaping and syntax problems, custom diagram styling, permalinks at the wrong commit or on files
with uncommitted changes, size, and anything that looks like a secret. Fix
every ERROR and re-run until it passes; fix WARN lines unless you're sure they're false
positives. If Python isn't available, do the same checks by reading the file.
Writing the report file asks the user for permission (Write is deliberately not pre-approved); that's expected.
Chat summary for --visual / --save (instead of the full walkthrough; for --example and
--diff, the summary rules in their format files take precedence): the scope line
(with a short "not examined" clause), the In one sentence line, the main flow as one text
diagram (repeating the report's main flow here is expected — chat and report are separate
outputs), 3–5 key points with certainty labels and references, the report path or link, and
"Where to go next". Key points = the one or two design facts that most shape the behavior, then
the most important risks or surprises.
Step 8 — Verify before sending
- Did I read the implementation — not only names, docs or tests?
- Did I follow dependencies far enough, and mark where I stopped?
- Is the entry point the real one (the thing that actually invokes this code)?
- Are inputs/outputs the meaningful ones, side effects separated from the primary output?
- Is every external service backed by a call site?
- Are failure scenarios grounded in the code, including notable unhandled ones?
- Are important claims referenced (
path:line+ symbol), with line numbers from single-file reads, and labeled Confirmed / Inferred / Unknown where not obvious? Does each Inferred finding that matters say how to verify it? - Does each diagram show a real mechanism, with labeled edges, real names and a caption? Does the Mermaid pass the checks in diagrams.md?
- Are Run & Debug commands taken from the repo rather than guessed?
- No secret values anywhere — including report files?
- No generic textbook explanations? No sections padded to fill the template?
- For a report file: did
check_report.pypass with no errors? Do permalinks skip files with uncommitted changes? - Would a new developer know which file to open first?
The result should read like a senior engineer's walkthrough — opinionated about what matters, honest about what isn't known — not an automated summary.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

