Add ESC key listener to detach from async tool tasks#72
Merged
Conversation
When using --async for tool calls, users can now press ESC to detach from a running task. The task continues in the background and the task ID is printed, matching the behavior of --detach. The ESC hint is shown in the spinner after the task ID is received from the server. https://claude.ai/code/session_01X3RL2TuBha7jrzCZdmtkPJ
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
This PR adds the ability to detach from running async tool tasks by pressing the ESC key in human-readable output mode. When a task is running in the terminal, users can now press ESC to detach and let the task continue in the background, with the task ID displayed for later reference.
Key Changes
setupEscListener()function: Sets up a raw mode stdin listener that detects ESC key presses and returns a promise that resolves when ESC is pressed. Only activates in TTY mode and includes proper cleanup of stdin state.callTool()to race the task completion promise against the ESC listener promise, allowing early exit when ESC is pressed.Implementation Details
outputMode === 'human'and!process.stdin.isRawto prevent interference with interactive shellsPromise.race()to allow either task completion or ESC key press to resolve firsthttps://claude.ai/code/session_01X3RL2TuBha7jrzCZdmtkPJ