MCP containers (github-mcp-server) not cleaned up after session ends

Resolved 💬 3 comments Opened Jan 5, 2026 by alkari Closed Jan 9, 2026

Description

Claude Code spawns ghcr.io/github/github-mcp-server Docker containers for MCP GitHub integration, but these containers are not cleaned up when:

  • Sessions end normally
  • Context is exhausted and sessions restart
  • User disconnects

Environment

  • Claude Code version: Latest (via VSCode extension)
  • Platform: Linux (Ubuntu on DGX)
  • Docker version: 27.x

Steps to Reproduce

  1. Use Claude Code with GitHub MCP integration enabled
  2. End the session (or let context exhaust)
  3. Start a new session
  4. Run: docker ps --filter ancestor=ghcr.io/github/github-mcp-server

Expected Behavior

MCP containers should be stopped and removed when the Claude Code session that spawned them ends.

Actual Behavior

Containers accumulate indefinitely. After 5 days of usage, I found 24 orphaned containers:

CONTAINER ID   NAMES                 STATUS       CREATED AT
6ecb8907b9c6   pedantic_elgamal      Up 6 hours   2026-01-05 08:40:18
7fc584aa9a86   brave_jepsen          Up 6 hours   2026-01-05 08:40:16
75647a32cb8f   focused_hellman       Up 2 days    2026-01-03 01:14:44
... (21 more containers dating back to 2025-12-30)

All containers showed:

  • 0% CPU usage
  • ~6MB RAM each
  • 0 active network connections

Verification

Confirmed no sessions were using these containers:

# All containers had 0 active connections
for name in $(docker ps --filter ancestor=ghcr.io/github/github-mcp-server --format "{{.Names}}"); do
  docker exec "$name" ss -tnp 2>/dev/null | grep -c ESTAB
done
# Output: 0 for all 24 containers

Workaround

Manual cleanup:

docker stop $(docker ps -q --filter ancestor=ghcr.io/github/github-mcp-server)
docker rm $(docker ps -aq --filter ancestor=ghcr.io/github/github-mcp-server)

Impact

  • Memory waste (~6MB per container, 144MB for 24 containers)
  • Docker resource exhaustion over time
  • Potential port conflicts if containers bind to host ports

Suggested Fix

Claude Code should register a cleanup hook to stop/remove MCP containers when:

  1. Session ends (normal exit)
  2. Context is exhausted (before restart)
  3. Connection is lost (timeout-based cleanup)

Alternatively, containers could be started with --rm flag so they auto-remove on stop.

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