360 Secure SkillHub
360 安全技能中心

Clean Codex Archives

核心功能是清理Windows、macOS、Linux上Codex的归档JSONL文件、SQLite库中归档会话行及关联日志、过期索引条目,严格保留活跃会话。典型场景为用户要求清除Codex归档会话或本地历史元数据。需先干运行查看待清理项,用户授权后加--apply执行,支持指定数据目录,可选压缩数据库;清理后自动验证结果,遇库锁定会提示处理后重试。

lunarcache
lunarcache
热度 7.65
最近更新 2026-07-23 17:33:01
分类:自动化依赖:代码执行 / 读写文件应用场景:自动化脚本 / 数据处理

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add clean-codex-archives
Metadata
name
clean-codex-archives
description
Safely inspect and remove locally archived Codex conversation data on Windows, macOS, and Linux, including archived rollout JSONL files, archived session rows and related logs in Codex SQLite databases, and stale session_index.jsonl entries. Use when the user asks to clear, purge, delete, or clean archived Codex conversations or their local history metadata.

Clean Codex Archives

Use the bundled scripts/clean_codex_archives.py script as the cross-platform entry point. It uses only Python's standard library and preserves active sessions.

Safety contract

  • Resolve the Codex data root from an explicit --codex-home argument, then the CODEX_HOME environment variable, then the current user's .codex directory.
  • Treat state_5.sqlite as the source of truth. Only rows with threads.archived = 1 are eligible for deletion.
  • Preserve all unarchived threads, their logs, and their session-index entries.
  • Run without --apply first. Use --apply only after the user explicitly authorizes deletion.
  • Delete associated logs and goals before deleting archived thread rows, because the archived IDs are needed to select related records safely.
  • Delete related thread_dynamic_tools and thread_spawn_edges rows when those tables are present.
  • Remove only archived_sessions/*.jsonl files. Do not delete the archive directory itself or unrelated files.
  • Rewrite session_index.jsonl only after database cleanup, retaining entries whose IDs still exist in state_5.sqlite and rejecting malformed JSON instead of silently dropping it.
  • If a database is locked, ask the user to close Codex or otherwise stop the process holding the database, then retry.

Workflow

  1. Run a dry run and inspect the counts for archive files, archived threads, related logs, goals, and stale index entries.
  2. If the user confirms deletion, rerun with --apply.
  3. Use --vacuum only when the user also wants SQLite files compacted; it may require exclusive database access and is not needed for logical deletion.
  4. Verify that archived-thread count is zero, archive-file count is zero, remaining index IDs all exist in the state database, and SQLite quick_check reports ok for modified databases.

Commands

# Inventory only; no changes. Use python3 on Unix-like systems.
python3 ./scripts/clean_codex_archives.py

# Apply the explicitly authorized cleanup.
python3 ./scripts/clean_codex_archives.py --apply

# Use a specific Codex data root.
python3 ./scripts/clean_codex_archives.py --codex-home "$HOME/.codex" --apply

# Optional physical compaction after deletion.
python3 ./scripts/clean_codex_archives.py --apply --vacuum

On Windows, use python instead of python3.