{"version":"2.1.269","anchor":"sandboxed-environment-worker-gains-streaming-dispatch","canonical_anchor":"turnstep-hooks-can-override-or-veto-the-model-per-request","heading":"Plugin hooks can now stream results as async generators","tier":"soon","area":"Sandbox","url":"https:\/\/changelogs.core-directive.com\/v\/2.1.269\/e\/sandboxed-environment-worker-gains-streaming-dispatch","release_url":"https:\/\/changelogs.core-directive.com\/v\/2.1.269","markdown":"### Plugin hooks can now stream results as async generators\n\nPlugin hooks can be written as async generators that stream chunks, with the first use letting a hook override the model per request\n\n**What**\n\n- Hooks can now be implemented as async generator functions (`async function*`) that yield a stream of chunks instead of returning one final value. Claude Code validates this: hooks registered on events designated as \"streaming\" events must be async generators, and hooks on non-streaming events must not be.\n\n- A full streaming dispatch pipeline was added end-to-end: the plugin host gained `dispatchStream`\/`linkStreams`\/`withinSteps` alongside the existing `dispatch`\/`link`\/`within`, the hooks-worker protocol gained matching frame types (`dispatch_stream`, `stream_pull`, `stream_step`, `next_pull`, `next_close`, `stream_close`), and the sandboxed tool\/environment worker gained its own `dispatch_stream`\/`stream_pull`\/`stream_close` messages backed by a `streams` map, so a dispatch can yield incremental results.\n\n- Currently only one event, `turn.step`, is enabled to use the streaming\/generator form. It reconstructs each model request\/response as discrete stream chunks and lets a registered plugin hook change which model a request uses. If a hook proposes a model that policy doesn't allow, Claude Code keeps the original model and logs a warning plus a hook-effect telemetry event.\n\n**Why** This lays the groundwork for hooks that need to see or influence a request incrementally rather than only before or after it completes; today that's used to let a plugin hook override or veto the model used for a turn, subject to policy.\n\n- Area: Sandbox\n- Tier: Nothing to try yet\n- Useful: 5\/5\n- Signal: 4\/5"}