claude-code - 💡(How to fix) Fix PreToolUse hooks lack parallel tool call grouping context

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

We build Empirica, an epistemic measurement framework that uses PreToolUse hooks for tool classification (noetic/read-only vs praxic/write). The lack of parallel batch context means our sentinel hook evaluates each call independently, which works but loses the signal that parallel calls represent a single logical action.

This is a minor enhancement request — the current behavior is functional, just information-limited.

Root Cause

We build Empirica, an epistemic measurement framework that uses PreToolUse hooks for tool classification (noetic/read-only vs praxic/write). The lack of parallel batch context means our sentinel hook evaluates each call independently, which works but loses the signal that parallel calls represent a single logical action.

This is a minor enhancement request — the current behavior is functional, just information-limited.

Code Example

{
  "toolName": "Read",
  "toolInput": { "file_path": "/src/main.py" },
  "parallelBatch": {
    "batchId": "batch_abc123",
    "batchSize": 3,
    "batchIndex": 0,
    "siblingTools": ["Read", "Read", "Grep"]
  }
}

---

{
  "toolName": "Read",
  "toolInput": { "file_path": "/src/main.py" },
  "batchSize": 3,
  "batchIndex": 0
}
RAW_BUFFERClick to expand / collapse

Problem

When Claude Code sends multiple tool calls in a single message (parallel tool calls), each PreToolUse hook fires as an independent subprocess invocation. The hook receives no information about whether the current tool call is part of a parallel batch, how many other calls are in the batch, or what those other calls are.

Impact

Hooks that maintain state or make gating decisions based on tool call patterns cannot distinguish between:

  • 3 parallel Read calls (a single investigation action)
  • 3 sequential Read calls over time (potentially different intent)

This matters for:

  • Rate limiting / nudging — a hook counting tool calls to suggest checkpoints sees 3 calls when the user's intent was 1 action
  • Permission gating — a hook that gates praxic tools can't assess whether a parallel batch is coherent (e.g., Read + Read + Edit — the reads are noetic, the edit is praxic, but they're one logical action)
  • Audit logging — hooks recording tool usage patterns get fragmented data

Proposed Solution

Include parallel batch context in the hook input:

{
  "toolName": "Read",
  "toolInput": { "file_path": "/src/main.py" },
  "parallelBatch": {
    "batchId": "batch_abc123",
    "batchSize": 3,
    "batchIndex": 0,
    "siblingTools": ["Read", "Read", "Grep"]
  }
}

Alternatively, a simpler approach — just batchSize and batchIndex:

{
  "toolName": "Read",
  "toolInput": { "file_path": "/src/main.py" },
  "batchSize": 3,
  "batchIndex": 0
}

batchSize: 1 (or field absent) means sequential/single call. batchSize > 1 means this is part of a parallel batch.

Context

We build Empirica, an epistemic measurement framework that uses PreToolUse hooks for tool classification (noetic/read-only vs praxic/write). The lack of parallel batch context means our sentinel hook evaluates each call independently, which works but loses the signal that parallel calls represent a single logical action.

This is a minor enhancement request — the current behavior is functional, just information-limited.

extent analysis

TL;DR

Include parallel batch context in the PreToolUse hook input to enable hooks to distinguish between parallel and sequential tool calls.

Guidance

  • Modify the PreToolUse hook input to include parallelBatch context, such as batchSize and batchIndex, to provide information about parallel tool calls.
  • Update hooks that maintain state or make gating decisions to utilize the new parallelBatch context, allowing them to correctly handle parallel tool calls.
  • Consider implementing a fallback or default behavior for cases where batchSize is 1 or the field is absent, indicating a sequential or single tool call.
  • Review and update audit logging to account for the new parallel batch context, ensuring accurate recording of tool usage patterns.

Example

{
  "toolName": "Read",
  "toolInput": { "file_path": "/src/main.py" },
  "batchSize": 3,
  "batchIndex": 0
}

Notes

The proposed solution requires modifications to the PreToolUse hook input and updates to existing hooks. The exact implementation details may vary depending on the specific requirements and constraints of the Empirica framework.

Recommendation

Apply the workaround by including parallel batch context in the PreToolUse hook input, as this will provide the necessary information for hooks to correctly handle parallel tool calls and improve the overall functionality of the Empirica framework.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix PreToolUse hooks lack parallel tool call grouping context