fix: allow opt-out of session_state_changed via env var#498
Open
vincentye38 wants to merge 1 commit intoagentclientprotocol:mainfrom
Open
fix: allow opt-out of session_state_changed via env var#498vincentye38 wants to merge 1 commit intoagentclientprotocol:mainfrom
vincentye38 wants to merge 1 commit intoagentclientprotocol:mainfrom
Conversation
When CLAUDE_CODE_EMIT_SESSION_STATE_EVENTS=0 is set in the environment, return the PromptResponse directly from the result message handler instead of waiting for session_state_changed(idle) which will never arrive. This provides a deterministic fallback for Claude Code binaries that do not support session state events. The env var defaults to "1" (enabled) to preserve existing behavior. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
|
Do we want to support different versions of Claude Code or should we instead document that you need a minimum version? Especially because this seems to fix the problem only by explicitly setting an env var, which I assume has low discovery? |
Author
|
CLAUDE_CODE_EMIT_SESSION_STATE_EVENTS Is introduced in v2.1.83. The default is set to 0. IMO, We should maintain this acp agent downward compatible with 0 while supporting 1 until Claude Code SDK changes default setting to 1. |
Author
|
@benbrandt Could you take a look at this PR. Thank you! |
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
CLAUDE_CODE_EMIT_SESSION_STATE_EVENTS=0is set in the environment, the prompt loop returns thePromptResponsedirectly from theresultmessage handler instead of waiting forsession_state_changed(idle)which will never arrive on older Claude Code binaries"1"(enabled) to preserve existing behavior"1", allowing deterministic opt-outChanges
Session.useSessionStateEvents— new boolean flag on the session, derived from the env var at session creationcreateSessionenv override —CLAUDE_CODE_EMIT_SESSION_STATE_EVENTSnow respectsprocess.envinstead of always hardcoding"1"useSessionStateEventsisfalseTest plan
CLAUDE_CODE_EMIT_SESSION_STATE_EVENTSunset (default): behavior unchanged, waits forsession_state_changed(idle)CLAUDE_CODE_EMIT_SESSION_STATE_EVENTS=0: prompt returns immediately afterresult(success), no hang0: client receivesPromptResponseand does not deadlock