Claude Code executes its own tools internally in --print mode -- there
is no way for a caller to externally dispatch individual tool calls
without abandoning that self-contained agent model. What
--output-format stream-json --include-hook-events does allow: observing
each tool_use/tool_result/hook event in real time.
- adapter.py: AgenticClaudeCodeAdapter gains an optional on_tool_event
callback; streaming mode (Popen + background reader thread) is used
only when set, blocking subprocess.run path is unchanged otherwise.
- runner.py: run_task gains emit_tool_events/on_tool_event, collecting
events onto RunResult.tool_events and posting a tool_call hub event
per tool when reporting is enabled.
- cli.py: --stream-tool-events flag on `run`, prints each event as a
tagged JSON line ahead of the unchanged final result block.
Live-verified against the real claude CLI: 5 real tool events streamed
correctly (2x Bash, 1x Write) plus Stop hook lifecycle events, real
commit landed, final result block unchanged. 13 new tests
(test_adapter.py + 2 in test_runner.py), all passing.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>