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, --new, or --delete opens the interactive workflow. It finds session working directories that no longer exist, lets you filter active or archived sessions, select a session, and choose whether to move or delete it. The selected action displays every planned data store change and asks for confirmation before applying it.

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

Delete one local session by ID. Deletion is also a dry-run by default:

codex-move-session --delete SESSION_ID

After reviewing the deletion plan, apply it explicitly:

codex-move-session --delete SESSION_ID --apply

Delete every session whose working directory is a project or one of its descendants:

codex-move-session --delete-project /previous/project
codex-move-session --delete-project /previous/project --apply

Limit deletion to one stored copy when an ID exists in both active and archived storage:

codex-move-session --delete SESSION_ID --delete-scope archived

The remaining copy is preserved, and its database row is redirected to the surviving rollout. Project-wide apply creates and verifies a separate backup for each session and stops at the first failure.

Deletion removes the local session and related database rows, related memory, and its rollout file after creating a backup. It never deletes project files.

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.

Inspect inconsistencies between rollout files, databases, and session_index.jsonl:

codex-move-session --doctor
codex-move-session --doctor --repair
codex-move-session --doctor --repair --apply

Doctor reports orphaned or missing rollout files and duplicate copies. Safe repairs redirect stale threads.rollout_path values, align archived state, recover blank titles, and create or supplement session_index.jsonl. It does not synthesize an entire database row for an orphaned rollout.

To create a missing destination as part of an applied migration:

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

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.
  • Desktop sidebar project ordering, collapsed workspace groups, and workspace labels.

It does not move project files. The destination must already exist before apply unless --create-new is provided. 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.

Session discovery combines compatible SQLite databases with active and archived rollout files. This exposes rollout-only sessions and recovers missing titles from session_index.jsonl, rollout content, or history.jsonl.

Session deletion uses the same safeguards. --delete and --delete-project are dry-runs unless --apply is present, and apply refuses to proceed while Codex is running or if the planned database rows or files changed after the preview. It also rechecks the database set and refuses to delete a rollout shared by another session. Before deletion, it backs up the affected databases, rollout file, and other changed Codex state. It also removes the session index entry, thread pins and sidebar ordering when no stored copy remains. After writing, it verifies database integrity, confirms the planned rows and rollout file are gone, and checks the remaining file updates. If deletion or verification fails, open transactions, captured original file content, and scoped original-row restoration automatically roll back the touched session data. The retained backup remains available for audit or recovery, and the tool reports if any automatic rollback step could not be completed.

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.3.0.tar.gz (33.8 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.3.0-py3-none-any.whl (40.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: codex_move_session-0.3.0.tar.gz
  • Upload date:
  • Size: 33.8 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.3.0.tar.gz
Algorithm Hash digest
SHA256 c6d27af2dab10f64287200e2109c77dd43a9128a349351e35d851f69d1095859
MD5 6105271580d940979aee88edb72314af
BLAKE2b-256 76a103d5e655f7cf7ba044d336bf5efdcb7116152662f3032e297d82c62a32ac

See more details on using hashes here.

File details

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

File metadata

  • Download URL: codex_move_session-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 40.6 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.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 371dcceb720b60ac8fb8c1f3deb8d4f78fe9b466535d2923a1ace335a6ae7228
MD5 6330368f45a3e3cf88625efa0b82431d
BLAKE2b-256 389fc1a0e21712bc120d79c12eb8ff60031f1878235ef8c7810f39c0632e0abb

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