---
name: how
description: "Explain how code works by reading it: a subsystem's runtime flow, its architecture, where something should live. Use for \"how does X work\", \"X 는 어떻게 동작해\", \"이 구조 설명해줘\", \"이건 어디에 둬야 해\", or a walkthrough before changing code. Why it is this way, or why it was decided, is why."
---

# How

Explore the codebase to answer "how does X work?" questions. Produce architectural explanations at the level of a senior engineer onboarding onto a subsystem, enough to build a working mental model, not so much that it reads like annotated source code.

## Step 1. Assess Complexity

If the scope is ambiguous, state your interpretation and explore. The user can redirect.

- **Simple** (a single module, a small utility, a narrow question such as "how does function X work"): no explorers. One explainer explores and explains in a single pass. Go to Step 2b.
- **Complex** (a subsystem spanning multiple files or services, a cross-cutting feature, a full architectural overview): spawn parallel explorers first, then hand off to the explainer. Go to Step 2a.

When in doubt, take the simple path.

## Step 2a. Explore (complex questions only)

Decompose the question into 2 to 4 exploration angles, each a distinct slice of the subsystem. Spawn all explorers in a single message:

- `subagent_type`: `Explore` (the built-in read-only explorer)

Each explorer gets the prompt in `references/explorer-prompt.md` with its angle filled in. Then go to Step 3.

## Step 2b. Direct Explain (simple questions)

Explore and explain it yourself in one pass, following the Instructions and Output Format in `references/explainer-prompt.md` (skip its explorer-findings parts). Go to Step 4.

## Step 3. Synthesize (complex questions only)

Once all explorers have returned, spawn one `Agent` subagent to synthesize their findings into one explanation. Synthesize once; do not re-run it per explorer:

- `subagent_type`: `general-purpose`
- `model`: `opus`
- Tell it in the prompt that it only reads and writes the explanation; it must not edit files.

Build its prompt from `references/explainer-prompt.md` with every explorer's findings filled in.

## Step 4. Present

Present the explainer's output to the user. Light edits for clarity or context from the conversation are fine. Do not substantially rewrite it.

## Output Format

The explanation uses the sections defined in `references/explainer-prompt.md`, dropping any that do not apply: Overview, Key Concepts, How It Works, Where Things Live, Gotchas.
