Codex Session Cleanup
Use this explicit-only skill for Codex artifact hygiene from any directory.
Default to a read-only scan that produces a JSON manifest and Markdown report.
Quarantine is reversible cleanup; purge is irreversible cleanup.
Safety Contract
- Never delete directly. Quarantine first, purge later.
- Never mutate during
scan.
- Never clean all sessions unless the user explicitly asks for all sessions.
- Never move, ignore, rewrite, or delete active memory by default. Copy memory
summaries and the memory registry into quarantine when cleanup runs.
- Never inspect or mutate
auth.json, internal_storage/**, or secret-like
env files unless the user explicitly requests a separate security-reviewed
workflow.
- Stop on SQLite integrity failures, JSONL parse errors, checksum mismatch,
ambiguous thread IDs, active/recent session risk, active jobs/goals, child
spawn risk, stale manifests, or missing backups.
First-Pass Workflow
- Load only the references needed:
references/artifact-model.md for Codex file and DB layout.
references/classifier-rules.md for confidence, scope, and memory triage.
references/safety-restore.md before apply, restore, or purge.
references/report-template.md when interpreting output.
- Run a scan first. From a repo, this scans the current Git root and audits
linked memory without mutating anything:
python3 "$skill_dir/scripts/codex_session_cleanup.py" scan
- Review the report sections for scope roots, selected threads, medium
candidates, protected exclusions, memory triage, artifact families, and
automation eligibility.
- Use existing read-only subagents only when the report is ambiguous or broad:
repo_explorer for scope sanity, false_positive_validator for candidate
risk, and history_reviewer for durable-memory review.
- Apply only with the exact manifest id and
--execute; keep memory copy-first:
python3 "$skill_dir/scripts/codex_session_cleanup.py" apply \
--manifest /path/to/manifest.json \
--confirm <manifest-id> \
--memory-policy copy \
--execute
- Rerun
scan after cleanup and report counts, quarantine path, DB integrity,
checksum status, history/index rows removed, session files quarantined,
memory files copied/moved, automation blockers, and remaining risk.
Scopes
- Current repo or directory:
scan
- Explicit root:
scan --scope root --root /path/to/repo
- Multiple roots:
scan --scope roots --root /repo/a --root /repo/b
- Roots file:
scan --scope roots --roots-file /path/to/roots.txt
- Repositories under cwd:
scan --scope cwd-subrepos --cwd /path/to/parent
- Codex-home artifacts only:
scan --scope codex-home
- All Codex sessions/artifacts:
scan --scope all
Nested repositories use longest-root-wins ownership unless
--include-parent-overlap is explicit.
Artifact Families
Default scan families are sessions plus memory. Add repeatable
--artifact-family values when needed:
sessions: session JSONL, history/index JSONL, state/log SQLite rows.
memory: memories/MEMORY.md and linked rollout summaries, copy-first.
quarantine: old quarantine bundles, purge remains manual.
logs: Codex logs and log directories, report-only by default.
cache: cache and temp directories, manual candidate only.
generated: generated images, manual candidate only.
skills-agents-config: skills, agents, AGENTS/config files, report-only.
Autonomous Apply Policy
Autonomous apply is allowed only for reversible quarantine of high-confidence
current-repo disposable session artifacts when scan evidence and read-only
validator consensus agree false-positive risk is low. Autonomous apply must use
--memory-policy copy; active memory files must not be moved, deleted, or
rewritten.
Manual review is required for medium-confidence candidates, broad all-session
sweeps, active/recent sessions, ambiguous IDs, parse or integrity issues,
durable linked memory, destructive memory mutation, and purge.
Memory Policy
Treat stale, outdated, or conflicting memory as a live-verification queue, not
as proof that the memory should be deleted. Preserve durable workflow knowledge
and mark drift-prone details in the report. Current repo code/docs and live
provider or GitHub state outrank historical memory when they conflict.
Destructive memory modes require an extra manifest-id confirmation:
python3 .../codex_session_cleanup.py apply ... \
--memory-policy move \
--confirm-memory-move <manifest-id> \
--execute
Implementation Notes
The script is the source of truth for deterministic scanning and mutation. Use
the references for policy and interpretation, not for hand-written cleanup
commands. Prefer adding classifier or artifact-family behavior to the script
over ad hoc shell filters.
Validate after changes:
python3 -m py_compile "$skill_dir/scripts/codex_session_cleanup.py"
python3 -m unittest discover -s "$skill_dir/tests"
python3 "<skill-creator-dir>/scripts/quick_validate.py" "$skill_dir"
node "<skill-auditor-dir>/scripts/audit-skills-baseline.mjs" "<skills-root>" /tmp/codex-session-cleanup-skill-audit
1---2name: codex-session-cleanup3description: Safely scan, triage, quarantine, restore, and purge Codex session/history/state/memory artifacts for current repo, explicit roots, subrepos, Codex-home, or all sessions.4---56# Codex Session Cleanup78Use this explicit-only skill for Codex artifact hygiene from any directory.9Default to a read-only scan that produces a JSON manifest and Markdown report.10Quarantine is reversible cleanup; purge is irreversible cleanup.1112## Safety Contract1314- Never delete directly. Quarantine first, purge later.15- Never mutate during `scan`.16- Never clean all sessions unless the user explicitly asks for all sessions.17- Never move, ignore, rewrite, or delete active memory by default. Copy memory18 summaries and the memory registry into quarantine when cleanup runs.19- Never inspect or mutate `auth.json`, `internal_storage/**`, or secret-like20 env files unless the user explicitly requests a separate security-reviewed21 workflow.22- Stop on SQLite integrity failures, JSONL parse errors, checksum mismatch,23 ambiguous thread IDs, active/recent session risk, active jobs/goals, child24 spawn risk, stale manifests, or missing backups.2526## First-Pass Workflow27281. Load only the references needed:29 - `references/artifact-model.md` for Codex file and DB layout.30 - `references/classifier-rules.md` for confidence, scope, and memory triage.31 - `references/safety-restore.md` before `apply`, `restore`, or `purge`.32 - `references/report-template.md` when interpreting output.332. Run a scan first. From a repo, this scans the current Git root and audits34 linked memory without mutating anything:3536```bash37python3 "$skill_dir/scripts/codex_session_cleanup.py" scan38```39403. Review the report sections for scope roots, selected threads, medium41 candidates, protected exclusions, memory triage, artifact families, and42 automation eligibility.434. Use existing read-only subagents only when the report is ambiguous or broad:44 `repo_explorer` for scope sanity, `false_positive_validator` for candidate45 risk, and `history_reviewer` for durable-memory review.465. Apply only with the exact manifest id and `--execute`; keep memory copy-first:4748```bash49python3 "$skill_dir/scripts/codex_session_cleanup.py" apply \50 --manifest /path/to/manifest.json \51 --confirm <manifest-id> \52 --memory-policy copy \53 --execute54```55566. Rerun `scan` after cleanup and report counts, quarantine path, DB integrity,57 checksum status, history/index rows removed, session files quarantined,58 memory files copied/moved, automation blockers, and remaining risk.5960## Scopes6162- Current repo or directory: `scan`63- Explicit root: `scan --scope root --root /path/to/repo`64- Multiple roots: `scan --scope roots --root /repo/a --root /repo/b`65- Roots file: `scan --scope roots --roots-file /path/to/roots.txt`66- Repositories under cwd: `scan --scope cwd-subrepos --cwd /path/to/parent`67- Codex-home artifacts only: `scan --scope codex-home`68- All Codex sessions/artifacts: `scan --scope all`6970Nested repositories use longest-root-wins ownership unless71`--include-parent-overlap` is explicit.7273## Artifact Families7475Default scan families are `sessions` plus `memory`. Add repeatable76`--artifact-family` values when needed:7778- `sessions`: session JSONL, history/index JSONL, state/log SQLite rows.79- `memory`: `memories/MEMORY.md` and linked rollout summaries, copy-first.80- `quarantine`: old quarantine bundles, purge remains manual.81- `logs`: Codex logs and log directories, report-only by default.82- `cache`: cache and temp directories, manual candidate only.83- `generated`: generated images, manual candidate only.84- `skills-agents-config`: skills, agents, AGENTS/config files, report-only.8586## Autonomous Apply Policy8788Autonomous apply is allowed only for reversible quarantine of high-confidence89current-repo disposable session artifacts when scan evidence and read-only90validator consensus agree false-positive risk is low. Autonomous apply must use91`--memory-policy copy`; active memory files must not be moved, deleted, or92rewritten.9394Manual review is required for medium-confidence candidates, broad all-session95sweeps, active/recent sessions, ambiguous IDs, parse or integrity issues,96durable linked memory, destructive memory mutation, and purge.9798## Memory Policy99100Treat stale, outdated, or conflicting memory as a live-verification queue, not101as proof that the memory should be deleted. Preserve durable workflow knowledge102and mark drift-prone details in the report. Current repo code/docs and live103provider or GitHub state outrank historical memory when they conflict.104105Destructive memory modes require an extra manifest-id confirmation:106107```bash108python3 .../codex_session_cleanup.py apply ... \109 --memory-policy move \110 --confirm-memory-move <manifest-id> \111 --execute112```113114## Implementation Notes115116The script is the source of truth for deterministic scanning and mutation. Use117the references for policy and interpretation, not for hand-written cleanup118commands. Prefer adding classifier or artifact-family behavior to the script119over ad hoc shell filters.120121Validate after changes:122123```bash124python3 -m py_compile "$skill_dir/scripts/codex_session_cleanup.py"125python3 -m unittest discover -s "$skill_dir/tests"126python3 "<skill-creator-dir>/scripts/quick_validate.py" "$skill_dir"127node "<skill-auditor-dir>/scripts/audit-skills-baseline.mjs" "<skills-root>" /tmp/codex-session-cleanup-skill-audit128```