keep-codex-fast-maintenance

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Keep Codex Fast

保持Codex运行流畅

Skill by ara.so — Daily 2026 Skills collection.
A backup-first maintenance skill for local Codex state. When Codex starts feeling heavy after weeks of chats, terminals, logs, worktrees, and project history, this skill gives you a safe, inspectable workflow to reduce drag without losing context.
Core rule: Make handoffs first. Archive, don't delete. Apply changes only when you are ready.

ara.so开发的Skill — 属于2026每日技能合集。
一款针对本地Codex状态的备份优先型维护Skill。当Codex在数周的聊天、终端操作、日志、工作树和项目历史积累后变得运行迟缓时,这款Skill能为你提供一套安全、可核查的工作流,在不丢失上下文的前提下减少运行负担。
核心原则: 先完成交接。选择归档,而非删除。仅在你准备就绪后再执行变更。

Installation

安装

Ask Codex directly:
text
Install the keep-codex-fast skill from https://github.com/vibeforge1111/keep-codex-fast
Or clone manually into your Codex skills directory:
bash
git clone https://github.com/vibeforge1111/keep-codex-fast keep-codex-fast

直接向Codex发送指令:
text
Install the keep-codex-fast skill from https://github.com/vibeforge1111/keep-codex-fast
或手动克隆到你的Codex技能目录:
bash
git clone https://github.com/vibeforge1111/keep-codex-fast keep-codex-fast

Mental Model

心智模型

LayerPurpose
ChatsExecution context
Handoff docsMemory and continuity
ArchivesHistory, not deletion
Fresh threadsSpeed
Never delete. Always archive. The script moves state into archive folders and writes backup/restore artifacts before applying any change.

层级用途
聊天记录执行上下文
交接文档记忆与连续性
归档文件历史留存,而非删除
全新会话提升速度
绝不删除,始终归档。 脚本会在执行任何变更前,将状态移至归档文件夹并生成备份/恢复文件。

CLI — Key Commands

CLI — 核心命令

All commands run from the project root. The script is read-only by default.
所有命令均从项目根目录运行。脚本默认处于只读模式。

1. Inspect Only (Safe, No Writes)

1. 仅检查(安全无写入操作)

bash
python scripts/keep_codex_fast.py
Reports: active session size, archived session size, extended path candidates, old session candidates, worktree candidates, log size, top Node/dev processes. Nothing is mutated.
bash
python scripts/keep_codex_fast.py
生成报告:活跃会话大小、归档会话大小、扩展路径候选项、旧会话候选项、工作树候选项、日志大小、占用资源Top的Node/开发进程。无任何内容被修改。

2. Detailed Report (Raw IDs, Titles, Paths)

2. 详细报告(包含原始ID、标题、路径)

bash
python scripts/keep_codex_fast.py --details
Shows thread IDs, chat titles, file paths, and process paths. Use when you need to identify specific sessions or worktrees before archiving.
bash
python scripts/keep_codex_fast.py --details
显示会话ID、聊天标题、文件路径和进程路径。用于在归档前识别特定会话或工作树。

3. Backup Only (No Move/Archive)

3. 仅备份(无移动/归档操作)

bash
python scripts/keep_codex_fast.py --backup-only
Creates backup artifacts of current Codex state without moving or modifying anything. Run this before any apply step as an extra safety net.
⚠️ Backup folders contain private local Codex metadata. Keep them on your machine. Do not publish or share without reviewing contents.
bash
python scripts/keep_codex_fast.py --backup-only
创建当前Codex状态的备份文件,但不移动或修改任何内容。在执行任何变更步骤前运行此命令,作为额外的安全保障。
⚠️ 备份文件夹包含本地Codex的私有元数据。请保存在本地机器上。未经内容审核,请勿发布或分享。

4. Apply Maintenance

4. 执行维护操作

