fix: exit process when ACP connection closes#530
Merged
benbrandt merged 3 commits intoagentclientprotocol:mainfrom Apr 13, 2026
Merged
fix: exit process when ACP connection closes#530benbrandt merged 3 commits intoagentclientprotocol:mainfrom
benbrandt merged 3 commits intoagentclientprotocol:mainfrom
Conversation
In oneshot mode (e.g. via ACPX), the claude-agent-acp process does not exit after the client closes the stdin pipe. `process.stdin.resume()` keeps the Node.js event loop alive indefinitely, causing orphan process accumulation on the host. Root cause: `runAcp()` discards the `AgentSideConnection` instance, so nothing listens for connection closure to trigger `process.exit()`. Fix: return the connection from `runAcp()` and call `process.exit(0)` when `connection.closed` resolves (i.e. when stdin reaches EOF). Persistent sessions are unaffected — the client keeps stdin open, so `connection.closed` does not fire until the client explicitly disconnects. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
benbrandt
added a commit
that referenced
this pull request
Apr 13, 2026
Make cancellation a no-op for unknown sessions, close each session query during disposal, and run the same cleanup path on SIGINT and SIGTERM in CLI mode. Follow up to #530
benbrandt
added a commit
that referenced
this pull request
Apr 13, 2026
Make cancellation a no-op for unknown sessions, close each session query during disposal, and run the same cleanup path on SIGINT and SIGTERM in CLI mode. Follow up to #530
benbrandt
pushed a commit
that referenced
this pull request
Apr 13, 2026
🤖 I have created a release *beep* *boop* --- ## [0.27.0](v0.26.0...v0.27.0) (2026-04-13) ### Features * allow clients to opt into receiving raw SDK messages ([#527](#527)) ([403a668](403a668)) * Update to claude-agent-sdk 0.2.104 ([#537](#537)) ([6811943](6811943)) ### Bug Fixes * Allow auto mode after plan mode and send description for auto mode ([#528](#528)) ([fb9aced](fb9aced)) * Better remote check for auth methods ([#538](#538)) ([93f58c0](93f58c0)) * better shutdown logic ([#543](#543)) ([9fb631f](9fb631f)) * exit process when ACP connection closes ([#530](#530)) ([5c81e99](5c81e99)) * guard tool info rendering when tool_use input is undefined ([#536](#536)) ([d627b8c](d627b8c)) * Remove backup auth check from new session ([#544](#544)) ([32b16c1](32b16c1)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: acp-release-bot[bot] <246668977+acp-release-bot[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
AgentSideConnectionfromrunAcp()instead of discarding itconnection.closedand callprocess.exit(0)on resolutionProblem
When used in oneshot mode,
claude-agent-acpdoes not exit after the client closes the stdin pipe.process.stdin.resume()keeps the Node.js event loop alive indefinitely. Over time, orphan processes accumulate on the host (~97MB RSS each), eventually exhausting system resources.Root cause
runAcp()creates anAgentSideConnectionbut discards the reference. TheConnection.#receive()loop detects stdin EOF and firesabortController.abort(), resolvingconnection.closed— but no code listens for it to triggerprocess.exit().Fix
acp-agent.ts:runAcp()now returns theAgentSideConnectioninstanceindex.ts: Awaitsconnection.closedand callsprocess.exit(0)Impact
connection.closeddoes not fire until explicit disconnectTest plan
🤖 Generated with Claude Code