360 Secure SkillHub
360 安全技能中心

Codex Session Image Scrubber

核心功能是清理臃肿的Codex会话日志,将嵌入的大图片/Base64 payload替换为占位符,完整保留对话、工具调用及文本结构。适用于会话因历史截图、图片导致加载缓慢、体积过大的场景。输入支持线程ID或指定JSONL文件,经确认、模拟运行、写入、验证步骤,输出清理后的会话文件及备份,同时返回前后体积变化、验证结果,确保文件可正常解析使用。

vyctorbrzezowski
vyctorbrzezowski
热度 24.33
最近更新 2026-06-06 01:14:12
分类:效率依赖:代码执行 / 读写文件应用场景:数据处理 / 自动化脚本 / 工作流

安装技能

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

执行命令安装此 skill: npx secure-skills-cli add codex-session-image-scrubber
Metadata
name
codex-session-image-scrubber
description
Use when a Codex thread or local session is slow because prior turns contain heavy image, screenshot, or base64 payloads. Helps locate the session JSONL, back it up, remove only embedded image blobs, preserve conversation text, and validate the cleaned file.

Codex Session Image Scrubber

Purpose

Clean oversized Codex session logs by replacing embedded image/base64 payloads with small placeholders while keeping the surrounding conversation, tool calls, and text intact.

Use this when the user says a Codex chat/thread is heavy, slow, bloated, or contains pasted screenshots/images/base64 they want removed from history.

Workflow

  1. Confirm the target thread/session.

    • Prefer a thread id if the user provides one.
    • If they provide a remembered phrase, locate the session with rg -l "<phrase>" ~/.codex/sessions ~/.codex/session_index.jsonl.
    • Do not edit the active file until you know which JSONL is the target.
  2. Dry-run the scrubber.

    node ~/.codex/skills/codex-session-image-scrubber/scripts/scrub-codex-session-images.mjs --thread-id <thread-id>
    

    Or, with an exact file:

    node ~/.codex/skills/codex-session-image-scrubber/scripts/scrub-codex-session-images.mjs --file /path/to/rollout.jsonl
    
  3. If the dry-run looks right, write the cleaned file.

    node ~/.codex/skills/codex-session-image-scrubber/scripts/scrub-codex-session-images.mjs --thread-id <thread-id> --write
    
  4. Validate after writing.

    • Confirm size dropped with ls -lh <file> <backup>.
    • Confirm the JSONL still parses; the script reports parseErrors: 0.
    • Check obvious image payloads are gone:
      rg -n "data:image|iVBORw0KGgo|/9j/4AAQ|UklGR" <file>
      
      Exit code 1 with no output is the desired result.
  5. Tell the user the before/after size, backup path, and whether validation passed. Suggest reopening the thread so the app reloads the lighter file.

Safety Rules

  • Only remove image payloads, not text that mentions images.
  • Keep <image> or </image> text markers if present; they are small and can preserve conversation structure.
  • Always keep a backup outside ~/.codex/sessions; the script defaults to ~/.codex/session_backups.
  • If multiple session files match a thread id, stop and pick explicitly instead of guessing.
  • If the user wants the backup removed later, ask for confirmation before deleting it.

Script

The deterministic scrubber is at scripts/scrub-codex-session-images.mjs.

Useful options:

  • --thread-id <id>: find a rollout JSONL under ~/.codex/sessions.
  • --file <path>: scrub a specific JSONL.
  • --write: perform the rewrite; without this the script is dry-run only.
  • --backup-dir <path>: override the backup directory.
  • --sessions-dir <path>: override the Codex sessions root.
  • --min-bytes <n>: threshold for suspicious image fields; defaults to 100000.