bash
python scripts/keep_codex_fast.py --apply --archive-older-than-days 10 --worktree-older-than-days 7
Archives old non-pinned sessions, moves stale worktrees, rotates large
logs_2.sqlite*
files, prunes dead/temp project references in
config.toml
, and normalizes Windows
\\?\C:\...
path mismatches in SQLite text fields.
bash
python scripts/keep_codex_fast.py --apply --archive-older-than-days 10 --worktree-older-than-days 7
归档未固定的旧会话、移动闲置工作树、轮换大型
logs_2.sqlite*
文件、清理
config.toml
中无效/临时的项目引用、标准化SQLite文本字段中的Windows
\\?\C:\...
路径不匹配问题。

5. Wait for Codex to Exit Before Applying

5. 等待Codex退出后再执行

bash
python scripts/keep_codex_fast.py --apply --wait-for-codex-exit
Holds until no Codex process is detected, then applies maintenance. Use this when you want to queue a cleanup but need Codex to close first.

bash
python scripts/keep_codex_fast.py --apply --wait-for-codex-exit
等待直到检测不到Codex进程后,再执行维护操作。当你想要排队执行清理但需要先关闭Codex时使用此命令。

Workflow: Step-by-Step

工作流:分步指南

Step 1 — Inspect First

步骤1 — 先检查

text
Use $keep-codex-fast to inspect my Codex local state and recommend a safe maintenance plan.
Review the report. Note which sessions are large, which worktrees are stale, and which logs are heavy.
text
Use $keep-codex-fast to inspect my Codex local state and recommend a safe maintenance plan.
查看报告,注意哪些会话体积较大、哪些工作树已闲置、哪些日志占用过多资源。

Step 2 — Create Handoff Docs for Active Chats

步骤2 — 为活跃聊天创建交接文档

For every active repo chat you may want to continue later, run this inside that chat:
text
Create a comprehensive handoff document for this repo/session before I archive Codex history.

Include:
- repo/path and branch
- current goal
- what we already completed
- files touched or investigated
- commands/tests already run
- known errors, warnings, or failing checks
- open decisions
- constraints, user preferences, and do-not-touch areas
- the next 3-7 concrete steps

Also include a reactivation prompt I can paste into a fresh Codex chat so it can continue from this handoff without relying on the old chat context.

Save the handoff in a sensible repo-local place like docs/codex-handoffs/YYYY-MM-DD-topic.md unless this repo already has a better handoff location.
A handoff captures: what you were doing, what changed, what files matter, what commands ran, what is still broken or undecided, and what to do next.
对于每个你之后可能需要继续的活跃仓库聊天,在该聊天内运行以下指令:
text
Create a comprehensive handoff document for this repo/session before I archive Codex history.

Include:
- repo/path and branch
- current goal
- what we already completed
- files touched or investigated
- commands/tests already run
- known errors, warnings, or failing checks
- open decisions
- constraints, user preferences, and do-not-touch areas
- the next 3-7 concrete steps

Also include a reactivation prompt I can paste into a fresh Codex chat so it can continue from this handoff without relying on the old chat context.

Save the handoff in a sensible repo-local place like docs/codex-handoffs/YYYY-MM-DD-topic.md unless this repo already has a better handoff location.
交接文档需记录:你正在做的工作、已变更的内容、重要文件、已执行的命令、仍存在的问题或未决定事项,以及下一步计划。

Step 3 — Apply Safe Maintenance

步骤3 — 执行安全维护

After handoffs exist for all chats you care about:
text
Use $keep-codex-fast to apply safe Codex maintenance.

Before changing anything, confirm that important active repo chats have handoff docs or do not need them.

Then back up first, archive instead of deleting, move stale worktrees, rotate large logs, prune dead config references, and verify the result.

If Codex is currently running, do not mutate local state. Tell me to close Codex first.

在为所有你关心的聊天创建好交接文档后:
text
Use $keep-codex-fast to apply safe Codex maintenance.

Before changing anything, confirm that important active repo chats have handoff docs or do not need them.

