Warning
Archived and no longer maintained.
Codex now supports changing the folders associated with a local project through Project menu > Edit project, including selecting a new primary folder. This tool modifies undocumented internal Codex state and should not be used with current Codex versions.
This repository is preserved for historical and educational purposes.
A Windows command-line tool that updates project-to-thread associations in the local Codex configuration after a project directory has been renamed or moved.
When a project directory is renamed manually, its threads may still appear in Codex search results but disappear from the project tree in the sidebar. This tool migrates structured references from the previous path to the new one without rewriting messages, commands, outputs, or historical logs.
Note
Unofficial, Windows-only community tool. This project is not affiliated
with or endorsed by OpenAI. Version 0.1.0 refuses to run migrations on other
operating systems. --help and --version remain available so the limitation
is visible without inspecting the source code.
Important
This tool modifies internal, undocumented Codex data formats. It validates the detected structure, creates a complete backup before applying changes, and aborts when the local configuration is not compatible with the expected format.
- Dry-run by default: reports planned changes without writing anything.
- Full backup of
%USERPROFILE%\.codexbefore every apply operation. - Verifies that Codex is completely closed before making changes.
- Case-insensitive Windows path comparison.
- Supports regular paths,
\\?\paths, UNC paths, and extended UNC paths. - Migrates project paths and paths below the project directory.
- Validates SQLite, JSON state files, and rollout files before applying.
- Uses atomic writes for JSON and JSONL files.
- Uses a SQLite transaction and validates the result with
PRAGMA quick_check. - Detects concurrent file changes with SHA-256 hashes.
- Automatically rolls back after a write failure, verification failure, or
Ctrl+Cduring apply. - Processes rollout files line by line to limit memory usage and preserve their original line endings.
- Uses only the Python standard library.
- Windows.
- Python 3.10 or later.
- A local Codex installation using
%USERPROFILE%\.codex. - The destination project directory must already exist before using
--apply.
The tool currently expects the following Codex structure:
state_5.sqlite, containing tablethreadswith columnsid,rollout_path,cwd, andsandbox_policy..codex-global-state.json, containingelectron-saved-workspace-roots,active-workspace-roots, andproject-order.cap_sid, containing valid JSON with aworkspace_by_cwdobject.- JSONL rollout files referenced by
threads.rollout_path.
If a Codex update changes this structure, the tool stops before applying any changes.
Clone the repository or download migrate_codex_project_path.py. No package
installation or third-party dependencies are required.
git clone <repository-url>
cd codex-project-path-migrator
python .\migrate_codex_project_path.py --version
python .\migrate_codex_project_path.py --helppython migrate_codex_project_path.py --old "PREVIOUS_PATH" --new "NEW_PATH" [--apply]
Rename or move the directory with File Explorer, PowerShell, Git, or another file-management tool. This script does not rename, move, or create the project directory itself.
Example:
old = C:\Users\Alice\Documents\Projects\monthly-invoices CODEX
new = C:\Users\Alice\Documents\Projects\monthly-invoices
It is normal for the previous path to no longer exist after the rename. The tool reports this as a warning but can continue.
Codex may remain open during a dry-run because no files are modified:
python .\migrate_codex_project_path.py `
--old "C:\Users\Alice\Documents\Projects\monthly-invoices CODEX" `
--new "C:\Users\Alice\Documents\Projects\monthly-invoices"The summary reports:
- Matches in
threads.cwdandthreads.sandbox_policy. - Affected rollout files and structured path changes.
- Changes in
.codex-global-state.jsonandcap_sid. - Compatibility errors and warnings.
- The exact changes that would be applied.
A dry-run does not create a backup because it does not modify anything.
Close Codex completely and run the same command with --apply:
python .\migrate_codex_project_path.py `
--old "C:\Users\Alice\Documents\Projects\monthly-invoices CODEX" `
--new "C:\Users\Alice\Documents\Projects\monthly-invoices" `
--applyThe apply operation aborts if it detects processes such as codex,
codex-code-mode-host, or codex-command-runner.
With --apply, a missing destination directory is an error. During a dry-run,
it is only a warning so the remaining configuration can still be inspected.
The following fields are updated in
%USERPROFILE%\.codex\state_5.sqlite:
threads.cwd.- Structured paths inside the JSON stored in
threads.sandbox_policy.
Each UPDATE also compares the previous value to detect database changes that
occurred after inspection.
The tool inspects files referenced by threads.rollout_path. It only modifies
structured fields in session_meta and turn_context events under:
cwd.workspace_roots.sandbox_policy.permission_profile.file_system_sandbox_policy.
Every other event is preserved byte for byte. Path references inside messages, commands, responses, or historical content are left unchanged and reported as warnings when relevant.
Structured paths are updated in
%USERPROFILE%\.codex\.codex-global-state.json. The prompt-history key is
explicitly excluded to avoid rewriting prompt history.
Required path keys and values are updated, including workspace_by_cwd. If the
destination path already exists with a different SID, the existing destination
entry is kept and the previous-path entry is removed.
- Codex logs.
- Historical messages and responses.
- Commands or outputs stored in rollouts.
- Prompt history in the global state file.
- The project directory or any project files.
Before writing anything, the complete %USERPROFILE%\.codex directory is
copied to:
%USERPROFILE%\.codex_backups\codex-backup-YYYYMMDD-HHMMSS
The exact path is printed in the final summary. Backups are retained after both successful migrations and automatic rollbacks.
If --apply fails, the tool attempts to restore every file it may have changed
and reports one of the following outcomes:
- Changes applied and verified.
- Changes restored from the backup.
- Incomplete rollback, including the files that could not be restored.
For manual recovery, close Codex, preserve a copy of the current state, and
replace %USERPROFILE%\.codex with the selected backup. Do not mix files from
different backups, especially state_5.sqlite, state_5.sqlite-wal, and
state_5.sqlite-shm.
Warning
Codex backups may contain conversations, local paths, and other private data. Never commit them to a repository or publish them.
No changes are applied when any of the following conditions is detected:
- The operating system is not Windows.
- Codex is still running or its process state cannot be determined.
--oldor--newis not an absolute Windows path.- The destination does not exist or is not a directory during
--apply. - A required file, table, column, or JSON key is missing.
- A sandbox policy is not a valid JSON object.
- An affected thread has no rollout file.
- A rollout contains unrecognized structured metadata with previous-path references.
- A JSON key would collide with an incompatible value.
- A source file changes between inspection and writing.
- Post-apply verification does not match the migration plan.
Validation failures return a non-zero exit code.
test_migrate_codex_project_path.py is the development test suite for the
migrator. It is not required to run migrate_codex_project_path.py, but it can
be used to verify the project after changes or before publishing a release.
The tests use temporary Codex profiles and never access or modify the user's real Codex configuration.
GitHub Actions runs the same suite on windows-latest with Python 3.10, 3.11,
3.12, 3.13, and 3.14 for every push to main and every pull request.
Run all tests from the repository root with automatic unittest discovery:
python -m unittest -vThis works because Python discovers files whose names start with test_. The
equivalent explicit discovery command is:
python -m unittest discover -s . -p "test_*.py" -vThe test file can also be executed directly:
python .\test_migrate_codex_project_path.py -vTo run one test class or one individual test:
python -m unittest -v test_migrate_codex_project_path.PathHandlingTests
python -m unittest -v `
test_migrate_codex_project_path.EndToEndTests.test_complete_apply_and_second_dry_run_are_consistentCoverage includes:
- Local paths, drive roots, extended UNC paths, and
..normalization. - Case-insensitive comparison.
- Path collisions and deduplication.
- Nullable SQLite values.
- Explicit rejection of unsupported operating systems.
- Missing or incompatible rollout files.
- CRLF and historical-content preservation.
- Selective file writes.
- Rollback after
KeyboardInterrupt. - Complete migration and second-run idempotency.
.
|-- .github
| |-- ISSUE_TEMPLATE
| | |-- bug_report.yml
| | `-- config.yml
| `-- workflows
| `-- tests.yml
|-- migrate_codex_project_path.py
|-- test_migrate_codex_project_path.py
|-- .gitignore
|-- LICENSE
`-- README.md
- Version 0.1.0 supports Windows only. macOS support requires a separate POSIX path and process-detection implementation and is not currently provided.
- The tool operates on the current user's
%USERPROFILE%\.codexdirectory. It does not currently accept an alternative Codex home path. - It does not rename, move, or create the project directory.
- It does not migrate free-form historical text references.
- Compatibility depends on the internal structure used by the installed Codex version.
- Migration between drives, UNC paths, and local paths is supported when the destination exists and every structural validation succeeds.
This project is licensed under the MIT License. See LICENSE.