Data Science In Action

Data Science In Action

[Tutorial] Building Your First Claude Code Refactoring Agent

From spec to automated refactoring in 30 minutes. Step-by-Step: Build a Claude Code Agent That Refactors Your Legacy Codebase

Engy Fouda's avatar
Engy Fouda
Jun 22, 2026
∙ Paid

In the last article, I explained why agent-based refactoring works. Now you’re probably thinking, “Okay, that sounds great, but how do I actually build one?”

Let me walk you through it. By the end of this tutorial, you’ll have a working Claude Code agent that can refactor one of your modules according to a spec you define.

What we’re building: A Claude Code agent that standardizes function naming conventions in your Python codebase.

Time investment: 30 minutes.

Prerequisites: VS Code, Claude Code extension installed, and one Python module you want to refactor.


Step 1: Create Your Project Structure

First, create a new folder for your agent workspace. I’m calling mine refactor-agent.

mkdir refactor-agent
cd refactor-agent

Inside that folder, we need three markdown files that Claude Code will read:

  1. CLAUDE.md (your agent’s brain)

  2. REFACTORING-SPEC.md (the specification you want maintained)

  3. ARCHITECTURE.md (how your agent thinks about the problem)

Let me show you each one.

Data Science In Action is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.

User's avatar

Continue reading this post for free, courtesy of Engy Fouda.

Or purchase a paid subscription.
© 2026 Engy Fouda · Privacy ∙ Terms ∙ Collection notice
Start your SubstackGet the app
Substack is the home for great culture