Skip to content

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

Closed as duplicate

Description

@alkari

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.

Activity

  1. github-actions commented on Jan 5, 2026

    @github-actions

    Found 3 possible duplicate issues:

    1. [BUG] MCP servers not properly terminated when Claude Code exits, causing orphaned processes #1935
    2. [BUG] claude mcp list causes orphaned mcp server processes #11778
    3. Windows: MCP server child processes not cleaned up on exit/crash #15211

    This issue will be automatically closed as a duplicate in 3 days.

    • If your issue is a duplicate, please close it and 👍 the existing issue instead
    • To prevent auto-closure, add a comment or 👎 this comment

    🤖 Generated with Claude Code

  2. added
    duplicateThis issue or pull request already exists
    and removed
    bugSomething isn't working
    has reproHas detailed reproduction steps
    platform:linuxIssue specifically occurs on Linux
    on Jan 9, 2026
  3. github-actions commented on Jan 9, 2026

    @github-actions

    This issue has been automatically closed as a duplicate of #1935.

    If this is incorrect, please re-open this issue or create a new one.

    🤖 Generated with Claude Code

  4. github-actions commented on Jan 18, 2026

    @github-actions

    This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.

  5. locked as resolved and limited conversation to collaborators on Jan 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    duplicateThis issue or pull request already exists

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions