Skip to content

chore: back up Codex sessions before WSL migration #3748

Open

Description

@risu729

Goal

Create a cold, ordinary-file backup of the current Codex sessions on the Windows drive before removing the old WSL instance. Keep it offline as a temporary safety copy; do not import it into the new Codex home by default.

Do not back up credentials, caches, plugins, diagnostic logs, or the complete ~/.codex directory.

Current size

Measured on 2026-07-16:

  • ~/.codex/sessions: 1,121,811,644 bytes, 1,101 files (about 1.1 GB)
  • ~/.codex/config.toml: 10,282 bytes
  • ~/.codex/rules: 1,369 bytes
  • Windows C: free space: about 190 GB

Expect the finished backup to use approximately 1.1 GB. Allow roughly 1.2 GB because active sessions may grow before this is run and filesystem-reported sizes can differ slightly.

Preconditions

Finish all ongoing Codex work, then close every Codex CLI, app, and agent process. Run the backup from a normal WSL shell, not from an active Codex session.

Confirm nothing remains:

pgrep -af '[c]odex'

Expected result: no output. If processes are listed, close them before continuing so transcripts are no longer being appended.

Copy

backup="/mnt/c/Users/risu/wsl-backup/codex-$(date +%F)"

mkdir -p "$backup"

rsync -rt --info=progress2 \
  "$HOME/.codex/sessions" \
  "$HOME/.codex/config.toml" \
  "$HOME/.codex/rules" \
  "$backup/"

Command explanation:

  • backup=...: selects a dated folder on the Windows filesystem.
  • mkdir -p: creates the destination and any missing parent directories.
  • rsync -r: copies directories recursively.
  • rsync -t: preserves modification timestamps.
  • --info=progress2: shows progress for the complete copy.
  • -a is intentionally not used because Unix ownership and permission metadata are unnecessary for this cold copy on NTFS.

The destination should contain:

codex-YYYY-MM-DD/
├── config.toml
├── rules/
└── sessions/

config.toml and rules/ are references for rebuilding stable preferences. They should not be restored wholesale if the goal is a clean Codex setup, because they contain old project trust and command-approval state.

Verify

rsync -rctn --delete --itemize-changes \
  "$HOME/.codex/sessions/" \
  "$backup/sessions/"

cmp "$HOME/.codex/config.toml" "$backup/config.toml"
diff -qr "$HOME/.codex/rules" "$backup/rules"
du -sh "$backup"

Verification explanation:

  • -c compares file contents using checksums instead of relying only on size and timestamps.
  • -n makes the command a dry run; it cannot modify the backup.
  • --delete is also dry-run-only here and reports unexpected destination files.
  • --itemize-changes prints every difference found.
  • cmp checks that config.toml is byte-for-byte identical.
  • diff -qr recursively compares the rules directory.

Expected result:

  • The first three commands produce no output.
  • du -sh reports around 1.1 GB, allowing for session growth before the backup is performed.

New WSL behavior

After restoring dotfiles and tools:

mise bootstrap
codex login

Start Codex with fresh local state. Do not copy sessions/, state_5.sqlite*, history.jsonl, goals, logs, authentication files, or caches into the new ~/.codex unless an old conversation is later found to be necessary.

Keep the Windows backup temporarily. Delete it only after the new WSL environment is working and there is confidence that no old session needs to be resumed.

Security

Session transcripts can contain private prompts, source code, command output, local paths, and accidentally printed secrets. Keep the backup private and do not commit or upload it.

Completion checklist

  • Finish and close all Codex processes
  • Copy sessions, configuration reference, and rules reference
  • Run checksum verification with no differences
  • Confirm backup size is approximately 1.1–1.2 GB
  • Bootstrap and log into Codex on the new WSL without importing old state
  • Delete the cold backup later when it is no longer needed

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions