Methodology behind the performance claims in README.
The end-to-end time from the AI client invoking the hook subprocess to pinrule emitting its hook output JSON. Includes:
- Python interpreter cold start (largest single factor — Python 3.11/3.12)
pinrulepackage import + rule loading from~/.pinrule/rules.json- Hook handler dispatch
- Engine check + state update + stdout write
python scripts/measure_perf.pyOutputs per-hook median + p95 latency across 100 runs.
Latency varies by machine:
- Apple M-series Mac: ~49ms median
- Lower-end Linux box (reported by community): ~67ms
- Older Intel Mac: ~80-100ms
The protocol budget is 200ms; pinrule sits well under that on every machine measured so far.
The fraction of total conversation tokens (input + output) that pinrule injects into the model's context per turn. This includes:
SessionStarthook: full rule baseline injected once per session (~1.8K tokens for the default 7-rule template, one-time cost)UserPromptSubmithook: per-turn compact anchor (~490 tokens average, often 0 tokens when no rule drifted in the previous response — see "0-anchor passthrough" below)PostToolUsehook: full reinject on long-context decay, fires only when accumulated context hits the model's decay threshold (Opus 60K / Sonnet 40K / Haiku 30K)
The 2% is (pinrule injected tokens) / (total conversation tokens) averaged across 30 real work sessions during pinrule's own development.
- 60% of sessions: 0 anchor tokens — no rule drifted in any response, so per-turn anchor is empty (just the
[pinrule reminder]header line) - Median session: 1 rule listed in anchor (~60 tokens)
- Worst-case session: 4 rules + drift markers (~280 tokens per turn)
The 0-anchor passthrough is what makes the average low — most working turns don't trigger any rule, so the per-turn cost is essentially zero. Only when the Agent actually drifts does the next turn's anchor list the drifted rule.
These figures come from the author's own dogfood during pinrule development — 30 working sessions over ~2 weeks, hand-counted from ~/.pinrule/session-state/*.json (each file records tool_byte_seq accumulation, drift events, reinject triggers) and Claude Code's conversation logs.
There is no pinrule audit --token-ratio helper yet — automating this is on the roadmap but no user has asked for it, so it stays manual. If you want to measure your own data, the inputs are:
~/.pinrule/session-state/<session_id>.json— per-session pinrule state (read/edit files, byte accumulation, reinject marks)- Your AI client's conversation log — authoritative source for total token count, since pinrule doesn't track that
If you measure your own ratio and want a reproducible script for it, file an Issue — that's the trigger to actually build the helper.
- Methodology is dogfood-internal, not a peer-reviewed benchmark. Numbers come from the author's own 30-session sample during development; user mileage will vary by:
- rule count (more rules → bigger baseline + bigger anchor when rules drift)
- drift rate (Agent drifts more often → bigger per-turn anchor)
- session length (longer session → more chance to hit decay threshold)
- No client-side overhead measurement yet — the AI client itself (Claude / Codex / Cursor / Hermes) adds latency for spawning the hook subprocess and reading its stdout; pinrule's
scripts/measure_perf.pymeasures pinrule's part only. - Token overhead doesn't include AI-client-side compression — if your client compresses long history before sending to the model, the actual prompt size is smaller than what pinrule injected.
If you measure your own pinrule session and the numbers diverge meaningfully from this doc, that's interesting — please share via Issue.