Then back up first, archive instead of deleting, move stale worktrees, rotate large logs, prune dead config references, and verify the result.

If Codex is currently running, do not mutate local state. Tell me to close Codex first.

What the Script Can Change

脚本可执行的变更

TargetAction
Old non-pinned active sessionsArchived, not deleted
Stale worktreesMoved out of hot path
Large
logs_2.sqlite*
files
Rotated
Dead/temp project entries in
config.toml
Pruned
Windows
\\?\C:\...
path mismatches in SQLite
Normalized

目标操作
未固定的旧活跃会话归档,而非删除
闲置工作树移出常用路径
大型
logs_2.sqlite*
文件
轮换
config.toml
中的无效/临时项目条目
清理
SQLite中的Windows
\\?\C:\...
路径不匹配问题
标准化

Recurring Maintenance Reminder

定期维护提醒

Set up a weekly or biweekly reminder that reports only — never auto-applies:
text
Use $keep-codex-fast to create a recurring Codex maintenance reminder.

Schedule it weekly if I use Codex heavily, or biweekly if that seems safer.

The reminder should:
- run the keep-codex-fast report first
- never pass --apply or run mutating maintenance automatically
- never archive, move, prune, rotate, normalize, delete, or mutate local Codex state
- remind me to create comprehensive handoff docs and reactivation prompts for active repo chats before any manual apply
- summarize active session size, archived session size, extended path candidates, old session candidates, worktree candidates, log size, and top Node/dev processes
- report heavy Node/dev processes without killing them
- tell me that manual apply should only happen after I confirm handoffs exist or are not needed and Codex is closed

设置每周或每两周的提醒,仅生成报告 — 绝不自动执行变更:
text
Use $keep-codex-fast to create a recurring Codex maintenance reminder.

Schedule it weekly if I use Codex heavily, or biweekly if that seems safer.

The reminder should:
- run the keep-codex-fast report first
- never pass --apply or run mutating maintenance automatically
- never archive, move, prune, rotate, normalize, delete, or mutate local Codex state
- remind me to create comprehensive handoff docs and reactivation prompts for active repo chats before any manual apply
- summarize active session size, archived session size, extended path candidates, old session candidates, worktree candidates, log size, and top Node/dev processes
- report heavy Node/dev processes without killing them
- tell me that manual apply should only happen after I confirm handoffs exist or are not needed and Codex is closed

Python Integration Examples

Python集成示例

Check What Would Be Archived (Dry Run Pattern)

检查将被归档的内容(空运行模式)

python
import subprocess
import json

result = subprocess.run(
    ["python", "scripts/keep_codex_fast.py", "--details"],
    capture_output=True,
    text=True
)
print(result.stdout)
python
import subprocess
import json

result = subprocess.run(
    ["python", "scripts/keep_codex_fast.py", "--details"],
    capture_output=True,
    text=True
)
print(result.stdout)

Trigger Backup Before Any Deploy/Migration Script

在任何部署/迁移脚本前触发备份

python
import subprocess
import sys

def backup_codex_state():
    """Run before any operation that might affect Codex local state."""
    result = subprocess.run(
        ["python", "scripts/keep_codex_fast.py", "--backup-only"],
        capture_output=True,
        text=True
    )
    if result.returncode != 0:
        print(f"[warn] Codex backup step reported issues:\n{result.stderr}")
    else:
        print("[ok] Codex state backed up.")
    return result.returncode

if __name__ == "__main__":
    sys.exit(backup_codex_state())
python
import subprocess
import sys

def backup_codex_state():
    """Run before any operation that might affect Codex local state."""
    result = subprocess.run(
        ["python", "scripts/keep_codex_fast.py", "--backup-only"],
        capture_output=True,
        text=True
    )
    if result.returncode != 0:
        print(f"[warn] Codex backup step reported issues:\n{result.stderr}")
    else:
        print("[ok] Codex state backed up.")
    return result.returncode

if __name__ == "__main__":
    sys.exit(backup_codex_state())

