Codex sweep

From Takazudo/claude-resources · View interactive version

Codex sweep is an AI agent skill from the GitHub repository Takazudo/claude-resources. Kill stale Codex plugin processes and clean their cxc-* temp dirs. Use for 'codex sweep', 'stale codex', 'too many codex processes', or EMFILE / 'too many open files' / inotify exhaustion errors.

How to use this skill

Skill file

Codex Sweep

Scans the process table for stale OpenAI Codex plugin processes and kills them, then removes their dead cxc-* temp dirs.

Why they accumulate: the codex plugin spawns one detached broker (app-server-broker.mjs + a codex app-server child) per workspace, and cleanup relies on Claude's SessionEnd hook — which never fires on killed terminals, crashes, or worktree-teammate sessions. Orphans pile up (~3 processes each); on WSL2 they exhaust fs.inotify.max_user_instances=128 and Vite starts failing with EMFILE.

Safe by design: the plugin respawns a broker on demand (ensureBrokerSession self-heal), so a false-positive kill costs at most a ~2s respawn. Brokers belonging to live Claude sessions are detected and kept.

Run

Run directly — no confirmation step needed (unlike /dev-clean-wsl's deletions, kills here cost nothing to redo):

node $HOME/.claude/scripts/codex-sweep.js

Pass through user args:

What it kills:

Report

Relay the script's summary line to the user. On --dry-run, show the per-broker table.

If the user hit EMFILE / inotify exhaustion on WSL2

After sweeping, verify the pressure dropped:

find /proc/*/fd -lname 'anon_inode:inotify' 2>/dev/null | wc -l

If it recurs, raise the ceiling (see the inotify note in /dev-clean-wsl):

echo 'fs.inotify.max_user_instances=1024' | sudo tee /etc/sysctl.d/60-inotify.conf
sudo sysctl --system

Troubleshooting

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.