Skip to content

Royal-lobster/code-explainer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

157 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Code Explainer icon

Code Explainer

✨ Interactive code walkthroughs with editor highlighting and AI-powered voice narration.

A coding agent skill that scans your codebase, builds a walkthrough plan, and explains code segment-by-segment β€” highlighting lines in VS Code / Cursor with a dedicated sidebar panel and narrating with natural-sounding local TTS. Works with Claude Code, Codex, OpenCode, Kilo Code, Amp, and more.

Code Explainer cover

🎬 Watch Demo Β Β·Β  πŸ“ Read Writeup


πŸš€ Features

  • πŸͺŸ VS Code Sidebar β€” Dedicated sidebar panel with walkthrough controls, segment navigation, and live explanation display
  • 🎯 Code Highlighting β€” Automatically opens files, scrolls to code, and highlights 1–8 line ranges with per-highlight explanations
  • πŸ”Š Local TTS β€” Natural-sounding voice narration powered by Kokoro-82M (#1 ranked open-source TTS), running locally on Apple Silicon via mlx-audio
  • 🎬 Three Modes β€” Walkthrough (hands-free with TTS), Read (text in terminal), or Podcast (single audio file)
  • 🧠 Adaptive Depth β€” Overview or Deep Dive explanations based on your familiarity
  • πŸ“‹ Plan-First β€” Scout finds files, planner builds narrative order, parallel segment agents generate highlights β€” outline visible immediately, segments stream in as they finish
  • πŸ’Ύ Save & Share β€” Save walkthroughs to .walkthrough.json files, replay later or share with teammates via the repo
  • ⌨️ Keyboard Shortcuts β€” Full keybinding support for hands-free navigation

πŸ“¦ Requirements

  • 🍎 macOS (Apple Silicon recommended for GPU-accelerated TTS)
  • 🐍 Python 3.10+
  • πŸ“— Node.js 18+
  • πŸ–₯️ VS Code or Cursor with CLI enabled (code or cursor command)

πŸ”§ Installation

Just tell your coding agent:

Install the code explainer skill from https://github.com/Royal-lobster/code-explainer

Your agent will clone the repo into the skills directory, run setup.sh, and ask you to reload your editor β€” all while keeping you in the loop at each step.

πŸ“‹ Manual installation

Skill-native agents

These agents support the skills/<name>/SKILL.md format natively. Clone directly into the skills directory:

Agent Install commands
Claude Code git clone https://github.com/Royal-lobster/code-explainer.git ~/.claude/skills/explainer
Amp git clone https://github.com/Royal-lobster/code-explainer.git ~/.config/agents/skills/explainer
OpenCode git clone https://github.com/Royal-lobster/code-explainer.git ~/.config/opencode/skills/explainer
Codex CLI git clone https://github.com/Royal-lobster/code-explainer.git ~/.codex/skills/explainer

Then run setup:

<SKILLS_DIR>/explainer/setup.sh
# Reload your editor: Cmd+Shift+P β†’ "Developer: Reload Window"

Rule-based agents

These agents use their own rules/instructions format. Clone to any location, run setup, then point your agent's rules at the SKILL.md:

# 1. Clone to a shared location
git clone https://github.com/Royal-lobster/code-explainer.git ~/code-explainer

# 2. Run setup
~/code-explainer/setup.sh

# 3. Reload your editor: Cmd+Shift+P β†’ "Developer: Reload Window"

Then add a rule or instruction pointing to the skill:

Agent How to add
Cursor Add a .cursor/rules/explainer.mdc file in your project that includes the contents of SKILL.md
Windsurf Append the contents of SKILL.md to ~/.codeium/windsurf/memories/global_rules.md
Kilo Code Copy SKILL.md to ~/.kilocode/rules/explainer.md
Roo Code Copy SKILL.md to ~/.roo/rules/explainer.md
Cline Copy SKILL.md to your .clinerules/explainer.md directory

Note: The SKILL.md references relative paths (e.g., docs/assess.md), so the full repo must exist at the cloned location. For rule-based agents, ensure paths in the copied rules resolve correctly or use absolute paths.

What setup.sh does

  • 🐍 Python venv creation with TTS engine (mlx-audio + sounddevice)
  • 🧩 VS Code extension build and installation (.vsix for VS Code + Cursor)
  • πŸ—£οΈ Voice model download (~330 MB)
  • πŸ”‘ Script permissions

πŸ’¬ Usage

In your coding agent:

/explainer the authentication system

Or naturally:

Explain how the matching engine works
Walk me through the order flow
How does the WebSocket gateway handle events?

βš™οΈ How It Works

1. πŸ’¬ You ask to explain a feature
2. 🎯 Asks your depth preference (Overview / Deep Dive) and delivery mode
3. πŸ” Scout sub-agent maps the codebase β€” discovers relevant files and call chain

Overview path (fast):
4. πŸ“‹ Single agent builds plan + highlights in one pass β†’ sends set_plan

Deep Dive path (thorough):
4. πŸ—ΊοΈ Planner builds narrative order + transition objects
5. ⚑ Parallel segment agents generate dense highlights
   Waits for all agents to finish, then sends full set_plan to sidebar

6. βœ… Plan in sidebar + chat β€” approve, reorder, or skip before playback starts
7. πŸ”„ Walkthrough runs based on your chosen mode:
   Walkthrough β€” sidebar drives playback automatically with TTS narration
   Read        β€” step through explanations in terminal, highlights code as you go
   Podcast     β€” renders a single audio file of the entire walkthrough
8. πŸ“ Summarizes key takeaways

🎬 Modes

Mode Description
πŸŽ₯ Walkthrough Highlights move through code automatically while voice narrates in sync. Hands-free β€” just watch and listen.
πŸ“ Read Text explanations in terminal. Highlights code, explains in text, waits for "next". No sidebar or TTS required.
πŸŽ™οΈ Podcast Generates a single audio file of the entire walkthrough. Listen anywhere.

πŸͺŸ Sidebar Controls

The VS Code sidebar provides buttons for all walkthrough controls:

  • ▢️ Play / Pause β€” Toggle walkthrough playback
  • ⏭️ Next / Previous β€” Navigate between highlights within a segment
  • ⏩ Next / Previous Segment β€” Jump between segments
  • ⏩ Speed β€” Adjust TTS playback speed
  • πŸ”ˆ Volume β€” Adjust TTS volume
  • πŸ—£οΈ Voice β€” Select TTS voice
  • πŸ”‡ Mute / Unmute β€” Toggle voice narration
  • πŸ”„ Restart β€” Restart walkthrough from the beginning
  • πŸ’Ύ Save β€” Save current walkthrough to .walkthroughs/ for later replay
  • βœ• Close β€” Close walkthrough (prompts to save if unsaved)

πŸ’Ύ Save & Share

Save walkthroughs as portable JSON files that live in your repo:

# Save via CLI
./scripts/explainer.sh save auth-flow

# Load a saved walkthrough
./scripts/explainer.sh load auth-flow

# List all saved walkthroughs
./scripts/explainer.sh list

Or use the VS Code command palette:

  • Code Explainer: Save Walkthrough β€” Save with a custom name
  • Code Explainer: Load Walkthrough β€” Browse and load saved walkthroughs

Saved walkthroughs are stored in .walkthroughs/ at the workspace root with relative file paths, so teammates can pull them and replay on their own machine. The sidebar also shows a browse list of saved walkthroughs when no walkthrough is active.

⌨️ Keyboard Shortcuts

All shortcuts are active when a walkthrough is running:

Shortcut Action
Ctrl+Shift+Space Toggle play / pause
Ctrl+Shift+] Next sub-segment
Ctrl+Shift+[ Previous sub-segment
Ctrl+Shift+Alt+] Next segment
Ctrl+Shift+Alt+[ Previous segment
Ctrl+Shift+\ Stop walkthrough
Ctrl+Shift+= Speed up TTS
Ctrl+Shift+- Speed down TTS

πŸ’¬ Text Controls

You can also type commands in your agent's chat:

Command Action
next ⏭️ Move to next segment
skip ⏩ Skip current segment
skip to 4 🎯 Jump to segment 4
pause ⏸️ Pause walkthrough
mute / unmute πŸ”‡ Toggle voice narration
stop ⏹️ End walkthrough

πŸ—£οΈ Voice Configuration

Code Explainer uses Kokoro-82M via mlx-audio for high-quality local TTS. Falls back to macOS say if unavailable.

# Change voice
export TTS_VOICE=am_adam    # American male

# Change speed
export TTS_SPEED=1.2        # 20% faster

🎀 Available Voices

Voice Description
af_heart πŸ‡ΊπŸ‡Έ American English, female (default)
af_bella πŸ‡ΊπŸ‡Έ American English, female
af_sarah πŸ‡ΊπŸ‡Έ American English, female
am_adam πŸ‡ΊπŸ‡Έ American English, male
am_michael πŸ‡ΊπŸ‡Έ American English, male
bf_emma πŸ‡¬πŸ‡§ British English, female
bm_george πŸ‡¬πŸ‡§ British English, male

πŸ—οΈ Architecture

The extension runs an HTTP + WebSocket server on localhost for communication between your coding agent and the VS Code sidebar.

Coding Agent ──HTTP──▢ Extension Server ──Events──▢ Sidebar Webview
                           β”‚                            β”‚
                      Highlight API              TTS Audio Stream
                           β”‚                            β”‚
                     VS Code Editor              Browser AudioContext

🧩 Key Components

Component Description
🌐 Extension Server (server.ts) HTTP + WebSocket server with bearer token auth. Endpoints for plan delivery, state queries, save/load, and long-polling user actions.
πŸͺŸ Sidebar (sidebar.ts) Webview panel showing the walkthrough β€” segment list, per-highlight explanations, and playback controls.
πŸ”„ Walkthrough (walkthrough.ts) State machine managing segment and sub-highlight navigation and playback status.
🎯 Highlight (highlight.ts) Opens files, scrolls to ranges, and applies gold background decorations.
πŸ”Š TTS Bridge (tts-bridge.ts) Streams audio from the Python TTS server to the sidebar webview via WebSocket.
🐍 TTS Server (tts_server.py) Persistent Python daemon that loads Kokoro once and streams audio over a Unix socket.
πŸ’Ύ Storage (storage.ts) Save and load walkthroughs as .walkthrough.json files for replay and sharing.
πŸ“‘ Helper Script (explainer.sh) CLI wrapper around the HTTP API β€” used by the coding agent to send plans and poll for user actions.

πŸ“ Project Structure

code-explainer/
β”œβ”€β”€ πŸ“„ SKILL.md                      # AI agent skill instructions
β”œβ”€β”€ πŸ”§ setup.sh                      # One-command setup script
β”œβ”€β”€ πŸ“‚ scripts/
β”‚   β”œβ”€β”€ πŸ“‘ explainer.sh              # HTTP API helper for the coding agent
β”‚   β”œβ”€β”€ 🐍 tts_server.py             # Persistent TTS server (Kokoro-82M)
β”‚   β”œβ”€β”€ πŸŽ™οΈ podcast.py                # Podcast mode audio generator
β”‚   └── πŸ”„ reinstall-extension.sh    # Quick extension rebuild
β”œβ”€β”€ πŸ“‚ docs/
β”‚   β”œβ”€β”€ πŸ“– setup.md                  # Setup reference
β”‚   β”œβ”€β”€ πŸ—‘οΈ uninstall.md              # Uninstall guide
β”‚   β”œβ”€β”€ 🎯 assess.md                 # Preference gathering (depth + delivery mode)
β”‚   β”œβ”€β”€ πŸ” scan.md                   # Scout sub-agent (file discovery + call chain)
β”‚   β”œβ”€β”€ πŸ“‹ plan.md                   # Planner sub-agent (narrative + transition objects)
β”‚   β”œβ”€β”€ ⚑ segments.md               # Parallel segment agents (highlight generation)
β”‚   β”œβ”€β”€ πŸŽ₯ walkthrough.md            # Walkthrough mode (sidebar + TTS)
β”‚   β”œβ”€β”€ πŸ“ read.md                   # Read mode (text in terminal)
β”‚   β”œβ”€β”€ πŸŽ™οΈ podcast.md               # Podcast mode (single audio file)
β”‚   └── πŸ—£οΈ tts.md                   # TTS reference (voices, speeds)
└── πŸ“‚ vscode-extension/
    β”œβ”€β”€ πŸ“¦ package.json
    β”œβ”€β”€ βš™οΈ tsconfig.json
    β”œβ”€β”€ πŸ“‚ src/
    β”‚   β”œβ”€β”€ πŸš€ extension.ts          # Main entry point
    β”‚   β”œβ”€β”€ 🌐 server.ts             # HTTP + WebSocket server
    β”‚   β”œβ”€β”€ πŸͺŸ sidebar.ts            # Webview sidebar provider
    β”‚   β”œβ”€β”€ πŸ”„ walkthrough.ts        # Walkthrough state machine
    β”‚   β”œβ”€β”€ 🎯 highlight.ts          # Code highlighting
    β”‚   β”œβ”€β”€ πŸ”Š tts-bridge.ts         # TTS audio streaming
    β”‚   β”œβ”€β”€ πŸ’Ύ storage.ts            # Walkthrough persistence
    β”‚   └── πŸ“ types.ts              # Message protocol types
    └── πŸ“‚ media/
        β”œβ”€β”€ 🎨 icon.svg
        β”œβ”€β”€ πŸ–ΌοΈ icon.png
        └── πŸ“œ sidebar.js            # Sidebar webview script

πŸ“„ License

MIT

About

Interactive code walkthrough skill with VS Code highlighting and AI-powered voice narration

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors