Using OpenAI Codex to refactor a legacy codebase
I was an early GitHub Copilot Pro subscriber from its debut. A few months ago, the company I work for started rolling out GitHub Copilot Enterprise.
Because weโre allowed to use our personal GitHub account for work, I was asked to enrol with it. However, when I enrolled under the companyโs Copilot subscription, GitHub automatically refunded my personal subscription โ because a GitHub account can only have one active Copilot license. Reference: GitHub Community discussion
To avoid any potential IP ownership disputes, I decided to stop using GitHub Copilot entirely on my personal machine.
At the same time, Iโm a ChatGPT Plus subscriber. I use it for learning and daily creative tasks. Even though I treat it like a technical search engine quite often (and Iโve tried the web agent), I didnโt realize Codex could run locally inside VS Code until very recently (tried Codex CLI long ago but the experience wasnโt great).
So I decided to try it on a genuinely challenging project: refactoring a legacy backend codebase.
The legacy situation
The codebase consisted of:
- A data object project mixing multiple concerns
- Thirteen containerized nano-services deployed to GCP Cloud Run
- Everything targeting .NET Core 3.1 (around five to six years old at the time of writing)
Refactoring objectives
- Consolidate the shattered nano-service projects into a single API project
- Migrate from .NET Core 3.1 to .NET 10
- Move from a poorly organized project structure into a DDD-style structure
- Enable strict mode across all projects (TreatWarningsAsErrors)
My Codex setup
- Plan: ChatGPT Plus
- Model: GPT-5.1-Codex-Max
- Agent: Full Access
- VS Code extension: Codex โ OpenAIโs coding agent
- Reasoning effort: Medium

| C# files | Total LOC | Classes | |
|---|---|---|---|
| Before | 527 | 45,927 | 390 |
| After | 394 | 44,393 | 408 |
It also helped fix thousands of errors when I enabled strict mode.
Even with AI, it still took me around 10 nights (about 2 hours per night) to complete.
There was one time Codex told me Iโd run out of usage quota and needed to wait 24 hours.

This would have been extremely difficult to do manually without a significant time investment.

How I feel about Codex afterwards
Pros
- The model was able to pause and ask for meaningful confirmation, like:
This is a very large refactor (hundreds of lambdas/short params across all services and tests). Doing it in one shot risks regressions and will take a lot of time.
-
It also felt faster and more accurate (for this kind of refactor) than my typical experience with Copilot.
-
And with a single Plus subscription, it offered strong value โ not just for Codex, but also for day-to-day learning and creative productivity.
Cons
- Itโs a bit of a pity it doesnโt have Next Edit Suggestions (NES) like GitHub Copilot, which I personally find more useful for tight, single-file editing.
Conclusion
In the past Codex CLI requires OpenAI API account and charge by token consumption, this discovery saved me a few bucks from monthly subscription cost. :)
This post was originally published on [Medium].