Skip to main content

Repair local Codex sessions after moving a project directory

Project description

codex-move-session

codex-move-session repairs local Codex sessions after a project directory is renamed or moved. It supports macOS, Linux, and Windows, discovers both current and legacy Codex session databases, and repairs absolute paths in session history and generated memories.

[!WARNING] This is an unofficial tool that modifies undocumented Codex data formats. Inspect the dry-run carefully, close every Codex process before applying, and retain the generated backup.

Install

Run without installing:

uvx codex-move-session

Install as a persistent uv tool:

uv tool install codex-move-session
codex-move-session --version

Before the first PyPI release, run directly from GitHub:

uvx --from git+https://github.com/zanderzhng/codex-move-session codex-move-session

Python 3.10 or newer is required.

Usage

Running without --old and --new opens the interactive workflow. It finds session working directories that no longer exist, lets you filter active or archived sessions, prompts for the new directory, displays every planned data store change, and asks for confirmation.

codex-move-session

For scripts, provide both paths. This is a dry-run and does not write anything:

codex-move-session --old /previous/project --new /current/project

Close Codex, review the dry-run, then apply the same migration:

codex-move-session --old /previous/project --new /current/project --apply

Include archived sessions or select another Codex profile:

codex-move-session \
  --old /previous/project \
  --new /current/project \
  --include-archived \
  --codex-home ~/.codex-work

CODEX_HOME is respected when --codex-home is not given.

What Changes

The migration is driven by sessions whose cwd equals the old directory or is below it. It can update:

  • Every matching threads.cwd and structured sandbox-policy path across compatible databases in CODEX_HOME/sqlite/ and legacy state_5.sqlite.
  • All exact old-root references in JSON string values inside affected rollout JSONL files, including metadata, messages, commands, tool calls, and tool output.
  • raw_memory and rollout_summary for affected thread IDs in Codex memory databases.
  • Known workspace roots and thread hints in .codex-global-state.json and cap_sid.

It does not move project files. The destination must already exist before apply. Prompt history, logs, caches, and previous backups are not rewritten.

Windows paths use case-insensitive matching and support drive, UNC, extended, and mixed-separator forms. macOS and Linux matching is case-sensitive. Similar names such as /project-copy are not treated as descendants of /project.

Safety

Dry-run is always the default. Apply mode:

  1. Refuses to run while a Codex desktop, CLI, or app-server process is detected.
  2. Verifies that files and database values did not change after planning.
  3. Creates a timestamped touched-data backup under CODEX_HOME/backups/.
  4. Uses SQLite transactions and atomic file replacement.
  5. Runs post-write database and content verification.
  6. Restores every touched store if writing or verification fails.

Each backup contains manifest.json, standalone SQLite snapshots, and the original content of every changed file. Backups can contain private conversations and local paths; do not publish them.

Development

uv sync --all-groups
uv run ruff check .
uv run pytest
uv build

Tests construct temporary Codex profiles and never modify the real profile.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

codex_move_session-0.1.0.tar.gz (13.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

codex_move_session-0.1.0-py3-none-any.whl (17.2 kB view details)

Uploaded Python 3

File details

Details for the file codex_move_session-0.1.0.tar.gz.

File metadata

  • Download URL: codex_move_session-0.1.0.tar.gz
  • Upload date:
  • Size: 13.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for codex_move_session-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a2f2159750200ec2f59bf5c7b465fa43fee142e8301bd0dd045404fcdcde176c
MD5 8ad8d78e0080e8f92e7418e93743cc5f
BLAKE2b-256 7d8bc0d022211fb97ed0b94c2bafd77520dea33db5fa3b3813951d6ed5e20c65

See more details on using hashes here.

File details

Details for the file codex_move_session-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: codex_move_session-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 17.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for codex_move_session-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 294b8a9f43c82e19a6bcc4f54295faabf09e1ba63071dc45627188746cc71c4d
MD5 1e91f6ff6f4afb20c0b1416ff1419426
BLAKE2b-256 f365182eb2f7d99c0f0280a50a4eae0856315213f52906df0c8562c84d6d9332

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page