Lifecycle stable ownership-aware

Clean reinstall of AgentKit

Ownership-aware kit uninstall → (optional) state reset → install stable CLI → login + kit init. Never wipe ~/.codex or ~/.claude.

Command boundaries

ak uninstall ≠ remove a global kit

Mixing these up is a common reason “remove AgentKit” fails or targets the wrong scope.

ak uninstall

Removes an AgentKit-managed project (ak new / project bootstrap). Requires an AK project at or above the current directory. Not the command for removing a globally installed kit.

  • Needs an AK project
  • Preview by default
  • Does not replace kit uninstall

ak kit uninstall <kit>

Removes kit-owned (AgentKit-owned) content for the scope/mode you select. Use this to remove engineer/marketing (global, project, native, plugin).

  • Per kit
  • Per scope/mode
  • Needs ownership records

Uninstall is preview-first

A run without --yes may finish with kit uninstall dry-run complete; re-run with --yes to execute . That is expected — nothing was removed; it is not an uninstall failure.

--force is not delete-all

ak kit uninstall has no --force flag. On ak update / ak kit init / project ak uninstall, --force only authorizes controlled collision/overwrite — not a clean-reset or delete-all, and not a way to skip recovery snapshots.

Separate layers

Uninstall kits · reset state · replace CLI · reinstall kits

Four different jobs. Correct order: uninstall kits (while ownership exists) → (optional) move AgentKit state → install stable CLI → login + kit init.

1. Uninstall kits

ak kit uninstall … for scopes you actually used

2. Reset AK state

logout + mv ~/.agentkit (after kit uninstall)

3. Replace CLI

self-update or install.sh on stable

4. Reinstall kits

login + kit init --channel stable

Binary and kit channels are separate. Use --channel stable explicitly when you want the stable path.

Clean reinstall

Clean reinstall of AgentKit stable

Recommended macOS/Linux flow. Keep ownership until kits are removed; prefer move/quarantine over delete; keep old state until audit/doctor pass.

  1. 1

    Stop active writers

    Close Codex, Claude Code, and any running AgentKit lifecycle command before touching temp files or uninstalling kits.

  2. 2

    Confirm ak CLI + stable channel

    type -a ak, ak --version, ak self-update --check --channel stable. Upgrade the CLI if needed — but do not delete ~/.agentkit yet.

  3. 3

    Work around ..* filename (2.7.0)

    If you hit the snapshot outside-scope error: close Codex, list then move (do not delete) matching temp files into quarantine.

  4. 4

    Audit + uninstall owned kits

    Only the scopes/modes you actually installed: global native, user plugin, project native, project plugin. Preview (--dry-run), then --yes.

  5. 5

    Verify uninstall evidence

    ak audit --json and ak backups list --json. Retained recovery snapshots are expected — keep them until reinstall verification passes.

  6. 6

    Reset AgentKit state (optional)

    Only after ownership-aware kit uninstall: ak logout, then mv ~/.agentkit to a recovery name — do not delete it yet.

  7. 7

    Install stable CLI

    Stable installer, hash -r, type -a ak, ak --version, ak doctor --json. Resolve duplicate binaries on PATH.

  8. 8

    Login + reinstall kits

    ak login, ak licenses, ak kit init … --channel stable --yes, then audit/doctor before restarting Codex.

01

Phase 1: stop active processes

Close Codex, Claude Code, and any running AgentKit lifecycle command before touching temp files under ~/.codex or running uninstall. Do not overlap lifecycle commands or kill an active mutation mid-flight.

02

Phase 2: installed CLI and stable channel

shell
type -a ak
ak --version
ak self-update --check --channel stable

# Upgrade CLI (do not delete ~/.agentkit — ownership is still needed for uninstall)
ak self-update --channel stable --yes

# Or reinstall the binary from the stable installer
# curl -fsSL https://agentkit.best/install.sh | AK_CHANNEL=stable sh
# hash -r
# ak --version

03

Phase 3: workaround for the 2.7.0 double-dot filename bug

Only if you see backups: walk produced path outside scope (or list finds matching files). Move, do not delete.

First list files matching the narrow pattern (maxdepth 1, regular files only):

shell
find "$HOME/.codex" -maxdepth 1 -type f \
  -name '..codex-global-state.json.bak.tmp-*' -print

After Codex is closed, move matching files to a recoverable quarantine outside the ~/.codex tree (still under ~/.agentkit for easy discovery):

shell
quarantine="$HOME/.agentkit/manual-quarantine/codex-temp-$(date +%Y%m%d-%H%M%S)"
mkdir -p "$quarantine"

find "$HOME/.codex" -maxdepth 1 -type f \
  -name '..codex-global-state.json.bak.tmp-*' \
  -exec mv -n {} "$quarantine"/ \;
Move; do not delete.
Match only ..codex-global-state.json.bak.tmp-*
Do not move config.toml, skills, hooks, credentials, session state, or unrelated dotfiles.
Keep the quarantine until reinstall verification succeeds.
If the file reappears while Codex is closed, or is not a regular file — stop and escalate; do not broaden cleanup.
Do not bypass AgentKit backup creation; do not use --no-backup as a workaround.

