keep-codex-fast-maintenance
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesekeep-codex-fast-maintenance
keep-codex-fast-maintenance
Skill by ara.so — Codex Skills collection.
A backup-first maintenance skill for keeping local Codex state fast, clean, and recoverable. When Codex starts feeling heavy after weeks of chats, terminals, logs, worktrees, and project history, this gives you a calm way to inspect what's going on and reduce local drag without losing context.
由ara.so开发的Skill — Codex Skills合集。
这是一款以备份为优先的维护Skill,用于保持本地Codex状态流畅、整洁且可恢复。当Codex在数周的聊天、终端操作、日志记录、工作树和项目历史积累后变得运行缓慢时,这款工具能让你从容检查当前状态,在不丢失上下文的前提下减少本地存储负担。
Core Principle
核心原则
Make handoffs first. Archive, don't delete. Apply changes only when you are ready.
All operations are read-only by default. Nothing is mutated until you explicitly use .
--apply先完成交接。归档而非删除。仅在你准备就绪后再应用更改。
所有操作默认均为只读模式。除非你明确使用参数,否则不会修改任何内容。
--applyInstallation
安装
Clone or copy this repository into your Codex skills directory:
bash
cd ~/.codex/skills # or your Codex skills path
git clone https://github.com/vibeforge1111/keep-codex-fast.gitOr ask Codex directly:
text
Install the keep-codex-fast skill from https://github.com/vibeforge1111/keep-codex-fast将此仓库克隆或复制到你的Codex skills目录中:
bash
cd ~/.codex/skills # 或你的Codex skills路径
git clone https://github.com/vibeforge1111/keep-codex-fast.git或者直接让Codex安装:
text
Install the keep-codex-fast skill from https://github.com/vibeforge1111/keep-codex-fastThree Modes
三种模式
- Inspect (default): Report-only, no writes, privacy-safe
- Maintain: Backs up, archives old sessions, moves stale worktrees, rotates logs, prunes dead config
- Repair (optional): Only with flag; trims oversized SQLite title/preview metadata after backup
--repair-thread-metadata-bloat
- 检查(默认):仅生成报告,不写入数据,隐私安全
- 维护:备份数据、归档旧会话、移动闲置工作树、轮转日志、清理无效配置
- 修复(可选):仅在使用标志时生效;备份后修剪SQLite中过大的标题/预览元数据
--repair-thread-metadata-bloat
Key Commands
关键命令
Inspect Mode (Read-Only)
检查模式(只读)
Basic inspection report:
bash
python scripts/keep_codex_fast.pyDetailed inspection with thread IDs, titles, and paths:
bash
python scripts/keep_codex_fast.py --details基础检查报告:
bash
python scripts/keep_codex_fast.py包含线程ID、标题和路径的详细检查:
bash
python scripts/keep_codex_fast.py --detailsBackup Mode
备份模式
Create backups only without changing local state:
bash
python scripts/keep_codex_fast.py --backup-onlyImportant: Backup folders contain private local Codex metadata. Keep them on your machine and do not share publicly.
仅创建备份,不修改本地状态:
bash
python scripts/keep_codex_fast.py --backup-only重要提示:备份文件夹包含本地Codex的私有元数据。请将其保存在本地,不要公开分享。
Maintenance Mode
维护模式
Apply core maintenance (archives sessions, moves worktrees, rotates logs):
bash
python scripts/keep_codex_fast.py --applyCustomize retention periods:
bash
python scripts/keep_codex_fast.py --apply \
--archive-older-than-days 10 \
--worktree-older-than-days 7Wait for Codex to exit before applying:
bash
python scripts/keep_codex_fast.py --apply --wait-for-codex-exit应用核心维护操作(归档会话、移动工作树、轮转日志):
bash
python scripts/keep_codex_fast.py --apply自定义保留期限:
bash
python scripts/keep_codex_fast.py --apply \
--archive-older-than-days 10 \
--worktree-older-than-days 7等待Codex退出后再应用更改:
bash
python scripts/keep_codex_fast.py --apply --wait-for-codex-exitRepair Thread Metadata Bloat (Advanced)
修复线程元数据膨胀(进阶)
Only use when the report shows unusually large title/preview metadata:
bash
python scripts/keep_codex_fast.py --apply --repair-thread-metadata-bloatThis trims oversized SQLite title/preview fields that can slow chat navigation. The actual conversation transcript remains intact.
仅当报告显示标题/预览元数据异常庞大时使用:
bash
python scripts/keep_codex_fast.py --apply --repair-thread-metadata-bloat此操作会修剪中过大的标题/预览字段,这些字段可能会拖慢聊天导航速度。实际对话记录会保持完整。
state_5.sqliteHandoffs First: Create Continuity Documents
先完成交接:创建连续性文档
Before archiving any important active chats, create handoff documents. These let you archive heavy chat history and start fresh threads without losing context.
Paste this into each active repo chat you want to preserve:
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.在归档任何重要的活跃聊天之前,请创建交接文档。这些文档能让你归档庞大的聊天历史并开启新的线程,同时不会丢失上下文。
将以下内容粘贴到每个你想要保留的活跃仓库聊天中:
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.Common Usage Patterns
常见使用模式
Pattern 1: Safe Inspection and Maintenance
模式1:安全检查与维护
text
Use $keep-codex-fast to inspect my Codex local state and recommend a safe maintenance plan.After reviewing the report:
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 inspect my Codex local state and recommend a safe maintenance plan.查看报告后:
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.Pattern 2: Weekly Maintenance Reminder
模式2:每周维护提醒
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 closedtext
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 closedPattern 3: Backup Before Major Changes
模式3:重大更改前备份
bash
undefinedbash
undefinedCreate backup snapshot before applying any changes
Create backup snapshot before applying any changes
python scripts/keep_codex_fast.py --backup-only
python scripts/keep_codex_fast.py --backup-only
Review what will change
Review what will change
python scripts/keep_codex_fast.py --details
python scripts/keep_codex_fast.py --details
Apply changes with custom retention
Apply changes with custom retention
python scripts/keep_codex_fast.py --apply
--archive-older-than-days 14
--worktree-older-than-days 10
--archive-older-than-days 14
--worktree-older-than-days 10
undefinedpython scripts/keep_codex_fast.py --apply
--archive-older-than-days 14
--worktree-older-than-days 10
--archive-older-than-days 14
--worktree-older-than-days 10
undefinedWhat Gets Maintained
维护内容
Active Sessions
活跃会话
- Default retention: 7 days
- Non-pinned sessions older than threshold are archived
- Pinned sessions are never archived
- Archives stored in timestamped backup folders
- 默认保留期限:7天
- 超过期限的非固定会话会被归档
- 固定会话永远不会被归档
- 归档内容存储在带时间戳的备份文件夹中
Worktrees
工作树
- Default retention: 7 days
- Stale worktrees moved to archive location
- Active worktrees preserved
- Worktree references updated in config
- 默认保留期限:7天
- 闲置工作树会被移动到归档位置
- 活跃工作树会被保留
- 配置中的工作树引用会被更新
Logs
日志
- Large files rotated
logs_2.sqlite* - Old logs compressed and archived
- Current logs preserved at manageable size
- 较大的文件会被轮转
logs_2.sqlite* - 旧日志会被压缩并归档
- 当前日志会被保留在可管理的大小
Config
配置
- Dead/temporary project entries pruned
- Windows extended paths () normalized
\\?\C:\... - Invalid references cleaned up
- 清理无效/临时项目条目
- 标准化Windows扩展路径()
\\?\C:\... - 清理无效引用
Thread Metadata (Optional)
线程元数据(可选)
- Only with
--repair-thread-metadata-bloat - Trims oversized title/preview fields in
state_5.sqlite - Conversation transcripts remain intact
- Repair manifest created for restore capability
- 仅在使用时生效
--repair-thread-metadata-bloat - 修剪中过大的标题/预览字段
state_5.sqlite - 对话记录保持完整
- 生成修复清单以便恢复
Configuration
配置
The script uses sensible defaults. Override via command-line flags:
python
undefined脚本使用合理的默认值。可通过命令行标志覆盖:
python
undefinedDefault thresholds
Default thresholds
ARCHIVE_OLDER_THAN_DAYS = 7
WORKTREE_OLDER_THAN_DAYS = 7
LOG_SIZE_THRESHOLD_MB = 100
ARCHIVE_OLDER_THAN_DAYS = 7
WORKTREE_OLDER_THAN_DAYS = 7
LOG_SIZE_THRESHOLD_MB = 100
Override example
Override example
python scripts/keep_codex_fast.py --apply
--archive-older-than-days 14
--worktree-older-than-days 10
--archive-older-than-days 14
--worktree-older-than-days 10
undefinedpython scripts/keep_codex_fast.py --apply
--archive-older-than-days 14
--worktree-older-than-days 10
--archive-older-than-days 14
--worktree-older-than-days 10
undefinedReal Code Example: Custom Maintenance Script
真实代码示例:自定义维护脚本
python
#!/usr/bin/env python3
"""
Custom Codex maintenance wrapper
"""
import subprocess
import sys
from pathlib import Path
from datetime import datetime
def run_maintenance(dry_run=True):
"""Run Codex maintenance with custom settings"""
# Create timestamped log
log_dir = Path.home() / ".codex" / "maintenance-logs"
log_dir.mkdir(exist_ok=True)
log_file = log_dir / f"maintenance-{datetime.now():%Y%m%d-%H%M%S}.log"
# Build command
cmd = [
sys.executable,
"scripts/keep_codex_fast.py",
]
if not dry_run:
cmd.append("--apply")
cmd.extend([
"--archive-older-than-days", "14",
"--worktree-older-than-days", "10",
])
else:
cmd.append("--details")
# Run with logging
print(f"Running maintenance (dry_run={dry_run})...")
print(f"Logging to: {log_file}")
with open(log_file, "w") as f:
result = subprocess.run(
cmd,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True
)
f.write(result.stdout)
print(result.stdout)
return result.returncode == 0
if __name__ == "__main__":
# First inspect
print("=== INSPECTION PHASE ===")
if not run_maintenance(dry_run=True):
sys.exit(1)
# Confirm before applying
response = input("\nApply maintenance changes? (yes/no): ")
if response.lower() == "yes":
print("\n=== MAINTENANCE PHASE ===")
run_maintenance(dry_run=False)
else:
print("Maintenance cancelled.")python
#!/usr/bin/env python3
"""
Custom Codex maintenance wrapper
"""
import subprocess
import sys
from pathlib import Path
from datetime import datetime
def run_maintenance(dry_run=True):
"""Run Codex maintenance with custom settings"""
# Create timestamped log
log_dir = Path.home() / ".codex" / "maintenance-logs"
log_dir.mkdir(exist_ok=True)
log_file = log_dir / f"maintenance-{datetime.now():%Y%m%d-%H%M%S}.log"
# Build command
cmd = [
sys.executable,
"scripts/keep_codex_fast.py",
]
if not dry_run:
cmd.append("--apply")
cmd.extend([
"--archive-older-than-days", "14",
"--worktree-older-than-days", "10",
])
else:
cmd.append("--details")
# Run with logging
print(f"Running maintenance (dry_run={dry_run})...")
print(f"Logging to: {log_file}")
with open(log_file, "w") as f:
result = subprocess.run(
cmd,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True
)
f.write(result.stdout)
print(result.stdout)
return result.returncode == 0
if __name__ == "__main__":
# First inspect
print("=== INSPECTION PHASE ===")
if not run_maintenance(dry_run=True):
sys.exit(1)
# Confirm before applying
response = input("\nApply maintenance changes? (yes/no): ")
if response.lower() == "yes":
print("\n=== MAINTENANCE PHASE ===")
run_maintenance(dry_run=False)
else:
print("Maintenance cancelled.")Troubleshooting
故障排除
"Codex is currently running"
"Codex is currently running"
Close Codex before applying changes:
bash
undefined应用更改前请关闭Codex:
bash
undefinedWait for Codex to exit automatically
Wait for Codex to exit automatically
python scripts/keep_codex_fast.py --apply --wait-for-codex-exit
python scripts/keep_codex_fast.py --apply --wait-for-codex-exit
Or manually close Codex first
Or manually close Codex first
undefinedundefinedBackup folders growing large
备份文件夹过大
Backups contain full session data and metadata. Clean old backups manually:
bash
undefined备份包含完整的会话数据和元数据。请手动清理旧备份:
bash
undefinedList backups
List backups
ls -lh ~/.codex/backups/ # or wherever backups are stored
ls -lh ~/.codex/backups/ # or wherever backups are stored
Remove old backups (review first!)
Remove old backups (review first!)
find ~/.codex/backups -type d -mtime +30 -exec rm -rf {} +
undefinedfind ~/.codex/backups -type d -mtime +30 -exec rm -rf {} +
undefinedThread metadata repair needed
需要修复线程元数据
When the report shows large title/preview metadata:
text
Warning: Found threads with title/preview metadata > 10KB
Consider using --repair-thread-metadata-bloatApply the repair:
bash
python scripts/keep_codex_fast.py --apply --repair-thread-metadata-bloatKeep the repair manifest private. It contains the original full title/preview text.
当报告显示标题/预览元数据过大时:
text
Warning: Found threads with title/preview metadata > 10KB
Consider using --repair-thread-metadata-bloat应用修复:
bash
python scripts/keep_codex_fast.py --apply --repair-thread-metadata-bloat请妥善保存修复清单,它包含原始完整的标题/预览文本。
Restore from backup
从备份恢复
If you need to restore state after applying changes:
- Locate the backup folder (timestamped in output)
- Follow instructions in within backup
restore-instructions.txt - For thread metadata repairs, use
restore-thread-metadata.py
如果应用更改后需要恢复状态:
- 找到备份文件夹(输出中带有时间戳)
- 按照备份文件夹内中的说明操作
restore-instructions.txt - 对于线程元数据修复,使用
restore-thread-metadata.py
Process reporting without killing
进程报告但不终止
The script reports heavy Node/dev processes but never kills them:
bash
undefined脚本会报告占用资源较多的Node/开发进程,但不会终止它们:
bash
undefinedJust inspect processes
Just inspect processes
python scripts/keep_codex_fast.py --details
You decide whether to stop processes manually.python scripts/keep_codex_fast.py --details
你可以自行决定是否手动终止进程。Mental Model
思维模型
- Chats are for execution
- Handoff docs are for memory
- Archives are for history
- Fresh threads are for speed
- 聊天用于执行操作
- 交接文档用于保存记忆
- 归档用于存储历史
- 新线程用于保证速度
Safety Guarantees
安全保障
- Read-only by default: No writes without
--apply - Backup first: All changes create timestamped backups
- Archive, don't delete: Sessions and worktrees moved, not removed
- Restore artifacts: Every change includes restore instructions
- Handoff prompts: Preserve context before archiving
- Process detection: Warns when Codex is running, never force-kills
- 默认只读:不使用则不会写入数据
--apply - 先备份:所有更改都会生成带时间戳的备份
- 归档而非删除:会话和工作树会被移动,而非移除
- 恢复文件:每次更改都会包含恢复说明
- 交接提示:归档前保留上下文
- 进程检测:当Codex运行时发出警告,从不强制终止
Advanced: Direct Script Integration
进阶:直接脚本集成
python
from pathlib import Path
import syspython
from pathlib import Path
import sysAdd keep-codex-fast to path
Add keep-codex-fast to path
skill_path = Path(file).parent / "keep-codex-fast"
sys.path.insert(0, str(skill_path / "scripts"))
from keep_codex_fast import (
inspect_codex_state,
create_backup,
apply_maintenance,
)
skill_path = Path(file).parent / "keep-codex-fast"
sys.path.insert(0, str(skill_path / "scripts"))
from keep_codex_fast import (
inspect_codex_state,
create_backup,
apply_maintenance,
)
Use as library
Use as library
state = inspect_codex_state()
print(f"Active sessions: {state['active_session_count']}")
print(f"Total size: {state['total_size_mb']:.1f}MB")
state = inspect_codex_state()
print(f"Active sessions: {state['active_session_count']}")
print(f"Total size: {state['total_size_mb']:.1f}MB")
Create backup before custom operation
Create backup before custom operation
backup_path = create_backup()
print(f"Backup created: {backup_path}")
undefinedbackup_path = create_backup()
print(f"Backup created: {backup_path}")
undefinedWhen to Use This Skill
使用时机
- Codex feels slower after weeks of heavy use
- Many long chat threads accumulated
- Working across multiple repos and worktrees
- Frequent terminal/dev server usage
- Want safe, reversible maintenance
- Need to reduce local state without losing context
- Codex在数周高频使用后运行变慢
- 积累了大量长聊天线程
- 在多个仓库和工作树间切换工作
- 频繁使用终端/开发服务器
- 需要安全、可撤销的维护操作
- 需要在不丢失上下文的前提下减少本地存储负担