/agent-utilities:cleanup-codexfrom agent-utilities
Diagnose and recover macOS Codex app-servers under descriptor pressure — read-only inspect, two-pass recycle of a detached server (native daemon restart) or of the ChatGPT/Codex desktop app, and snapshot-bound reaping of leftover processes.
Ships in agent-utilities. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
Use this skill when Codex slows down, hits "too many open files", or leaves
processes behind. It runs on macOS. Define CC once, with SKILL_DIR set to
this skill's directory:
CC() { node "$SKILL_DIR/scripts/cleanup-codex.mjs" "$@"; }
CC inspect # add --json for the structured result
Inspect is read-only. For each app-server it reports ancestry (gui when the
ChatGPT/Codex app hosts it, otherwise detached), descriptors, descendants, and
control socket, plus the launchd maxfiles limit GUI apps inherit. A GUI server
under descriptor pressure gets a recommendation to recycle the desktop app.
Warnings describe pressure only; thresholds are tunable (--fd-count-warn,
--highest-fd-warn, --age-hours-warn, --descendant-warn).
Recycle takes two passes. Share the inspect output with the user and get their
go-ahead first. The first pass changes nothing and prints a confirmation token;
rerun the identical command with --confirm '<token>' to act. Any change to the
bound identities in between invalidates the token.
Desktop app (GUI server). For a server hosted by the ChatGPT or Codex app:
CC recycle --pid <gui-pid> --desktop
CC recycle --pid <gui-pid> --desktop --confirm '<token>'
Confirming quits the app, which closes the user's desktop session (every open window and thread) until it reopens; say so when asking for the go-ahead.
Both passes run only when the app is idle. The Codex databases the selected
server holds open name its Codex home, and the newest state_N.sqlite there
lists its threads. Every thread counts as the app's except those from
codex exec, the CLI, the VS Code extension, MCP or subagents. The app is busy
if a counted thread updated in the last 5 minutes, a counted thread active in
the last day still has a turn or tool call open, an app-server child started
in the last 5 minutes, or the app is frontmost. Anything that cannot be read
or tied to that server counts as busy, including an app with no threads yet.
Otherwise the command refuses with desktop-busy and lists why; retry once
the work has finished. An open turn left behind by a crash also counts: the
refusal names its thread, and the user clears it by finishing, cancelling or
archiving that thread in the app. The check repeats under the lock, with one
last activity read just before quitting. It also refuses when run from inside
the app (desktop-recycle-inside-app); run it from a terminal outside the app.
Before quitting it arms a detached watchdog: if the recycle process dies or
anything fails, the watchdog reopens that exact bundle in the background once
the old app exits, unless it is already running, and gives up after 10
minutes. Then it asks the app to quit and waits up to 30 seconds. The app is
never force-killed. If it does not quit (say, a dialog is open), the command
stops with desktop-host-quit-timeout (or desktop-quit-request-failed when
the request itself failed) and the watchdog is cut to 60 seconds, so a quit
the user later makes on purpose is not undone. If whether the app quit cannot
be read, it stops with desktop-host-quit-unverified and touches nothing
more; the armed watchdog reopens the app once it sees it gone. Once the app
is gone it reopens that exact bundle at once, waits up to 90 seconds for a new server and up to 30 for the old
server to exit, then reaps leftovers of the old tree that still match their
recorded identities. Every relaunch uses open -g on the bundle path (falling
back to its bundle id), so it never takes focus. Any later failure is reported
beside the relaunch with exit 3. Allow the confirmed pass at least 3
minutes, or run it in the background.
GUI apps inherit launchd's maxfiles soft limit (256 by default), but current
Codex app-servers raise their own limit, so a descriptor above launchd's soft
limit proves the server is not capped there. Only a server still below that
limit gets the desktop-recycle and launchd advice (a root LaunchDaemon running
launchctl limit maxfiles 8192 unlimited at boot); recommend it rather than
changing it here.
Detached server. Managed mode (the default) rechecks that the daemon's PID
record still names the receipt's server, runs codex app-server daemon restart,
then verifies a new server owns the control socket and the old tree is gone.
For a server the daemon does not run, --unmanaged --launcher <path> stops the
exact recorded tree and starts the launcher (default RAILYARD_CODEX_BIN, then
codex on PATH).
CC recycle --pid <detached-pid>
CC recycle --pid <detached-pid> --unmanaged --launcher ~/.local/bin/codex
--nofile-attestor <path> (or RAILYARD_NOFILE_ATTESTOR) is optional. Without
it, the descriptor limit is reported as unverified, and an unmanaged launcher
must canonically be the old server's executable. With it, the replacement must
attest at least --min-soft-limit (default 8192). The attestor is a regular
executable owned by you or root, not group/world-writable, and prints one JSON
object with exactly these keys:
ATTESTOR --pid PID --json →
{"schema":"codex-nofile-attestation-v1","pid":…,"uid":…,"processStartTime":…,"softNofile":…},
where processStartTime is the process's start time as an ISO string.ATTESTOR --launcher PATH --json →
{"schema":"codex-launcher-nofile-attestation-v1","path":…,"dev":…,"ino":…,"replacementExecutable":…,"softNofile":…},
naming the launcher file and the canonical executable it starts.For a detached server that will exit on its own, record its tree while it runs and reap once it is gone:
CC inspect --snapshot "$TMPDIR/codex-tree.json"
CC reap --snapshot "$TMPDIR/codex-tree.json"
npm exec MCP
servers, are reported and left alone.An opt-in SessionEnd hook (cleanup --hook) can clean one finished session's
processes automatically. The plugin does not register it; add it only when the
user asks for automatic cleanup. RAILYARD_CLEANUP_CODEX_HOOK_DISABLED=1 turns
it into a no-op.
The cleanup command retains its existing RAILYARD_* environment variables,
receipt location, and mutation lock so older and newer installations share
the same process-safety state. If you previously configured the optional hook,
point its command at this skill's installed scripts/cleanup-codex.mjs.
0 healthy or recycled · 1 warning · 2 refused, or a first pass awaiting
confirmation · 3 an attempted action could not be verified; the result names
the recovery reason.
scripts/canary.test.mjs (opens in a new tab)scripts/cleanup-codex.mjs (opens in a new tab)scripts/desktop.test.mjs (opens in a new tab)scripts/hook.test.mjs (opens in a new tab)scripts/inventory.test.mjs (opens in a new tab)scripts/lib/constants.mjs (opens in a new tab)scripts/lib/desktop-activity.mjs (opens in a new tab)scripts/lib/desktop-watchdog.mjs (opens in a new tab)scripts/lib/desktop.mjs (opens in a new tab)scripts/lib/hook-receipts.mjs (opens in a new tab)scripts/lib/hook.mjs (opens in a new tab)scripts/lib/inventory.mjs (opens in a new tab)scripts/lib/process-evidence.mjs (opens in a new tab)scripts/lib/reap.mjs (opens in a new tab)scripts/lib/recycle-deps.mjs (opens in a new tab)scripts/lib/recycle-evidence.mjs (opens in a new tab)scripts/lib/recycle.mjs (opens in a new tab)scripts/lib/snapshot.mjs (opens in a new tab)scripts/lib/transaction.mjs (opens in a new tab)scripts/recycle.test.mjs (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
agent-utilities@novotnyllc is listed by novotnyllc/marketplace — review the source before installing
npx claudepluginhub novotnyllc/marketplace --plugin agent-utilities15 skills in this plugin
/browser-useControl the user's existing signed-in Chrome: native browser tool first, with direct DevTools attachment only as a last fallback./clean-room-rebuildClean-room rebuild of a feature from a shipped app without its source. REA investigation writes a behaviour-only spec, a fresh session builds from it, and mutation-tested checks verify the result. For investigation only, use reverse-engineer-anything./create-cliCLI UX/spec: args, flags, help, output, errors, config, dry-run./fleet-chezmoiInspect, compare, and deliberately reconcile chezmoi source and live-state drift across configured machines. Use for chezmoi status, diff, pull, add, apply, source-repository drift, or post-apply verification./frontend-designCreate distinctive, production-grade frontend UI. Use when building web pages, apps, or components and design quality matters./fusion-parametric-designCreate, edit, repair, inspect, or validate CAD / Autodesk Fusion models and 3D-printable parametric mechanical parts (enclosures, mounts, brackets, assemblies, fit coupons) via Fusion MCP. Not for artistic mesh sculpting, animation, or rendering.