Lightweight CLI for scanning and safely cleaning local Codex MCP helper process residue.
It is designed for the common case where closing a Codex window or session leaves STDIO MCP helpers such as codegraph, apifox-mcp-server, or node_repl running in the background.
Use it directly with npx:
npx mcp-process-cleaner scanOr install it globally:
npm install -g mcp-process-cleaner
mcp-cleanup scanThe default workflow is scan first, then clean explicitly:
mcp-cleanup scan
mcp-cleanup clean
mcp-cleanup clean --applyscanshows MCP-related process residue.cleanis a dry run and prints the exact targets.clean --applysendsSIGTERMto detected Codex STDIO MCP root processes.--forceupgrades cleanup toSIGKILL.
| Command | Purpose |
|---|---|
mcp-cleanup scan |
Show Codex STDIO MCP residue and local HTTP MCP services. |
mcp-cleanup scan --json |
Print machine-readable scan output. |
mcp-cleanup clean |
Dry-run cleanup and show targets. |
mcp-cleanup clean --apply |
Clean detected Codex STDIO MCP root processes. |
mcp-cleanup clean --name codegraph --apply |
Clean only one MCP family. |
mcp-cleanup install-hook --apply |
Install the Codex hook for deferred cleanup. |
mcp-cleanup zombies scan |
Optional system zombie diagnostics. |
Install the Codex hook with one command:
mcp-cleanup install-hook --applyIt writes or merges ~/.codex/hooks.json, backs up an existing file before changing it, and does not duplicate the hook if you run it again.
Codex Stop hooks run at turn scope, not app-window-exit scope. For that reason the installed hook does not directly kill MCP processes on every Stop. Instead, it installs a deferred watcher:
{
"hooks": {
"Stop": [
{
"hooks": [
{
"type": "command",
"command": "mcp-cleanup hook --apply --codex-stop-json",
"timeout": 5,
"statusMessage": "Scheduling MCP cleanup"
}
]
}
]
}
}mcp-cleanup hook --apply --codex-stop-json starts a detached watcher and prints the empty JSON object Codex expects from a successful Stop hook. The watcher waits for the Codex parent process to exit, then runs the same cleanup behavior as mcp-cleanup clean --apply.
For manual debugging, you can omit --codex-stop-json to see a human-readable report:
mcp-cleanup hook --applyAfter editing hooks, Codex may ask you to review and trust the command through /hooks.
By default, cleanup targets only Codex STDIO MCP root processes:
codegraph serve --mcpapifox-mcp-server- Codex
node_repl
Local HTTP MCP services are reported but skipped by default. For example, a service such as xiaocan may show as 1 service, 6 processes because it is started through a shell/package-manager/watch chain. That is still one HTTP service, and ordinary cleanup will not kill it.
- Read-only by default.
scannever kills processes.cleanis a dry run unless--applyis present.SIGKILLrequires--force.- Local HTTP MCP services are skipped by default.
- System zombie processes are not shown in the default scan.
A Z or <defunct> process has already exited. Killing the child PID cannot clear it. The parent process must reap it, or the parent app must be restarted.
System zombie diagnostics are intentionally separate from normal MCP cleanup:
mcp-cleanup zombies scan
mcp-cleanup zombies clean --parent <pid>
mcp-cleanup zombies clean --parent <pid> --applyUse this only when you explicitly want to inspect or signal the parent app. Normal mcp-cleanup scan and mcp-cleanup clean --apply will not show or touch unrelated apps.
npm test
npm run pack:check
node src/cli.js scanThis package has no runtime dependencies and uses Node.js built-ins only.