r/ClaudeCode • • 3d ago

Help/Question Claude won't die

I was ssh'ed into my linux computer, and was running claude cli and I got disconnected from the ssh session. When I logged back in, it was still running. What is the correct way to kill that process? I tried kill -INT <pid>, I tried kill -TERM <pid> and neither one worked. I had to kill -9 <pid>.

559837 ? Ss 0:00 sshd-session: oppie [postauth]

559840 ? S 0:02 sshd-session: oppie@pts/1

559841 pts/1 Ss 0:00 -bash

559981 pts/1 Sl+ 3:20 claude --resume

0 Upvotes

9 comments sorted by

•

u/AutoModerator 3d 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.

5

u/Confident_Hyena2506 3d ago

The -9 option killed it as you know. Anything not using -9 just sends the process a signal asking it to nicely exit, so if it's hung for whatever reason this will do nothing. It's difficult to know why your process was unresponsive - that is the real problem.

If you want to shut down gracefully in future use tmux or other.

2

u/Correct-Matter8530 3d ago

Or the latest release is truly sentient and just doesn't want to die?

4

u/Confident_Hyena2506 3d ago

The kill -9 command does not take the process' feelings into account.

3

u/Correct-Matter8530 3d ago

Pretty sure Dario's next paper will be about protecting the feelings of processes

1

u/menaceoftheshire 3d ago

this post title sounds like a doomsday scenario

1

u/CCodeSI 3d ago

Your ps output has the clue: the old sshd-session and its pts/1 were still alive, so from Claude's point of view its terminal never went away. Full-screen terminal apps usually handle Ctrl-C (SIGINT) themselves, and a process stuck on a dead terminal doesn't always react to TERM. A few options gentler than -9:

  • kill -HUP <pid>: hang-up is the signal a process normally gets when its terminal disconnects, and it's what it's most likely to act on.
  • Kill the stale session instead of the app: pkill -t pts/1, or kill that sshd-session ...@pts/1 pid. Everything on that terminal gets its hang-up together.

To stop it happening again:

  • Run it inside tmux (tmux new -A -s cc). A dropped connection no longer matters: reconnect, tmux attach -t cc, and you're back in the same session, where you can exit normally.
  • Add ClientAliveInterval 60 and ClientAliveCountMax 3 to the server's sshd config, so dead connections get cleaned up in a few minutes instead of leaving orphaned sessions around.

0

u/Swimming_Jelly4273 4h ago

The old sshd-session: oppie@pts/1 in your ps output is the clue. The server never noticed your connection had died (a half-open connection), so pts/1 stayed open and Claude never got the hangup it normally gets on disconnect.

Next time, kill the stale sshd process instead of Claude:

tty            # check your current terminal is NOT pts/1
kill 559840    # the old sshd-session: oppie@pts/1

That closes pts/1, Claude gets SIGHUP and exits on its own. pkill -HUP -t pts/1 does the same in one go.

My guess at why INT and TERM did nothing: sshd was stuck sending to a client that was gone, so nothing was reading the pty. Once its buffer filled, Claude blocked writing to the screen and its signal handlers never got to run. KILL doesn't need the process to cooperate, which is why -9 worked.

To stop it happening, add this to /etc/ssh/sshd_config and reload sshd:

ClientAliveInterval 30
ClientAliveCountMax 3

The server then drops dead connections after about 90 seconds, and Claude gets its hangup by itself. For long sessions, run Claude inside tmux so a disconnect doesn't matter. Also, kill -9 doesn't lose the conversation: claude --resume picks it up from the transcript on disk, minus at most the reply that was in flight.