MCP plugin disconnects when context is compacted (/compact)
Description
The Telegram MCP plugin (and likely other stdio-based MCP plugins) disconnects every time context compaction occurs — either manually via /compact or automatically when approaching context limits.
Steps to Reproduce
- Start Claude Code with the Telegram channel plugin:
claude --channels plugin:telegram@claude-plugins-official - Use the Telegram MCP tools normally (reply, react, etc.)
- Trigger context compaction via
/compactor let it happen automatically - After compaction, the MCP tools become unavailable with "MCP server disconnected"
Root Cause Analysis
The plugin server uses StdioServerTransport (stdin/stdout). When Claude Code compacts context, the stdin pipe is closed/reset, triggering the shutdown handler:
process.stdin.on("end", shutdown)
process.stdin.on("close", shutdown)
The shutdown() function then kills the bot process and exits. This is intentional for zombie prevention, but it causes the plugin to die during normal context management operations.
Expected Behavior
MCP plugin connections should survive context compaction. The plugin process should remain alive and reconnect after compaction completes.
Actual Behavior
Every /compact or automatic context compression kills the MCP connection. The plugin process terminates. Users must restart Claude Code to restore the connection.
Impact
- In long conversations, context compaction is frequent — the plugin disconnects multiple times per session
- Users lose the ability to send/receive Telegram messages mid-conversation
- The only workaround is restarting Claude Code entirely
Environment
- Claude Code: latest (installed via npm)
- OS: Linux (WSL2)
- Plugin:
plugin:telegram@claude-plugins-officialv0.0.5 - MCP SDK:
@modelcontextprotocol/sdk^1.0.0
Suggested Fix
Either:
- Preserve stdio pipes across context compaction (do not close/reopen MCP connections)
- Automatically reconnect MCP plugins after compaction
- Provide a mechanism for plugins to distinguish compaction reset from session ended
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