Protect Your Claude Code Sessions from Accidental Termination
Multi-layered defense against killing all Node.js processes
English • 繁體中文 • Installation • Features
Ever accidentally killed ALL Node.js processes with this command?
taskkill /F /IM node.exe # Windows
pkill node # Linux/Mac💥 What actually happens:
- ❌ Claude Code terminates → Your entire session is lost
- ❌ Development servers die → All your running apps crash
- ❌ Background tasks killed → Build processes, watchers, everything
- ❌ Work interrupted → Have to restart everything from scratch
You just wanted to kill ONE stubborn server on port 3000. Instead, you nuked your entire Node.js ecosystem.
SaveClaudeNode provides two-layer protection:
|
PreToolUse Hook Blocks dangerous commands before they execute inside Claude Code Effectiveness: ~95% |
Guardian Daemon Monitors all Node.js processes and logs termination events Effectiveness: 100% logging |
|
|
|
|
Install PreToolUse Hook only (blocks 95% of accidental kills):
|
PowerShell: git clone https://github.com/Jeffrey0117/saveclaudenode.git
cd saveclaudenode
.\install-hook.ps1 |
Command Prompt: git clone https://github.com/Jeffrey0117/saveclaudenode.git
cd saveclaudenode
install-hook.bat |
Restart Claude Code → ✅ Protected!
For full protection with monitoring:
1. Install Rust:
winget install Rustlang.Rustup2. Build Guardian:
git clone https://github.com/Jeffrey0117/saveclaudenode.git
cd saveclaudenode
cargo build --release3. Install Hook:
.\install-hook.ps14. Run Guardian:
# Visible window
.\start-guard.bat
# Background (recommended)
.\start-guard-silent.vbsAfter installation, try this command in Claude Code:
taskkill /F /IM node.exeExpected Output:
⛔ 禁止無差別殺 node.exe!這會把 Claude Code 也殺掉!
請使用 /kill <端口號> 來精確殺掉特定端口的進程。
✅ Hook is working!
════════════════════════════════════════════════
SaveClaudeNode - Node.js Process Guardian
════════════════════════════════════════════════
[2026-01-28 07:30:15] 🚀 SaveClaudeNode guardian started
[2026-01-28 07:30:15] 📁 Log file: saveclaudenode.log
[2026-01-28 07:30:15] ⏱️ Scan interval: 500ms
守護程式已啟動!
- Monitoring all node.exe and electron.exe processes
- Auto-detecting Claude Code processes
- Log file: saveclaudenode.log
[2026-01-28 07:30:16] 🛡️ Protected Claude Code process: PID 12345
[2026-01-28 07:35:22] ⚠️ ALERT: Protected process PID 12345 was TERMINATED!
graph TB
A[User Types Command] --> B{Inside Claude Code?}
B -->|Yes| C[PreToolUse Hook]
C --> D{Dangerous Command?}
D -->|Yes| E[❌ BLOCKED]
D -->|No| F[✅ Execute]
B -->|No| G[External Command]
G --> H[Guardian Daemon]
H --> I{Claude Code Killed?}
I -->|Yes| J[⚠️ Log Alert]
I -->|No| K[Continue Monitoring]
| Layer | Tool | What It Blocks | Effectiveness | Limitation |
|---|---|---|---|---|
| 1 | PreToolUse Hook | taskkill /IM node.exepkill nodeStop-Process -Name node |
~95% | Only works inside Claude Code |
| 2 | Guardian Daemon | N/A - Monitoring only | 100% logging | Cannot prevent termination |
The hook detects and blocks these patterns:
# Windows
taskkill /F /IM node.exe
taskkill //F //IM node.exe
taskkill /IM electron.exe
wmic process where name="node.exe" delete
# PowerShell
Stop-Process -Name node
Get-Process node | Stop-Process
# Unix-style (if running in WSL/Git Bash)
pkill node
killall node
kill -9 $(pidof node)saveclaudenode/
├── 🦀 src/
│ └── main.rs # Rust guardian daemon source
├── 🪝 hooks/
│ └── block-node-kill.js # Claude Code PreToolUse hook
├── 📦 target/release/
│ └── saveclaudenode.exe # Compiled binary (287KB)
├── 🔧 install-hook.ps1 # PowerShell hook installer
├── 🔧 install-hook.bat # Batch hook installer
├── ▶️ start-guard.bat # Start daemon (visible)
├── 🔇 start-guard-silent.vbs # Start daemon (background)
├── 📖 README.md # This file
├── 📖 INSTALL.md # Detailed installation guide
└── ⚖️ LICENSE # MIT License
Option 1: Startup Folder (Easiest)
- Press
Win + R - Type
shell:startup→ Enter - Copy
start-guard-silent.vbsto the opened folder - ✅ Guardian will start automatically on boot
Option 2: Task Scheduler (More Control)
$action = New-ScheduledTaskAction -Execute "C:\path\to\saveclaudenode.exe"
$trigger = New-ScheduledTaskTrigger -AtLogOn
Register-ScheduledTask -TaskName "SaveClaudeNode" -Action $action -Trigger $trigger -RunLevel Highest| Spec | Value |
|---|---|
| Language | Rust 🦀 |
| Dependencies | sysinfo, chrono, windows-rs |
| Binary Size | 287KB |
| CPU Usage | < 0.1% |
| Memory | ~2MB |
| Scan Interval | 500ms |
| Detection Method | Process diff + CLI pattern matching |
| Spec | Value |
|---|---|
| Language | JavaScript |
| Hook Type | PreToolUse (pre-execution) |
| Detection | Regex + keyword analysis |
| False Positives | Near zero |
| Performance Impact | < 1ms per command |
The guardian daemon can:
- ✅ Detect when Claude Code is killed
- ✅ Log all termination events with timestamps
- ✅ Track which processes were terminated
But it cannot:
- ❌ Prevent termination (would require kernel driver)
- ❌ Restart Claude Code automatically
- ❌ Recover lost session data
Why? Windows security model prevents user-space apps from blocking process termination. Only kernel-mode drivers can do this.
✅ Use both layers together:
- Hook blocks 95% of accidental kills inside Claude Code
- Guardian provides audit trail for external terminations
- Combined protection covers most scenarios
- Windows Service mode (run as system service)
- Desktop notifications on Claude Code termination
- Whitelist mechanism (allow specific PIDs)
- Process recovery (experimental auto-restart)
- Kernel driver version (true prevention)
- Linux/macOS support
- Cloud logging & analytics
- Multi-user session support
Want a feature? Open an issue!
Contributions are welcome! This project was born from frustration.
- 🐛 Report bugs - Open an issue
- 💡 Suggest features - Share your ideas
- 🔧 Submit PRs - Fix bugs or add features
- ⭐ Star the repo - Help others discover it
- 📢 Share - Tell your fellow Claude Code users
# Clone the repo
git clone https://github.com/Jeffrey0117/saveclaudenode.git
cd saveclaudenode
# Install Rust
winget install Rustlang.Rustup
# Build
cargo build --release
# Test
.\target\release\saveclaudenode.exeThis project is licensed under the MIT License - see the LICENSE file for details.
TL;DR: Free to use, modify, and distribute. Just keep the license notice.
Created by developers who got tired of accidentally killing their Claude Code sessions. 😅
Special thanks to:
- Everyone who's ever typed
taskkill /IM node.exein frustration - The Rust community for amazing system programming tools
- Claude Code team for making such an awesome tool worth protecting
- 🐛 Bug reports: GitHub Issues
- 💬 Questions: GitHub Discussions
- ⭐ Feature requests: GitHub Issues