Conversation
Post-hooks receive the run's aggregated usage in their environment: CONVOY_RUN_COST (executor plus advisor), CONVOY_RUN_ADVISOR_COST, CONVOY_RUN_TOKENS_* and CONVOY_RUN_DURATION_MS, summed from the metadata the runner already holds, on success and on failure. Each variable appears only when a phase recorded that fact; nothing is reported as zero. The README documents the formats with a PR-comment hook and an awk budget guard. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BG8wiaLWbUzGXBm3rtzN41
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FUdVGWR9FvgD11kEsuS1U4
dagoaie
force-pushed
the
feat/hook-run-usage-pr
branch
2 times, most recently
from
September 14, 2026 11:36
852d3f5 to
5bad914
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Post-hooks are the place to notify, gate or comment on a run, but they only got the run's status and ID — not what the run cost. A hook that wants to leave the cost on a PR or refuse to continue past a budget had to re-parse
metadata.jsonitself. The runner already holds every phase's usage; this exposes the aggregate.Summary
src/usage.ts:sumRunUsagefolds the recorded phases into aRunUsage— cost (executor plus advisor), advisor cost on its own, summed executor tokens and summed phase durations. Each field is present only when a phase recorded that fact; absent facts are never reported as zero.src/metadata.ts:runUsage()on the metadata store, built from the in-memory phases so the hook sees the same numbersconvoy runswill show.src/hooks.ts: post-hooks receiveCONVOY_RUN_COST,CONVOY_RUN_ADVISOR_COST(4 decimals, USD),CONVOY_RUN_TOKENS_{INPUT,OUTPUT,CACHE_READ,CACHE_WRITE,REASONING,TOTAL}andCONVOY_RUN_DURATION_MS, on success and on failure. InheritedCONVOY_RUN_*usage variables are stripped from the hook's environment so a stale parent value can't leak in.src/runner.ts: passes the usage snapshot to the post-hooks on both exit paths (+4 lines).README.md: documents the variables with a PR-comment hook and anawkbudget guard.hook-run-usagearchived with its spec.Verification
bun run typecheck,bun test(3203 pass), coverage 92.4 % lines / 93.0 % functions.openspec validate hook-run-usage --strict.env | grep '^CONVOY_RUN_': cost and token counts match the run'smetadata.json, duration equals the recorded phase durations,CONVOY_RUN_ADVISOR_COSTabsent when no advisor ran.CONVOY_RUN_COST) fixed and covered by a unit test.🤖 Generated with Claude Code
https://claude.ai/code/session_01BG8wiaLWbUzGXBm3rtzN41