Commit 6c02272
authored
v0.40.0: capture task telemetry via SubagentStop (confirmed root cause) (#38)
Resolves the multi-release "0 task events" mystery with a clean,
in-session empirical proof — not another guess.
The proof (run this session, fresh 0.39.3, async already reverted):
1. Captured a cutoff timestamp.
2. Dispatched a real subagent via the Agent tool (32947 tokens,
returned). Result: ZERO events after cutoff.
3. In the SAME session, triggered a Read-deny on a large file.
Result: exactly 1 `denied` event written after its cutoff.
4. An unbounded recursive search was blocked by hook-pre-bash
(hooks demonstrably live this session).
So: appendEvent + the hook runtime are healthy (Read-deny wrote),
but PostToolUse:Task produces nothing on a real dispatch. That is
the entire "0 task events" history explained — the parent-side
PostToolUse hook simply does not fire for the dispatch tool on this
Claude Code. async (v0.35.0) was never the cause; the April zeros
predate it. Releases v0.33.1 / v0.39.2 chased the wrong layer.
The fix — SubagentStop:
Claude Code's SubagentStop is the canonical subagent-completion
event (bundle schema: agent_id, agent_type, agent_transcript_path,
last_assistant_message). It fires once per subagent by definition.
New hook-subagent-stop writes the `event:"task"` record from it:
- subagent_type = agent_type (the adoption signal v0.30 needs:
was a subagent used, tp-* or not)
- estTokens = best-effort sum from the transcript usage
(agent_transcript_path), 0 on any failure
- code:"subagent_stop" marks the source so a future revival of
PostToolUse:Task can be deduped, not double-counted
Routing-miss detection (general-purpose where tp-* fit) stays in
the PreToolUse:Task diagnostic, which has the task description
SubagentStop lacks.
Wiring:
- src/hooks/subagent-stop.ts — buildSubagentTaskEvent +
tokensFromTranscript (both pure / injectable, fully tested).
- index.ts case hook-subagent-stop (synchronous — writes telemetry).
- hooks/hooks.json + installer.ts: SubagentStop section, installed
+ uninstalled idempotently alongside the others.
- typo-guard registers hook-subagent-stop.
Verified end-to-end against the built dist: a SubagentStop payload
for tp-pr-reviewer writes event:"task" subagent_type=tp-pr-reviewer
code=subagent_stop.
PostToolUse:Task is KEPT (harmless; carries tokens if CC ever fixes
it; code-marked events let stats dedup).
Tests: 1328/1328 pass (+9 subagent-stop + typo-guard).1 parent 9cbc089 commit 6c02272
35 files changed
Lines changed: 330 additions & 34 deletions
File tree
- .claude-plugin
- agents
- hooks
- src
- cli
- hooks
- tests
- cli
- hooks
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| |||
0 commit comments