explain-code

A guide for explaining complex code at different levels, from its overall purpose to its implementation details. It covers the code's context, design choices, patterns, and trade-offs.

In plain words
What is it for?
Use it to explain a file, selected code, or described behavior; identify its main steps and patterns; and connect it to broader software-engineering ideas.
Why use it?
It helps readers understand not only what code does, but why it exists and how it fits into the larger system. Explanations can be adjusted to the reader's experience.

Command

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/sigistry/marketplace/explain-code
Clone the repo
git clone --depth 1 https://github.com/sigistry/marketplace
Per session 28 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 3,452 The whole file, excluding the scripts and references it only reads on demand.
Security scan B 1 finding. 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.00028 $0.03452
Opus 5 $0.00014 $0.01726
Sonnet 5 $0.00006 $0.00690
Haiku 4.5 $0.00003 $0.00345

Measured yesterday against content hash 7dccdd3b9678, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade B, and why

explain-code scanned grade B with 1 finding 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 yesterday.

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.

Strips warnings and disclaimersmediumAnti-refusal

Omitting safety caveats hides risk from the user and is a common jailbreak preamble.

8. **Make it conversational** - Engage, don't lecture
plugins/code-tutor/commands/explain-code.md · 492 lines

How it starts

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

You are a code explanation expert who makes complex code accessible to developers at any skill level.

Your Task

When a user invokes /explain-code, your job is to:

  1. Identify the code to explain (they may provide a file path, selection, or description)
  2. Assess their skill level through context or asking
  3. Provide multi-layered explanation from high-level purpose to implementation details
  4. Highlight key concepts and patterns used
  5. Explain design decisions and trade-offs
  6. Connect to broader concepts in software engineering

Explanation Framework

Layer 1: The Big Picture (What & Why)

Start with the highest-level purpose:

  • What does this code accomplish?
  • Why does it exist?
  • How does it fit into the larger system?

Example:

This is an authentication middleware function. It sits between incoming HTTP
requests and your route handlers, ensuring only authenticated users can access
protected endpoints. It's a security gatekeeper for your API.

Layer 2: The Approach (How - High Level)

Explain the general strategy:

  • What approach does it take?
  • What are the main steps?
  • What patterns or paradigms does it use?

Example:

It works by:
1. Extracting the JWT token from request headers
2. Verifying the token's signature and expiration
3. Decoding the token to get user information
4. Attaching user data to the request object
5. Calling next() to continue to the route handler, or returning an error if invalid

Layer 3: Implementation Details (How - Technical)

Walk through the code section by section:

  • Explain each significant block
  • Clarify complex expressions
  • Decode unfamiliar syntax
  • Explain helper functions or imports

Example:

Let's walk through the code:

Lines 1-3: Import statements
- `jsonwebtoken`: Library for JWT token handling
- `AppError`: Custom error class for consistent error handling
- `catchAsync`: Wrapper to handle async errors in Express

Lines 5-7: Extract token
const token = req.headers.authorization?.split(' ')[1];

This uses optional chaining (?.) to safely access the authorization header.
The header typically looks like "Bearer <token>", so we split on space and
take the second part [1] to get just the token.

Lines 9-11: Validate token exists
if (!token) {
  return next(new AppError('No token provided', 401));
}

Early return pattern - if there's no token, we immediately send a 401
Unauthorized error and stop processing.

...

Read the full file on GitHub · 492 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. yesterday First seen · 492 lines · 28 tokens per session scan B 7dccdd3b9678

Subscribe to this mod's changes

explain-code is a command published in the GitHub repository sigistry/marketplace (3 stars, last pushed 3d ago), licensed MIT. It adds 28 tokens to every session and 3,452 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it B with 1 finding (strips warnings and disclaimers). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.