Apply With Age Thresholds From Environment Variables

通过环境变量设置期限后执行维护

python
import subprocess
import os

archive_days = os.environ.get("CODEX_ARCHIVE_DAYS", "14")
worktree_days = os.environ.get("CODEX_WORKTREE_DAYS", "7")

subprocess.run([
    "python", "scripts/keep_codex_fast.py",
    "--apply",
    "--archive-older-than-days", archive_days,
    "--worktree-older-than-days", worktree_days,
    "--wait-for-codex-exit",
], check=True)
python
import subprocess
import os

archive_days = os.environ.get("CODEX_ARCHIVE_DAYS", "14")
worktree_days = os.environ.get("CODEX_WORKTREE_DAYS", "7")

subprocess.run([
    "python", "scripts/keep_codex_fast.py",
    "--apply",
    "--archive-older-than-days", archive_days,
    "--worktree-older-than-days", worktree_days,
    "--wait-for-codex-exit",
], check=True)

Wrap in a Simple Maintenance CLI

封装为简易维护CLI

python
#!/usr/bin/env python3
"""
maintenance.py — thin wrapper around keep_codex_fast.py for project-local use.
"""
import argparse
import subprocess
import sys

SCRIPT = "scripts/keep_codex_fast.py"

def main():
    parser = argparse.ArgumentParser(description="Codex maintenance wrapper")
    parser.add_argument("--inspect", action="store_true", help="Report only, no writes")
    parser.add_argument("--backup", action="store_true", help="Backup only, no moves")
    parser.add_argument("--apply", action="store_true", help="Apply full maintenance")
    parser.add_argument("--archive-days", type=int, default=10)
    parser.add_argument("--worktree-days", type=int, default=7)
    parser.add_argument("--details", action="store_true")
    args = parser.parse_args()

    cmd = ["python", SCRIPT]

    if args.details:
        cmd.append("--details")

    if args.backup:
        cmd.append("--backup-only")
    elif args.apply:
        cmd += [
            "--apply",
            "--archive-older-than-days", str(args.archive_days),
            "--worktree-older-than-days", str(args.worktree_days),
            "--wait-for-codex-exit",
        ]
    # default: inspect only (no extra flags needed)

    result = subprocess.run(cmd, text=True)
    sys.exit(result.returncode)

if __name__ == "__main__":
    main()

python
#!/usr/bin/env python3
"""
maintenance.py — thin wrapper around keep_codex_fast.py for project-local use.
"""
import argparse
import subprocess
import sys

SCRIPT = "scripts/keep_codex_fast.py"

def main():
    parser = argparse.ArgumentParser(description="Codex maintenance wrapper")
    parser.add_argument("--inspect", action="store_true", help="Report only, no writes")
    parser.add_argument("--backup", action="store_true", help="Backup only, no moves")
    parser.add_argument("--apply", action="store_true", help="Apply full maintenance")
    parser.add_argument("--archive-days", type=int, default=10)
    parser.add_argument("--worktree-days", type=int, default=7)
    parser.add_argument("--details", action="store_true")
    args = parser.parse_args()

    cmd = ["python", SCRIPT]

    if args.details:
        cmd.append("--details")

    if args.backup:
        cmd.append("--backup-only")
    elif args.apply:
        cmd += [
            "--apply",
            "--archive-older-than-days", str(args.archive_days),
            "--worktree-older-than-days", str(args.worktree_days),
            "--wait-for-codex-exit",
        ]
    # default: inspect only (no extra flags needed)

    result = subprocess.run(cmd, text=True)
    sys.exit(result.returncode)

if __name__ == "__main__":
    main()

Troubleshooting

故障排查

Script reports nothing unusual but Codex still feels slow

脚本报告无异常但Codex仍运行缓慢

