# Repair saved Codex chats

Canonical: https://hypaware.ai/docs/cli-reference/repair-saved-codex-chats

Provided by `@hypaware/codex`. Codex 0.166.0 and later report
`modelProviderMismatch` for chats saved while HypAware's gateway capture was
on. The daemon repairs those chats once on its own; this command previews,
applies or undoes the repair by hand. See
[reopen chats saved with gateway capture](https://hypaware.ai/docs/integrations/codex/index.md#reopen-chats-saved-with-gateway-capture).

```text
hyp codex repair [--dry-run] [--json] [--codex-bin <path>]
hyp codex repair --restore <backup-path> [--json] [--codex-bin <path>]
```

`--dry-run` counts the chats a repair would change and changes nothing.
Without it, close Codex Desktop, the ChatGPT app and every Codex CLI session
first; the command refuses while any of them is running. It copies each
affected chat file and Codex's state database into a new backup directory,
changes the saved provider name from `hypaware` to `openai`, and prints the
backup path. It refuses custom routes and profiles. A saved chat whose file was
deleted is left unchanged, and the command says how many. When nothing needs
repair it makes no backup. If an earlier repair was interrupted, it refuses and
prints the `--restore` command for that backup.

`--restore <backup-path>`, with Codex closed the same way, puts back the chat
files and provider names saved in that backup. It refuses a backup from another
Codex home and a chat changed since the repair, so new messages are kept. It
cannot be combined with `--dry-run`. `--codex-bin` names the Codex executable
that reads your configuration; on macOS the default is the one bundled with the
ChatGPT or Codex app in `/Applications`, otherwise `codex` on `PATH`. `--json`
prints the result as one JSON object.

Each backup is a full copy of the affected chats and of Codex's state database,
under `$CODEX_HOME/hypaware-provider-repair` (normally
`~/.codex/hypaware-provider-repair`). A repair that stops before it starts
applying changes removes its backup. From the moment it starts applying them,
the backup stays, even if the repair then fails or is rolled back. HypAware
removes no backup after that: not on a later repair, a restore, `hyp privacy
purge`, detach or daemon uninstall. It stays until you delete it.

```sh
hyp codex repair --dry-run
hyp codex repair
hyp codex repair --restore ~/.codex/hypaware-provider-repair/backup-XXXXXX
```

Returns `0` on success, `1` when the repair or restore fails or is refused, and
`2` for a usage error.

