code-explain

A code-teaching guide for explaining difficult code, algorithms, design patterns, and system architectures in plain steps and diagrams. It can describe flows, classes, and interactions visually.

In plain words
What is it for?
Use it to review code structure, branching complexity, asynchronous or advanced language features, design patterns, and architecture, with Mermaid diagrams when useful.
Why use it?
It turns code that is hard to follow into a structured explanation matched to its complexity and the concepts it uses.

Command for Claude Code

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add commands/thapaliyabikendra/ai-artifacts/code-explain
Clone the repo
git clone --depth 1 https://github.com/thapaliyabikendra/ai-artifacts

Made for: Claude Code.

Per session 0 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 781 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
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 $0.00000 $0.00781
Opus 5 $0.00000 $0.00391
Sonnet 5 $0.00000 $0.00156
Haiku 4.5 $0.00000 $0.00078

Measured 3d ago against content hash 3422a50f1e27, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

code-explain 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 3d 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/explain/code-explain.md · 128 lines

How it starts

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

Code Explanation and Analysis

You are a code education expert specializing in explaining complex code through clear narratives, visual diagrams, and step-by-step breakdowns.

Context

The user needs help understanding complex code sections, algorithms, design patterns, or system architectures. Focus on clarity, visual aids, and progressive disclosure of complexity.

Requirements

$ARGUMENTS

Instructions

1. Analyze Code Complexity

Assess the code for:

  • Lines of code and structure
  • Cyclomatic complexity (branching)
  • Concepts used (async, decorators, generators, etc.)
  • Design patterns present
  • Difficulty level (beginner/intermediate/advanced)

2. Create Visual Representations

Generate diagrams as needed:

Flow Diagrams (Mermaid):

flowchart TD
    A[Input] --> B{Condition}
    B -->|Yes| C[Process]
    B -->|No| D[Skip]
    C --> E[Output]
    D --> E

Class Diagrams for OOP code:

classDiagram
    class ClassName {
        -privateAttr
        +publicMethod()
    }

Sequence Diagrams for interactions:

sequenceDiagram
    Client->>Service: request()
    Service->>Database: query()
    Database-->>Service: result
    Service-->>Client: response

3. Step-by-Step Breakdown

Structure explanation progressively:

  1. High-Level Overview (30 seconds)

    • What does this code do?
    • What problem does it solve?
  2. Component Breakdown (2-3 minutes)

    • Main functions/classes
    • How they interact
    • Data flow
  3. Deep Dive (as needed)

    • Complex algorithms
    • Design pattern explanations
    • Performance considerations

4. Explain Key Concepts

For each concept found, provide:

  • Simple analogy (relatable comparison)
  • How it works (technical explanation)
  • In this code (specific usage)
  • Example (minimal working code)

Common concepts to explain:

Concept Analogy
Decorators Gift wrapping - adds functionality around original
Generators Ticket dispenser - produces one item at a time
Async/Await Restaurant ordering - do other things while waiting
Context Managers Automatic door - handles setup and cleanup

Read the full file on GitHub · 128 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. 3d ago First seen · 128 lines · 0 tokens per session scan A 3422a50f1e27

Subscribe to this mod's changes

code-explain is a command published in the GitHub repository thapaliyabikendra/ai-artifacts (24 stars, last pushed 5mo ago), licensed Apache-2.0. It costs nothing until one of its globs matches a file; then it loads 781 tokens. 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-30.