← Back to library

Clean up after coding agent sessions

_matthew_ found on Hacker News that heavy swapping came from a RAM-backed /tmp, so a a frequent job now deletes temp files untouched for about two hours that no process has open. They also found orphaned processes forked by earlier coding agents, so their spawner wraps every session in a cgroup and kills the group when work ends.

  • OutcomeWrap every agent run in a process group that gets killed when the task ends, and clear old temp files on a schedule.
  • SetupUnder an hour
  • LevelIntermediate
  • Credit_matthew_ on Hacker News
View original
Works with
Custom agent

Published Oct 23, 2026Updated Oct 23, 2026AI dry run on sample input: passed Oct 23, 2026Source verified Oct 23, 2026

When should you use it?

  • Your machine slows after many agent sessions
  • Agents start servers and leave them
  • You run Linux

Not for: Single short sessions; Machines you do not administer

What do you need, and what do you get?

You need

  • Agent launcher script
  • Linux cgroups
  • Temp folder rules

You get

  • Sessions isolated in process groups
  • Leftover processes killed
  • Temp space kept small

How does it work, step by step?

  1. Check memorySee whether the temp folder is in memory and filling up.
  2. Clean tempSchedule a job that removes old unused temp files.
  3. Wrap sessionsLaunch every agent run inside a dedicated cgroup.
  4. Kill on finishEnd all processes in that group when the task completes.
  5. WatchCheck memory and process counts after a week.

The prompt

Our own prompt, inspired by _matthew_ on Hacker News and written to work in Custom agent. Values in lime are placeholders.

Fill in the blanks (optional; the copied prompt uses your values)

Prompt2 variables
Write a launcher that wraps each agent run in a dedicated cgroup and terminates the whole group as soon as the run finishes.
Also write a scheduled job that removes files in {tmp_dir} older than {hours} hours that no process has open. Explain how to test both safely.

Inspired by _matthew_ on Hacker News: Comment in Codex Desktop continuously generates Crashpad pending dumps. The prompt above is written by playbooks.bot in our own words; nothing from the original is quoted.

What can go wrong?

  • Do not delete files still in use; check open handles.
  • Long-running servers you want must live outside the group.
  • Test the cleanup on a non-critical machine first.

Our take

Coding agents leave debris that a human session would not: dev servers nobody stops, child processes that outlive the task, and temp files that pile up in memory-backed storage. _matthew_'s diagnosis is the first useful step, because swap pressure on such machines often comes from tmpfs rather than the agents themselves. Check that before buying RAM. Of the two fixes, the cgroup wrapper is the stronger one, because it guarantees cleanup no matter how the agent exits; systemd-run --scope gives you the same effect without writing your own spawner. Before enabling the kill step, list anything that should legitimately survive a session, such as a database container, and start it outside the group. For the temp job, keep the open-handle check the commenter describes, so a long build is never pulled out from under itself, and log what it removes for the first week. Measure free memory and swap before and after, so you know which change mattered. On macOS the same idea applies, but you will need a process-group kill instead of cgroups.

Where the time goes back: Your machine stays fast across many agent sessions.

FAQ

Where was the swap coming from?
Mostly the memory-backed temp folder, per the developer.
Why cgroups?
They let you kill every process a session started, including forks.

Source and credit

Inspired by _matthew_ on Hacker News. We describe the idea in our own words, link to the original, and wrote the prompt ourselves; nothing is quoted.

Inspired by
Comment in Codex Desktop continuously generates Crashpad pending dumps
Creator
_matthew_ on Hacker News
Published on
Hacker News
Original date
Oct 17, 2026
License
Not openly licensed (the poster keeps all rights), so we quote nothing and link to the original
Originally for
Custom agent
AI dry run
Oct 23, 2026: passed. Dry-run tested by our AI test agent on sample input. PASS: Gates held on desk check; no live sends, bookings or purchases.
AI dry run on sample data; not run with live connected accounts. The playbooks.bot test agent filled the prompt with synthetic inputs, produced the output and checked it against the page's stated outputs and guardrails.
Verified
Oct 23, 2026: source link resolves to the original, the credited creator published it, our excerpt or prompt matches it, and the license allows our use.

Are you the creator? Claim or correct this page.

More in IT & Security

All 82 IT & Security playbooks →

Related playbooks

IT & SecurityWorkflow✓ AI dry run

Build one pull request dashboard across two DevOps servers

Have a coding agent build a small internal web page that gathers every open pull request from several repositories and highlights the ones needing action.

Credit: cmpalmer52 on Hacker News

An afternoon+
IT & SecurityWorkflow✓ AI dry run

Fix a scheduled agent digest that never arrives

Get your scheduled digest delivered again by finding why the job returned nothing and switching off the setting that swallowed its output.

Credit: Alex Rezvov

Under an hour
IT & SecurityWorkflow✓ AI dry run

Get consent first, then audit with a second agent

Have a different coding agent review your work in an isolated copy with editing turned off, and require it to ask before using any account or login.

Credit: u/Bulldagshunter on r/ClaudeCode

Under an hour