[BUG] Telegram plugin (bun server.ts) orphans on session exit, causing high CPU
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
Summary
Each Claude Code session spawns a new bun server.ts Telegram MCP plugin process
but does not kill the previous one when the session ends. On a server with multiple
daily sessions, these accumulate and saturate CPU.
## Environment
- OS: Ubuntu 24.04 (ARM64, Oracle Cloud)
- Claude Code version: 2.1.168
- Telegram plugin version: 0.0.6
## Root Cause
The orphan watchdog in server.ts (around line 670) checks:
```ts
process.ppid !== bootPpid
But when Claude Code exits, the direct parent (bun run --cwd ... start) does not
die — it gets reparented to init (PID 1). From server.ts's perspective, its own
ppid never changes, so the watchdog never fires and the process survives indefinitely.
What Should Happen?
At startup, record the grandparent PID (Claude Code itself) by reading
/proc/<ppid>/status. In the watchdog interval, check if bun run's parent has
changed (reparented to init = grandparent died):
function readParentPid(pid: number): number | null {
try {
const status = readFileSync(/proc/${pid}/status, 'utf8')
const m = status.match(/^PPid:\s+(\d+)/m)
return m ? parseInt(m[1], 10) : null
} catch {
return null
}
}
const bootGrandparentPid = process.platform === 'linux' ? readParentPid(bootPpid) : null
setInterval(() => {
let parentOrphaned = false
if (process.platform === 'linux' && bootGrandparentPid != null && bootGrandparentPid > 1) {
const gp = readParentPid(bootPpid)
parentOrphaned = gp === null || gp !== bootGrandparentPid
}
const orphaned =
(process.platform !== 'win32' && (process.ppid !== bootPpid || parentOrphaned)) ||
process.stdin.destroyed ||
process.stdin.readableEnded
if (orphaned) shutdown()
}, 5000).unref()
I have applied this fix locally and confirmed it resolves the issue.
Error Messages/Logs
Steps to Reproduce
## Steps to Reproduce
- Configure the Telegram plugin
- Start and close 3+ Claude Code sessions
- Run:
ps aux | grep 'bun server.ts' - Observe multiple zombie processes, each consuming 40-100% CPU
Claude Model
Sonnet (default)
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.1.168
Platform
Anthropic API
Operating System
Ubuntu/Debian Linux
Terminal/Shell
Other
Additional Information
_No response_
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