Modernise Legacy Code One File at a Time
A big-bang rewrite is risky and rarely finishes. A better approach: ask Claude to modernise one file at a time, keeping the behaviour identical while updating the syntax and idioms.
@app/Services/OrderService.php
Rewrite this file to use modern PHP 8.2 syntax:
- Replace array() with []
- Add typed properties and return types where missing
- Replace null checks with the nullsafe operator (?->)
- Use match() instead of switch/case where appropriate
- Do NOT change any business logic — only modernise the syntax
Claude makes targeted, safe changes and leaves the logic untouched. Run your test suite immediately after to verify nothing broke — this workflow pairs perfectly with the TDD tip.
The same pattern works across languages and frameworks:
# JavaScript → TypeScript
"Add TypeScript types to this file without changing any runtime behaviour"
# React class components → functional components
"Convert this class component to a functional component using hooks"
# Deprecated library APIs
"Update this file to use the v3 API — the migration guide is at [url]"
For large files, ask Claude to explain its planned changes before making them — you can catch misunderstandings before any code is touched.
Modernising file by file is safer than a big rewrite, and Claude makes it fast enough to actually finish.
Log in to leave a comment.
Set up Claude Code as an automated reviewer in your CI pipeline — on every pull request, it reads the diff, checks for bugs, security issues, missing tests, and convention violations, then posts its findings as a PR comment. Your human reviewers get a head start because the obvious issues are already flagged before they look.
Before deploying, tell Claude to read your project — migrations, environment variables, queue workers, scheduled tasks, caching, third-party integrations — and generate a deployment checklist that's specific to your app. Not a generic "did you run migrations?" list, but one that knows YOUR infrastructure and catches the things YOUR deploy can break.
Instead of writing a README from memory or copying a template, tell Claude to read your project and generate one that's actually accurate — real setup instructions from your config, real architecture from your directory structure, real API examples from your routes, and real prerequisites from your dependency files.