explain-code

A command that explains unfamiliar code at several levels, from a high-level summary to detailed or line-by-line analysis.

In plain words
What is it for?
Use it for onboarding, knowledge transfer, or investigating a file, function, or module, including its callers, data flow, error handling, performance, testing, and unusual Python patterns.
Why use it?
It helps developers understand what code does, how it fits into the project, and where its dependencies, edge cases, and risks are.

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/benkapner/claude-code-basecamp/explain-code
Clone the repo
git clone --depth 1 https://github.com/Benkapner/claude-code-basecamp

Made for: Claude Code.

Per session 26 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 563 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.00026 $0.00563
Opus 5 $0.00013 $0.00282
Sonnet 5 $0.00005 $0.00113
Haiku 4.5 $0.00003 $0.00056

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

Security

Grade A, and why

explain-code 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 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.

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.md · 80 lines

How it starts

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

Explain Code

Analyze and explain code functionality at multiple levels of detail.

Instructions

Explain the code specified by $ARGUMENTS (a file path, function name, or module). If no argument given, ask what to explain.

Step 1: Context

  • Identify the file's role in the project
  • Review imports and dependencies
  • Check how it's called (grep for usage)

Step 2: High-Level Overview

  • What does this code do? (1-2 sentences)
  • What problem does it solve?
  • How does it fit into the larger system?

Step 3: Structure Breakdown

  • Break into logical sections
  • Map data flow and control flow
  • Identify key classes, functions, and their responsibilities

Step 4: Detailed Analysis

For complex or non-obvious sections:

  • Explain the algorithm or approach
  • Clarify data transformations and processing steps
  • Describe error handling and edge cases
  • Explain Python-specific patterns (decorators, generators, context managers, comprehensions)

Step 5: Practical Notes

  • Performance — bottlenecks, complexity, scalability concerns
  • Dependencies — external services, APIs, database operations
  • Testing — how to test this code, what scenarios matter
  • Gotchas — non-obvious behavior, implicit assumptions, known limitations

Output Format

FILE: [path]
PURPOSE: [one sentence]

OVERVIEW:
  [2-3 sentence summary]

STRUCTURE:
  [section breakdown with line ranges]

DETAILED ANALYSIS:
  [section-by-section explanation, focused on non-obvious parts]

PRACTICAL NOTES:
  [performance, dependencies, testing, gotchas]

Important

  • Scale depth to complexity. A 10-line utility gets a short explanation. A 200-line pipeline stage gets a thorough one.
  • Focus on the "why" not just the "what". Don't just describe what each line does — explain why it's done that way.
  • Use parallel agents (Explore) to check how the code is used across the project.
  • Skip the obvious. Don't explain import os or x = 5. Focus on logic that requires understanding.

Read the full file on GitHub · 80 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 · 80 lines · 26 tokens per session scan A 30b8269e3918

Subscribe to this mod's changes

explain-code is a command published in the GitHub repository Benkapner/claude-code-basecamp (16 stars, last pushed 12d ago), licensed MIT. It adds 26 tokens to every session and 563 once invoked, about $0.0001 per session on Opus 5. 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.