Skip to content

Conversation

@Dave-London
Copy link
Contributor

Summary

Fixes #865

When the Claude Code action completes, spawned MCP server processes (started by the CLI via --mcp-config) are not terminated, causing the GitHub Actions workflow to hang indefinitely until timeout or manual cancellation.

Root cause: The query() function returns a Query object that extends AsyncGenerator and has a close() method documented as:

"Close the query and terminate the underlying process. This forcefully ends the query, cleaning up all resources including pending requests, MCP transports, and the CLI subprocess."

The current code iterates the query with for await but never calls close(). When the async generator completes naturally, the underlying CLI process and its child MCP servers (which use StdioServerTransport and block on stdin forever) are not terminated, keeping the Node.js event loop alive.

Fix: Store the Query object reference and call close() in a finally block after consuming the async generator.

Test plan

  • TypeScript type check passes
  • Prettier format passes
  • All tests pass (631 pass, 20 pre-existing failures on main)

🤖 Generated with Claude Code

… workflow hang

Store the Query object reference and call close() in a finally block
after the for-await loop completes. Without this, child processes
spawned by the CLI (e.g., MCP servers using StdioServerTransport) keep
the Node.js event loop alive, causing the GitHub Actions workflow to
hang indefinitely until timeout.

Fixes anthropics#865

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MCP servers not terminated after Claude completes - workflow hangs indefinitely

1 participant