Skip to content

Print task ID on Ctrl+C interrupt for async tool calls#177

Open
jancurn wants to merge 4 commits intomainfrom
claude/update-tools-call-help-0MSlE
Open

Print task ID on Ctrl+C interrupt for async tool calls#177
jancurn wants to merge 4 commits intomainfrom
claude/update-tools-call-help-0MSlE

Conversation

@jancurn
Copy link
Copy Markdown
Member

@jancurn jancurn commented Apr 16, 2026

Summary

Enhanced the tools-call --task command to provide better user experience when interrupting long-running async tasks. When a user presses Ctrl+C during task execution, the CLI now prints the task ID and helpful recovery commands instead of silently terminating.

Key Changes

  • Added SIGINT handler to callTool() that captures and displays the task ID when interrupted in human mode
  • Prints recovery commands (tasks-result and tasks-cancel) to help users manage interrupted tasks
  • Updated --task option description to clarify Ctrl+C behavior
  • Added comprehensive documentation in the help text explaining async task behavior and the difference between --task and --detach
  • Properly cleans up event listeners and timers in the SIGINT handler

Implementation Details

  • The SIGINT handler only displays task information in human output mode, keeping JSON output clean
  • Handler is registered before task execution and properly deregistered in the finally block to prevent memory leaks
  • Spinner and timer are stopped before printing the interrupt message for clean output
  • Help text now includes a dedicated "Async tasks" section explaining --task vs --detach behavior

https://claude.ai/code/session_01DMuLoe25t4Fwjyun36nRFx

claude added 4 commits April 16, 2026 10:43
When `tools-call --task` is interrupted with Ctrl+C and a task ID has
been captured, print recovery commands to stderr so the user can fetch
or cancel the server-side task. Silent in --json mode.

Also updates --task flag help text, adds an "Async tasks" section to the
tools-call help footer, and documents that --json --detach returns a
CreateTaskResult instead of CallToolResult.

Closes #169

https://claude.ai/code/session_01DMuLoe25t4Fwjyun36nRFx
Extract a shared `printDetachedHint()` helper so both ESC-detach and
Ctrl+C interrupt produce identical output with tasks-result and
tasks-cancel recovery commands.

https://claude.ai/code/session_01DMuLoe25t4Fwjyun36nRFx
Extract formatTaskCommandsHint() to output.ts and use it everywhere:
tools-call --detach, tools-call --task ESC/Ctrl+C, tasks-list, and
tasks-get. All now show the same "Available commands" block.

https://claude.ai/code/session_01DMuLoe25t4Fwjyun36nRFx
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.

3 participants