1# Refactor your codebase | Codex use cases1---
2 2name: Refactor your codebase
3Codex use cases3tagline: Remove dead code and modernize legacy patterns without changing behavior.
4 4summary: Use Codex to remove dead code, untangle large files, collapse
55 duplicated logic, and modernize stale patterns in small reviewable passes.
6 6skills:
77 - token: $security-best-practices
8 8 url: https://github.com/openai/skills/tree/main/skills/.curated/security-best-practices
9Codex use case9 description: Review security-sensitive cleanup, dependency changes, auth flows,
10 10 and exposed surfaces before merging a modernization pass.
11# Refactor your codebase11 - token: $skill-creator
12 12 url: https://github.com/openai/skills/tree/main/skills/.system/skill-creator
13Remove dead code and modernize legacy patterns without changing behavior.13 description: Turn a proven modernization pattern, review checklist, or parity
14 14 workflow into a reusable repo or team skill.
15Difficulty **Advanced**15bestFor:
16 16 - Codebases with dead code, oversized modules, duplicated logic, or stale
17Time horizon **1h**17 abstractions that make routine edits expensive.
18 18 - Teams that need to modernize code in place without turning the work into a
19Use Codex to remove dead code, untangle large files, collapse duplicated logic, and modernize stale patterns in small reviewable passes.19 framework or stack migration.
20 20starterPrompt:
21## Best for21 title: Modernize in Small Passes
22 22 body: >-
23- Codebases with dead code, oversized modules, duplicated logic, or stale abstractions that make routine edits expensive.23 Modernize and refactor this codebase.
24- Teams that need to modernize code in place without turning the work into a framework or stack migration.24
25 25
26# Contents26 Requirements:
27 27
28[← All use cases](https://developers.openai.com/codex/use-cases)28 - Preserve behavior unless I explicitly ask for a functional change.
29 29
30Copy page [Export as PDF](https://developers.openai.com/codex/use-cases/refactor-your-codebase/?export=pdf)30 - Start by identifying dead code, duplicated paths, oversized modules, stale
31 31 abstractions, and legacy patterns that are slowing changes down.
32Use Codex to remove dead code, untangle large files, collapse duplicated logic, and modernize stale patterns in small reviewable passes.32
33 33 - For each proposed pass, name the current behavior, the structural
34Advanced34 improvement, and the validation check that should prove behavior stayed
35 35 stable.
361h36
37 37 - Break the work into small reviewable refactor passes such as deleting dead
38Related links38 code, simplifying control flow, extracting helpers, or replacing outdated
39 39 patterns with the repo's current conventions.
40[Modernizing your Codebase with Codex](https://developers.openai.com/cookbook/examples/codex/code_modernization)40
41 41 - Keep public APIs stable unless a change is required by the refactor.
42## Best for42
43 43 - Call out any framework migration, dependency upgrade, API change, or
44- Codebases with dead code, oversized modules, duplicated logic, or stale abstractions that make routine edits expensive.44 architecture move that should be split into a separate migration task.
45- Teams that need to modernize code in place without turning the work into a framework or stack migration.45
46 46 - If the work is broad, propose the docs, specs, and parity checks we should
47## Skills & Plugins47 create before implementation.
48 48
49- [Security Best Practices](https://github.com/openai/skills/tree/main/skills/.curated/security-best-practices)49
50 50 Propose a plan to do this.
51 Review security-sensitive cleanup, dependency changes, auth flows, and exposed surfaces before merging a modernization pass.51relatedLinks:
52- [Skill Creator](https://github.com/openai/skills/tree/main/skills/.system/skill-creator)52 - label: Modernizing your Codebase with Codex
53 53 url: /cookbook/examples/codex/code_modernization
54 Turn a proven modernization pattern, review checklist, or parity workflow into a reusable repo or team skill.54---
55
56| Skill | Why use it |
57| --- | --- |
58| [Security Best Practices](https://github.com/openai/skills/tree/main/skills/.curated/security-best-practices) | Review security-sensitive cleanup, dependency changes, auth flows, and exposed surfaces before merging a modernization pass. |
59| [Skill Creator](https://github.com/openai/skills/tree/main/skills/.system/skill-creator) | Turn a proven modernization pattern, review checklist, or parity workflow into a reusable repo or team skill. |
60
61## Starter prompt
62
63Modernize and refactor this codebase.
64Requirements:
65- Preserve behavior unless I explicitly ask for a functional change.
66- Start by identifying dead code, duplicated paths, oversized modules, stale abstractions, and legacy patterns that are slowing changes down.
67- For each proposed pass, name the current behavior, the structural improvement, and the validation check that should prove behavior stayed stable.
68- Break the work into small reviewable refactor passes such as deleting dead code, simplifying control flow, extracting helpers, or replacing outdated patterns with the repo's current conventions.
69- Keep public APIs stable unless a change is required by the refactor.
70- Call out any framework migration, dependency upgrade, API change, or architecture move that should be split into a separate migration task.
71- If the work is broad, propose the docs, specs, and parity checks we should create before implementation.
72Propose a plan to do this.
73
74Open in the Codex app
75
76Modernize and refactor this codebase.
77Requirements:
78- Preserve behavior unless I explicitly ask for a functional change.
79- Start by identifying dead code, duplicated paths, oversized modules, stale abstractions, and legacy patterns that are slowing changes down.
80- For each proposed pass, name the current behavior, the structural improvement, and the validation check that should prove behavior stayed stable.
81- Break the work into small reviewable refactor passes such as deleting dead code, simplifying control flow, extracting helpers, or replacing outdated patterns with the repo's current conventions.
82- Keep public APIs stable unless a change is required by the refactor.
83- Call out any framework migration, dependency upgrade, API change, or architecture move that should be split into a separate migration task.
84- If the work is broad, propose the docs, specs, and parity checks we should create before implementation.
85Propose a plan to do this.
86 55
87## Introduction56## Introduction
88 57
94 63
951. Remove unused code, stale helpers, old flags, and compatibility shims that are no longer needed.641. Remove unused code, stale helpers, old flags, and compatibility shims that are no longer needed.
962. Shrink noisy modules by extracting helpers, splitting components, or moving side effects to clearer boundaries.652. Shrink noisy modules by extracting helpers, splitting components, or moving side effects to clearer boundaries.
973. Replace legacy patterns with the repo’s current conventions: newer framework primitives, clearer types, simpler state flow, or standard library utilities.663. Replace legacy patterns with the repo's current conventions: newer framework primitives, clearer types, simpler state flow, or standard library utilities.
984. Keep public behavior stable while making the next change cheaper.674. Keep public behavior stable while making the next change cheaper.
99 68
100## How to use69## How to use
1032. Pick one cleanup theme at a time: remove unused code, simplify control flow, modernize an outdated pattern, or split a large file into smaller owned pieces.722. Pick one cleanup theme at a time: remove unused code, simplify control flow, modernize an outdated pattern, or split a large file into smaller owned pieces.
1043. Before Codex patches files, have it state the current behavior, the structural improvement it wants to make, and the smallest check that should prove behavior stayed stable.733. Before Codex patches files, have it state the current behavior, the structural improvement it wants to make, and the smallest check that should prove behavior stayed stable.
1054. Review and run the smallest useful check after each pass instead of batching the whole cleanup into one diff.744. Review and run the smallest useful check after each pass instead of batching the whole cleanup into one diff.
1065. Keep stack changes, dependency migrations, and architecture moves as separate tasks unless they’re required to finish the cleanup.755. Keep stack changes, dependency migrations, and architecture moves as separate tasks unless they're required to finish the cleanup.
107 76
108You can use Plan mode to create a plan for the refactor before starting the77You can use Plan mode to create a plan for the refactor before starting the
109work.78 work.
110 79
111## Leverage ExecPlans80## Leverage ExecPlans
112 81
113The [code modernization cookbook](https://developers.openai.com/cookbook/examples/codex/code_modernization) introduces ExecPlans: documents that let Codex keep an overview of the cleanup, spell out the intended end state, and log validation after each pass.82The [code modernization cookbook](https://developers.openai.com/cookbook/examples/codex/code_modernization) introduces ExecPlans: documents that let Codex keep an overview of the cleanup, spell out the intended end state, and log validation after each pass.
114They’re useful when the refactor spans more than one module or takes more than one session. Use them to record deletions, pattern updates, contracts that had to stay stable, and what’s still deferred.83They're useful when the refactor spans more than one module or takes more than one session. Use them to record deletions, pattern updates, contracts that had to stay stable, and what's still deferred.
115 84
116## Use skills for repeatable patterns85## Use skills for repeatable patterns
117 86
118[Skills](https://developers.openai.com/codex/skills) are useful when the same cleanup rules repeat across repos, services, or teams. Use framework-specific skills when available, add security and CI skills around risky cleanups, and create a team skill when you have a proven checklist for unused-code removal, module extraction, or legacy-pattern modernization.87[Skills](https://developers.openai.com/codex/build-skills) are useful when the same cleanup rules repeat across repos, services, or teams. Use framework-specific skills when available, add security and CI skills around risky cleanups, and create a team skill when you have a proven checklist for unused-code removal, module extraction, or legacy-pattern modernization.
119If you end up doing the same modernization pass across more than one codebase, Codex can help turn the first successful pass into a reusable skill.88If you end up doing the same modernization pass across more than one codebase, Codex can help turn the first successful pass into a reusable skill.
120
121## Related use cases
122
123[
124
125### Create a CLI Codex can use
126
127Ask Codex to create a composable CLI it can run from any folder, combine with repo scripts...
128
129Engineering Code](https://developers.openai.com/codex/use-cases/agent-friendly-clis)[
130
131### Create browser-based games
132
133Use Codex to turn a game brief into first a well-defined plan, and then a real browser-based...
134
135Engineering Code](https://developers.openai.com/codex/use-cases/browser-games)[
136
137### Follow a goal
138
139Use `/goal` when a task needs Codex to keep working across turns toward a verifiable...
140
141Engineering Automation](https://developers.openai.com/codex/use-cases/follow-goals)
142