How I Automated 6 Hours of Code Improvements While I Slept
Last night, I went to bed with a codebase that had 24 console.log statements scattered across production files, inconsistent color naming, missing accessibility tests, deprecated function calls in 23 components, and 8 stale branches cluttering my repository.
When I woke up? All fixed. Zero human effort during the night.
Here's how I used five AI agents working in parallel to knock out hours of tedious cleanup work while I slept.
The Problem: Technical Debt Compounds
Every developer knows this feeling. Your codebase accumulates small issues over time:
- Console.log statements you meant to remove
- Deprecated functions you never got around to updating
- Tests you planned to write "later"
- Dead branches from experiments that went nowhere
Individually, each takes maybe 30 minutes to fix. But together? That's a full day of monotonous work that keeps getting pushed to "someday."
The Solution: Parallel AI Agents
Instead of tackling these one at a time (or continuing to ignore them), I set up five Claude instances to work simultaneously. Each agent got its own isolated workspace and a specific mission.
Here's what each agent tackled:
| Agent | Task | Files Changed |
|---|---|---|
| 1 | Remove console.log from production | 7 API routes |
| 2 | Migrate deprecated color functions | 23 components |
| 3 | Add accessibility tests | 4 new test files |
| 4 | Standardize CSS class naming | 19 files |
| 5 | Clean up stale git branches | 8 branches deleted |
Wait, How Can They Work at the Same Time?
This is where it gets interesting. Normally, if two people edit the same file simultaneously, chaos ensues. Git will throw merge conflicts, changes overwrite each other, and you spend more time fixing the mess than you saved.
The trick is git worktrees.
Git Worktrees Explained Simply
Imagine your codebase is a document. Normally, you can only have one copy open at a time. If you want to make two different sets of changes, you have to finish one, save it, then start the other.
Git worktrees let you open multiple copies of that document simultaneously—each in its own folder, each on its own "branch" (version). Changes in one folder don't affect the others until you explicitly combine them.
Your Project/
├── main/ (your normal workspace)
├── agent1-worktree/ (agent 1's isolated copy)
├── agent2-worktree/ (agent 2's isolated copy)
├── agent3-worktree/ (agent 3's isolated copy)
└── ...
Each AI agent gets its own worktree. They can all read and write files without stepping on each other's toes because they're working in completely separate directories.
When they finish, the changes get merged back together in a specific order. Since each agent was working on different files, the merges are clean.
The Coordination: Boundaries Matter
The key to making this work isn't just parallel execution—it's clear boundaries.
Before launching the agents, I analyzed the codebase to ensure:
- No overlapping files: Agent 1's API routes don't touch Agent 2's components
- No shared dependencies: Agent 3's new test files don't import things Agent 4 is modifying
- Clear merge order: Some changes need to happen before others (infrastructure before code that uses it)
Each agent received a scope document specifying:
- Files they own (can modify freely)
- Files they can read (for context, but don't touch)
- Files they must not touch (another agent owns these)
This is essentially the same coordination strategy you'd use with a human team, just applied to AI agents.
The Results
Before (bedtime):
- 24 console.log statements in production
- 23 files using deprecated color functions
- 0 accessibility tests for interactive components
- Mixed naming conventions (emerald-* vs green-* CSS classes)
- 8 stale branches from old experiments
After (morning):
- 0 console.log in production
- 0 deprecated function calls
- 4 comprehensive accessibility test files
- Consistent green-* naming throughout
- Clean branch list
Human time spent: ~15 minutes to set up the plan, 5 minutes to review and merge in the morning.
AI agent time: ~4 hours of parallel work (but I was asleep, so it cost me nothing)
Why This Matters
This isn't about replacing developers. These tasks still required judgment:
- Deciding what counts as "production code" vs. acceptable logging
- Choosing the right migration pattern for deprecated functions
- Determining which components need accessibility tests
- Planning the merge order to avoid conflicts
The AI agents executed the tedious parts—finding every instance, making consistent changes across dozens of files, running tests to verify nothing broke.
That's the pattern: humans decide strategy, AI handles execution at scale.
How to Try This Yourself
The basic workflow:
- Identify independent tasks that touch different files
- Create worktrees for each parallel workstream
- Give each agent clear boundaries (what they own vs. can't touch)
- Plan merge order based on dependencies
- Review and merge when they finish
The setup takes some thought, but once you've done it a few times, it becomes second nature. And waking up to a cleaner codebase never gets old.
Want to learn more about AI-assisted development workflows? Check out our services or get in touch.
Need Help Getting Things Done?
Whether it's a project you've been putting off or ongoing support you need, we're here to help.