[FEATURE] Mods API: $.model.fork has no timeoutMs (or maxTokens), unlike $.model.complete

Status Open
Reported on v2.1.296
Maintainer reply None cached
Activity 0 comments · opened Oct 12, 2026

Preflight Checklist

  • [x] I have searched existing requests and this feature hasn't been requested yet
  • [x] This is a single feature request (not multiple features)

Problem Statement

In the mods API, $.model.complete lets a hook bound the call: ModelCompleteRequest has timeoutMs (documented as "how a hook bounds the completion itself, by the clock") and maxTokens. $.model.fork takes only { prompt } (ModelForkRequest), so a plugin cannot put an upper bound on a fork's duration or reply size.

Because a hook's budget does not count time spent awaiting $ calls, a hook that awaits a fork is held for as long as the fork runs. The natural place for a fork is turn.complete (e.g. "suggest next steps" or "write a handoff note when context passes N%"), since it needs the session's transcript and benefits from the prompt cache:

on('turn.complete', { reason: 'answer' }, async ($, e, next) => {
  const result = await next(e)
  const reply = await $.model.fork({ prompt: 'List up to 3 next steps as JSON' }) // no way to bound this
  // ...
  return result
})

The only abort today is the turn being interrupted (aborted), which the plugin does not control.

Proposed Solution

Add timeoutMs (and ideally maxTokens) to ModelForkRequest, resolving with the same aborted result $.model.complete uses when the time elapses:

await $.model.fork({ prompt, timeoutMs: 20_000, maxTokens: 400 })

Alternative Solutions

  • Accept an AbortSignal so a plugin can cancel a fork it started (e.g. from a $.clock.after timer).
  • What we do today: detach the fork with $.clock.after(0, async () => { ... }) so turn.complete returns immediately, and allow one fork at a time with a module-level flag. This avoids holding the dispatch but still cannot stop a fork that runs long or produces a long reply.

Priority

Medium - Would be very helpful

Feature Category

Developer tools/SDK

Use Case Example

  1. A mod suggests up to three next steps after each answer that used tools, via $.model.fork in turn.complete.
  2. A mod writes a handoff note via $.model.fork once context usage passes a threshold.
  3. Both want to give up after ~20 s and cap the reply at a few hundred tokens, as they already do for classification calls with $.model.complete({ timeoutMs, maxTokens }).

Additional Context

  • Claude Code 2.1.296 (type declarations written by 2.1.295), Windows 11, plugin installed at user scope.
  • Related (different problem, same API): #100083, #100699 — fork prompt-cache behavior.

View original on GitHub ↗