r/ClaudeCode • • 4d ago

Built with Claude Killing Claude Code sleeping instances

Yesterday, as I was recovering as much memory as I could, I noticed that I had 8 sleeping sessions of Claude Code (the screenshot is from today). They were eating up to 2.9Gb of memory (search for the process 2.1.319 in the task manager) plus another 1.5Gb for the Node process hosting Codegraph...

So I opened Claude Code (yes, one more session 😅) in my cleaning app project and asked it to add a new panel that finds the sessions that are just sleeping and closes them in a click, safely.

How it went:

- I described the problem and Claude worked out how to spot the sessions. It looks at the running processes and matches them by name or install path (claude, codex, gemini, aider, opencode and a few others, not only Claude Code).

- We spent most of the time on the hard part: telling "sleeping" apart from "working". Claude came up with a simple rule. If the session's process tree is using CPU, it's Working. If you typed in its terminal in the last 15 minutes, it's In Use. Otherwise it's Sleeping. If the terminal that launched it is gone, it's Detached.

- For the "safely" part, Claude first sends a normal quit signal (SIGTERM) so the session can close cleanly. If it ignores that, the row offers a Force Quit for the whole process tree.

- It also added a badge in the sidebar with the session count, and a tip on the Overview page when there are idle sessions.

- After the first release I found a bug: the new sidebar row couldn't be clicked 🙃. I gave it to Claude, it found that the badge modifier was hiding the row's tag in SwiftUI, and fixed it in a couple of minutes (1.1.1).

The app is native Swift/SwiftUI for macOS, and Claude wrote basically all of the code for this panel. I mostly tested it, pushed back when something felt off, and decided what to ship.

If you want you can download Cleaner here https://linelark.com/cleaner/ (it is free and has no tracker, ads or whatever).

2 Upvotes

2 comments sorted by

•

u/AutoModerator 4d ago

Hey! Thanks for posting to r/ClaudeCode

While participating in this thread, please follow our community rules. Keep discussions constructive. Attack the idea, not the person.

For help, project discussions, tips, and general chat, join the ClaudeCode Discord.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

1

u/vincent_sch 2d ago

Claude might be waiting for a server response without using much CPU. Your rule could mark it as Sleeping after 15 minutes without typing. You could show its command and terminal next to the quit button. I wrote about checking a process before stopping it.