Reflect tree

From NikiforovAll/claude-code-rules · View interactive version

Reflect tree is an AI agent skill from the GitHub repository NikiforovAll/claude-code-rules. Visualize a Claude Code session as a quest/skill tree — a navigable SVG graph where nodes are turns and edges show flow, with distinct visual encoding for normal flow, dead-ends, corrections, retries, reversals, and backtracking. Sibling to /reflect (which produces an incidents+recommendations dashb

How to use this skill

Skill file

/reflect-tree — session quest-tree

Produce a single-file interactive HTML quest-tree of a Claude Code session. The vertical spine is the linear sequence of turns; back-edges and off-spine nodes encode wrong turns (corrections, retries, reversals, dead-ends, backtracks) so the user can see the whole journey at a glance — including detours and where the agent had to redo work.

This is a sibling to /reflect. Same input contract, different output: /reflect is a two-pane incidents/recommendations dashboard; /reflect-tree is a graph.

When to use

Session JSONLs live under: ~/.claude/projects/<encoded-cwd>/<session-id>.jsonl

Node classifications

Each turn becomes a node. Pick the strongest applicable label:

Edge types

Each non-normal node carries a refs array listing the ancestor turn IDs it relates to.

Knowledge mining (per-node insight)

Every node must carry an insight block — the single most important, reusable lesson from that turn, framed so a future agent could drop it into a prompt or rule. This is the value of the tree: each node becomes copyable knowledge.

For each turn, extract:

Skip prompt_snippet for filler normal turns (routine Reads/Greps with no insight). Better to have 6 strong insights than 50 weak ones.

The HTML drawer renders these per-node with a Copy insight button that copies prompt_snippet to the clipboard. A header-level Copy all insights button assembles every node's prompt_snippet into one markdown document grouped by classification.

Visual language

| Class | Shape | Color (CSS token) | Symbol |

|------------------|------------------|--------------------------|--------|

| normal user | filled circle | --accent | — |

| normal assistant | open circle | --fg | — |

| correction | diamond | --err border | ! |

| retry | double ring | --warn | ↻ |

| reversal | hollow square | --warn dashed | ⇄ |

| dead-end | filled X | --err | ✕ |

| backtrack | arrow node | --muted dashed | ↶ |

| self-correction | small diamond | --ok border | ✓! |

X-position: normal = center spine; correction/reversal nudged left; retry/dead-end nudged right. This keeps the spine readable while making detours visually distinct.

A legend is rendered inline in the header.

Collapsed-run capsule

When grouping consecutive normal turns into a capsule, render the entire label inside the rounded rect — turn-range, count, and topic together. Do not place the turn-range outside the box; it looks broken when the rect background only covers part of the label.

Pattern (SVG):

<g class="capsule" transform="translate(300 380)">
  <rect x="-150" y="-13" width="300" height="26"/>
  <text x="0" y="0">
    <tspan class="turn-range">T120–T139</tspan> · 11 turns · refactor + INFRA_GUIDE.md
  </text>
</g>

The rect width must accommodate the full text. Center the <text> (anchor middle, dominant-baseline middle) so it sits inside the rect. Use rx/ry ≥ 8 for the pill shape. Style the turn-range inline with <tspan class="turn-range"> so it stays bold/foreground while the rest of the label is muted.

How to render

Synthesize a fresh single-file HTML each run, using reference/example.html as inspiration (override anything that doesn't fit the actual session). The reference establishes:

Output directory — do not write inside the skill folder. Resolve a temp dir from the environment, in this preference order:

  1. $TMPDIR (Unix/macOS)
  2. $TMP or $TEMP (Windows / Git Bash)
  3. /tmp as fallback

Then create a reflect-tree/ subdir inside it (mkdir -p) and write the report as <that-dir>/reflect-tree/<slug>.html. Slug rules — kebab-case, derived from session goal:

Open it in the browser when done: start "" <path> (Git Bash on Windows).

Files in this skill

Workflow

Default (no args) — reflect on current session:

  1. From conversation memory, walk the turns in order. For each, decide the classification (default normal); for non-normal turns, fill in refs (which earlier turn(s) this re-attempts/undoes/contradicts).
  2. Group consecutive normal turns into capsules where they would clutter the spine.
  3. Read reference/example.html for the current aesthetic / SVG layout patterns.
  4. Write the tree to the temp dir (<temp>/reflect-tree/<slug>.html) — fresh HTML, same look-and-feel as the reference, populated with real turns/edges.
  5. Open it with start "" <path>.

Explicit session — /reflect-tree <id-or-path>:

  1. Resolve to a JSONL path (if just an id, look under ~/.claude/projects/<encoded-cwd>/<id>.jsonl).
  2. Run scripts/analyze_session.py <path>. Skill is forked (context: fork), so the compressed transcript is safe in context. No subagent.
  3. Walk the transcript and classify each turn yourself — the script does not classify. Focus on user/assistant exchange (what the user wanted vs. what the agent did), not raw tool patterns.
  4. Fallback to JSONL when transcript is lossy. Transcript truncates tool args/results and long messages. When detail matters (exact rejected input, full error body, Edit diff), Read the JSONL directly with offset/limit scoped to the event. JSONL is source of truth; transcript is the index.
  5. Render and open (default steps 2–5).

Notes

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.