Run with
--details
to see raw thread IDs and process paths:
bash
python scripts/keep_codex_fast.py --details
Check for heavy Node/dev processes listed in the report. The script reports them but does not kill them — review manually.
使用
--details
参数查看原始会话ID和进程路径:
bash
python scripts/keep_codex_fast.py --details
查看报告中列出的高资源占用Node/开发进程。脚本仅会报告这些进程,不会终止它们 — 请手动检查。

Apply step completes but state still seems large

执行维护后状态体积仍较大

The apply step archives, not deletes. Check your Codex archive folder — archived sessions accumulate there over time. Periodically review the archive folder and remove old entries you no longer need.
维护步骤仅会归档,不会删除。检查你的Codex归档文件夹 — 归档会话会随时间积累。定期查看归档文件夹,移除你不再需要的旧条目。

Windows path mismatches (
\\?\C:\...
) appearing in reports

报告中出现Windows路径不匹配问题(
\\?\C:\...

This is a known SQLite text field issue on Windows. The
--apply
step normalizes these automatically. Run:
bash
python scripts/keep_codex_fast.py --apply --archive-older-than-days 10 --worktree-older-than-days 7
这是Windows系统上SQLite文本字段的已知问题。
--apply
步骤会自动标准化这些路径。运行以下命令:
bash
python scripts/keep_codex_fast.py --apply --archive-older-than-days 10 --worktree-older-than-days 7

Backup folder is unexpectedly large

备份文件夹体积异常大

Backup folders snapshot Codex local metadata. If you run
--backup-only
repeatedly, old backups accumulate. Prune old backup snapshots manually — check timestamps in the backup folder and remove those older than your retention window.
备份文件夹会快照Codex的本地元数据。如果你反复运行
--backup-only
命令,旧备份会积累。手动清理旧备份快照 — 检查备份文件夹中的时间戳,移除超出你的保留期限的备份。

--wait-for-codex-exit
hangs indefinitely

--wait-for-codex-exit
无限挂起

Codex may still be running in the background. Check for Codex processes:
bash
undefined
Codex可能仍在后台运行。检查Codex进程:
bash
undefined

macOS/Linux

macOS/Linux

ps aux | grep -i codex
ps aux | grep -i codex

Windows PowerShell

Windows PowerShell

Get-Process | Where-Object { $_.Name -like "codex" }

Close Codex fully, then re-run the apply step.
Get-Process | Where-Object { $_.Name -like "codex" }

完全关闭Codex后,重新执行维护步骤。

Pinned sessions being incorrectly flagged as archive candidates

已固定会话被错误标记为归档候选项

The script should not archive pinned sessions. If you see pinned sessions in the candidate list, run inspect-only first (
--details
) and confirm before applying. Do not pass
--apply
until you have verified the candidate list.

脚本不应归档已固定的会话。如果你在候选列表中看到已固定会话,请先运行仅检查模式(
--details
)并确认,再执行
--apply
。在验证候选列表前,请勿执行
--apply

Safety Guarantees

安全保障

  • Default is read-only. No files are written, moved, or changed unless you explicitly pass
    --apply
    or
    --backup-only
    .
  • Archive, never delete. Sessions, worktrees, and logs are moved to archive folders, not removed.
  • Backup before apply. The script writes backup/restore artifacts before making any change.
  • Codex-running guard. Use
    --wait-for-codex-exit
    or close Codex manually before applying to avoid mutating state while Codex holds file locks.
  • Reminder automation never auto-applies. The recurring reminder prompt is explicitly scoped to report-only. It never passes
    --apply
    .
  • 默认只读模式:除非你明确传入
    --apply
    --backup-only
    参数,否则不会写入、移动或修改任何文件。
  • 归档而非删除:会话、工作树和日志会被移至归档文件夹,而非直接删除。
  • 执行前备份:脚本在进行任何变更前,会生成备份/恢复文件。
  • Codex运行防护:使用
    --wait-for-codex-exit
    参数或手动关闭Codex后再执行维护,避免在Codex持有文件锁时修改状态。
  • 提醒自动化绝不自动执行:定期提醒明确仅生成报告,绝不会传入
    --apply
    参数。