Loading...
Loading...
Safely inspect, backup, and maintain local Codex state to keep performance fast and clean
npx skill4agent add aradotso/codex-skills keep-codex-fast-maintenanceSkill by ara.so — Codex Skills collection.
--applycd ~/.codex/skills # or your Codex skills path
git clone https://github.com/vibeforge1111/keep-codex-fast.gitInstall the keep-codex-fast skill from https://github.com/vibeforge1111/keep-codex-fast--repair-thread-metadata-bloatpython scripts/keep_codex_fast.pypython scripts/keep_codex_fast.py --detailspython scripts/keep_codex_fast.py --backup-onlypython scripts/keep_codex_fast.py --applypython scripts/keep_codex_fast.py --apply \
--archive-older-than-days 10 \
--worktree-older-than-days 7python scripts/keep_codex_fast.py --apply --wait-for-codex-exitpython scripts/keep_codex_fast.py --apply --repair-thread-metadata-bloatCreate 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.Use $keep-codex-fast to inspect my Codex local state and recommend a safe maintenance plan.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.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# Create backup snapshot before applying any changes
python scripts/keep_codex_fast.py --backup-only
# Review what will change
python scripts/keep_codex_fast.py --details
# Apply changes with custom retention
python scripts/keep_codex_fast.py --apply \
--archive-older-than-days 14 \
--worktree-older-than-days 10logs_2.sqlite*\\?\C:\...--repair-thread-metadata-bloatstate_5.sqlite# Default thresholds
ARCHIVE_OLDER_THAN_DAYS = 7
WORKTREE_OLDER_THAN_DAYS = 7
LOG_SIZE_THRESHOLD_MB = 100
# Override example
python scripts/keep_codex_fast.py --apply \
--archive-older-than-days 14 \
--worktree-older-than-days 10#!/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.")# Wait for Codex to exit automatically
python scripts/keep_codex_fast.py --apply --wait-for-codex-exit
# Or manually close Codex first# List backups
ls -lh ~/.codex/backups/ # or wherever backups are stored
# Remove old backups (review first!)
find ~/.codex/backups -type d -mtime +30 -exec rm -rf {} +Warning: Found threads with title/preview metadata > 10KB
Consider using --repair-thread-metadata-bloatpython scripts/keep_codex_fast.py --apply --repair-thread-metadata-bloatrestore-instructions.txtrestore-thread-metadata.py# Just inspect processes
python scripts/keep_codex_fast.py --details--applyfrom pathlib import Path
import sys
# 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,
)
# 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")
# Create backup before custom operation
backup_path = create_backup()
print(f"Backup created: {backup_path}")