-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpost-tool-batch.sh
More file actions
executable file
·28 lines (23 loc) · 1.09 KB
/
Copy pathpost-tool-batch.sh
File metadata and controls
executable file
·28 lines (23 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env bash
# PostToolBatch hook: observability for parallel tool batches.
# Logs batch size and tool names. If the batch included Edit/Write, emits a
# reminder via systemMessage so the next turn re-checks lint/format rules.
set -euo pipefail
input_json="$(cat)"
timestamp="$(date +'%Y-%m-%d %H:%M:%S')"
# Extract tool names if present; schema may vary, so be defensive.
tool_names="$(printf '%s' "$input_json" | jq -r '
(.tool_calls // .batch // .tools // [])
| map(.tool_name // .name // "?")
| join(",")
' 2>/dev/null || echo '?')"
batch_size="$(printf '%s' "$input_json" | jq -r '
(.tool_calls // .batch // .tools // []) | length
' 2>/dev/null || echo 0)"
mkdir -p ~/.claude/logs
echo "[$timestamp] batch_size=$batch_size tools=$tool_names" >> ~/.claude/logs/tool-batches.log
# If the batch touched files, nudge the model to re-verify lint/format conventions.
if [[ "$tool_names" == *Edit* || "$tool_names" == *Write* ]]; then
jq -n --arg msg "Batch of $batch_size tools included Edit/Write. Re-check: linter passes, trailing blank line, English comments." \
'{systemMessage: $msg}'
fi