How to stop a background AI agent safely
Find the process first (npx skillhawk agents or ps), check its command so you stop the right one, then send it a normal stop signal with kill <pid> and use kill -9 only if it will not exit. If something keeps restarting it, remove the schedule as well: the crontab line, the launchd or systemd job, or the GitHub workflow.
In order
- Interactive session: switch to its terminal and exit it normally, so it can finish writing its log.
- Headless or detached process:
kill <pid>sends SIGTERM, which lets it clean up. Wait a few seconds;kill -9 <pid>is the last resort. - Leftover dev servers and watchers: stop them by pid the same way;
lsof -nP -iTCP -sTCP:LISTENshows which process holds a port. - Schedules:
crontab -eto delete the line;launchctl bootout gui/$(id -u)/<label>for a launchd job on macOS;systemctl --user disable --now <unit>on Linux;gh workflow disable <workflow>for a scheduled GitHub Action. - Idle check-ins in Claude Code: the docs say
CLAUDE_CODE_GOAL_CHECKIN_MINUTES=0turns them off.
A worked example
skillhawk agents ends with the exact command for what it flagged (example data):
Nothing was stopped. To stop the flagged processes yourself: kill 100 300
The Skillhawk command that helps
See what is running, then stop it yourself:
npx skillhawk agents
kill 100 300
skillhawk never stops anything itself; you decide.
Questions
Is kill -9 safe for an agent?
Use it last. SIGKILL gives the process no chance to finish writing files or logs; try a plain kill (SIGTERM) first.
I stopped it and it came back. Why?
A scheduler started it again. Check crontab, launchd or systemd user jobs and scheduled GitHub workflows, and remove the entry.
Sources
- launchctl on macOS (SS64)
- GitHub CLI: gh workflow disable
- Claude Code docs: Manage costs effectively (idle check-ins)