After quarantine, rerun dry-run then confirmed uninstall (correct scope — see Phase 4).

04

Phase 4: audit and uninstall owned kits

Run only modes you actually installed. Review each dry-run before --yes. Repeat for each kit (engineer, marketing, …).

Global native

shell
# Global native (example: Engineer Kit)
ak audit --json

ak kit uninstall engineer --global --dry-run
ak kit uninstall engineer --global --yes

# Repeat for other installed kits (e.g. marketing) — same scope
# ak kit uninstall marketing --global --dry-run
# ak kit uninstall marketing --global --yes

Claude Code user plugin

shell
# Claude Code user plugin
ak kit uninstall engineer --global --plugin-mode --dry-run
ak kit uninstall engineer --global --plugin-mode --yes

Native project

shell
# Native project — use an absolute path
ak kit uninstall engineer \
  --project-dir /absolute/path/to/project \
  --dry-run

ak kit uninstall engineer \
  --project-dir /absolute/path/to/project \
  --yes

Project plugin

shell
# Project plugin
ak kit uninstall engineer \
  --plugin-mode \
  --project-dir /absolute/path/to/project \
  --dry-run

ak kit uninstall engineer \
  --plugin-mode \
  --project-dir /absolute/path/to/project \
  --yes

05

Phase 5: verify uninstall evidence

shell
ak audit --json
ak backups list --json

Retained recovery snapshots are expected evidence — do not delete them until the lifecycle result and reinstall are verified. Only describe uninstall as completed when the confirmed (--yes) command succeeded.

06

Phase 6: intentionally reset AgentKit internal state

Only if you truly want a clean AgentKit state. After ownership-aware kit uninstall has completed.

shell
# Only after ownership-aware kit uninstall has finished
ak logout

stamp=$(date +%Y%m%d-%H%M%S)
mv "$HOME/.agentkit" "$HOME/.agentkit.pre-stable-$stamp"

# Keep the renamed directory until stable install + audit/doctor pass
# Do not delete yet — it holds backups, quarantine, registry, and auth state
  • Resets AgentKit state while retaining a recovery copy (mv, not rm).
  • Also moves backups and the temporary-file quarantine from Phase 3 (under ~/.agentkit).
  • Do not delete the renamed directory until the new stable installation and kit audit pass.

07

Phase 7: install stable

shell
curl -fsSL https://agentkit.best/install.sh | AK_CHANNEL=stable sh
hash -r

type -a ak
ak --version
ak doctor --json

# If type -a ak shows multiple binaries: fix PATH before continuing

08

Phase 8: authenticate and reinstall the kit

shell
ak login
ak licenses

# Example: Engineer Kit on global Codex, stable channel
ak kit init engineer \
  --target codex \
  --global \
  --channel stable \
  --yes

ak audit engineer --strict --json
ak doctor --adapter codex --json

# Restart Codex only after the checks above complete

Keep the quarantine and ~/.agentkit.pre-stable-* until ak audit / ak doctor pass. Only then consider removing recovery copies.

Windows

Windows (PowerShell) — safety invariants

Do not mechanically translate Unix commands into recursive deletes of entire runtime homes. Keep ownership-aware kit uninstall before any state reset.

Inspect every ak.exe resolution (Get-Command ak -All) before replacement.
Remove or replace only the verified AgentKit executable — do not remove a PATH directory that may hold other programs.
Do not delete %USERPROFILE%\.codex or %USERPROFILE%\.claude.
Quarantine state (Move-Item) instead of broad deletion.
Ownership-aware ak kit uninstall before moving %USERPROFILE%\.agentkit.

Quarantine ..* temp files (Phase 3 equivalent)

powershell
# PowerShell — close Codex first. Only temp files matching the narrow pattern.
$codex = Join-Path $env:USERPROFILE '.codex'
$stamp = Get-Date -Format 'yyyyMMdd-HHmmss'
$quarantine = Join-Path $env:USERPROFILE ".agentkit\manual-quarantine\codex-temp-$stamp"
New-Item -ItemType Directory -Force -Path $quarantine | Out-Null

Get-ChildItem -LiteralPath $codex -File -Force |
  Where-Object { $_.Name -like '..codex-global-state.json.bak.tmp-*' } |
  ForEach-Object {
    Move-Item -LiteralPath $_.FullName -Destination $quarantine -ErrorAction Stop
  }

Get-ChildItem -LiteralPath $quarantine -Force

Move AgentKit state (Phase 6 equivalent)

powershell
# PowerShell — only after ownership-aware kit uninstall
ak logout
$stamp = Get-Date -Format 'yyyyMMdd-HHmmss'
$homeAk = Join-Path $env:USERPROFILE '.agentkit'
$dest = Join-Path $env:USERPROFILE ".agentkit.pre-stable-$stamp"
Move-Item -LiteralPath $homeAk -Destination $dest

Reinstall CLI (Windows installer)

powershell
# PowerShell
irm https://agentkit.best/install.ps1 | iex
# Open a new terminal, then:
Get-Command ak -All
ak --version
ak doctor --json

ak kit uninstall / audit / kit init flags match Unix. Prefer absolute project paths for --project-dir. Use %USERPROFILE% when referring to home paths.

Related guides