Skip to content

12. Safe Refactoring of Legacy Code (Characterize, Change, Verify)

September 29, 2026 · 45 min

Show notes

In Episode 12 of Beyond Prompting, we tackle one of the most high-stakes tasks in software engineering: letting an AI agent refactor an existing codebase. Author Sho Shimoda breaks down why asking Claude to "modernize this module" in one giant prompt usually results in hundreds of changed lines, broken production, and hours spent untangling regressions. In this episode, we cover:

    • The "Big-Bang" Trap: Why a single commit touching twelve files leaves you with twelve suspects when tests go red, and why working in small, single-purpose steps makes debugging instant.
    • Characterization Tests First: How to lock down the current behavior of legacy code by generating tests before refactoring, creating a behavioral safety net when no specification exists.
    • The 4-Step Refactoring Loop: Forcing Claude into a disciplined cycle—list distinct changes smallest first, execute one change, verify against characterization tests, and commit before moving to the next.
    • Reviewing Agent Diffs: How to review AI-generated code for subtle failure modes (like changed return contracts or deleted code paths) and using /code-review as a mechanical first pass.
    • Checkpoint Rewinds: Using Esc Esc or /rewind to instantly restore conversation and file state to an earlier checkpoint when an exploration fails.

(Note for listeners: This episode covers Chapter 12 of Sho Shimoda's book RUNNING CLAUDE: The Operator’s Guide to Chat, Cowork and Claude Code, available on Amazon as the successor book to Master Claude: Chat, Cowork and Code).

All episodes of Master Claude Chat, Cowork, Code

Settings

Display

Language

Decides which stations you see first on the home page.

History

Recently played stations and episodes and your latest searches are only stored in this browser.

Notifications

A short notice when a podcast you follow has a new episode. Turn off single podcasts with the bell on their page.

Account

Save favorites – in the app and on the website.

Keyboard shortcuts

/
Open search
Space
Play or pause
← →
In the player: back 15 s, forward 30 s (episodes) · in a row: next tile
↑ ↓
In a row: target within the tile
Home / End
In a row: first or last tile
Esc
Close window or menu
?
This overview
Now playing

Go to station page

Play next

    Add episodes with “Play next” – they play after the current episode.