feat(hooks): integrate rtk upstream as external CLI for token reduction#2
Merged
Merged
Conversation
Add PreToolUse hook delegating eligible Bash commands to the upstream rtk binary (rtk-ai/rtk, v0.34.3) for 60-90% token reduction. RTK is treated as an optional external dependency (install via brew or cargo --git), invoked verbatim from the hook, never absorbed into the codebase. Hook degrades silently when rtk is missing. Documented: - ADR-032: install-not-absorb policy for standalone CLI tools, contrasted with ADR-027's absorb-not-install for Claude Code plugins - CLAUDE.md: install instructions with explicit warning against cargo install rtk (crate-name collision on crates.io with an unrelated Lua toolkit) - docs/diagrams: comparative architecture (9Router proxy MITM vs RuFlo in-process hook) plus the final RuFlo+RTK integration diagram - docs/plans/260511-gpoapa: retrospective PRD documenting the change Negative reference: 9router/open-sse/rtk/ reimplemented rtk in JS inside a MITM proxy (~1000 LOC owned, no upstream tests, degraded 20-40% claim). RuFlo invokes the upstream binary instead. Refs: 260511-gpoapa Co-Authored-By: claude-flow <ruv@ruv.net>
The RTK PreToolUse hook was originally added to .claude/hooks/ only, which is the local repo mirror — not the canonical source-of-truth. Per the repo pattern (scripts/init-arquetipo.sh:208, tests/*.sh, and scripts/gen-reference.sh:80), docs/arquetipo/deliverables/hooks/hooks/ is the canonical location that ships in the npm package and is copied to user projects on init. Changes: - Add canonical rtk-rewrite.sh under deliverables/hooks/hooks/ (identical to the .claude/hooks/ mirror that was added in the previous commit). - Register the rtk hook in the deliverable settings.json under PreToolUse matcher Bash, alongside validate-bash.py and the existing pre-command hook. Bump _meta.hooks_count from 15 to 16. - Add a check_mirror_sync function to tests/hooks-syntax-suite.sh that diffs .claude/hooks/<file> vs deliverables/hooks/hooks/<file> for an allow-list of tracked files (starting with rtk-rewrite.sh). Fails the suite if they drift. Legacy drift on other files is not yet in scope; the list will be extended as those are reconciled separately. Test suite: PASS=29 FAIL=0 (was 28, +1 mirror check). Refs: 260511-gpoapa, PR #2, ADR-032 Co-Authored-By: claude-flow <ruv@ruv.net>
Documentation and version bump for the alpha.12 release. Code changes landed in the previous two commits of PR #2 (260511-gpoapa). - README.md: new "RTK Token Reduction (optional)" section with the three valid install commands, the name-collision warning, and a pointer to ADR-032. Features table updated (24 -> 25 hooks; added RTK row). - package.json: 1.0.0-alpha.11 -> 1.0.0-alpha.12. publishConfig and files arrays unchanged; rtk-rewrite.sh ships inside the existing docs/arquetipo/deliverables/** glob. - RELEASE-NOTES.md: rewritten for alpha.12. Highlights focus on the RTK integration, ADR-032, the anti-drift test, the diagrams, and the workflow audit (process miss + retroactive PRD). Migration path is purely additive (no breaking changes from alpha.11). The release.yml workflow fires on push of tag v1.0.0-alpha.12. This commit does not create or push that tag - tag creation is deferred until PR #2 is merged to main. Refs: 260511-gpoapa, PR #2, ADR-032 Co-Authored-By: claude-flow <ruv@ruv.net>
DarkCodePE
pushed a commit
that referenced
this pull request
May 14, 2026
Wave C C3 of ADR-036. Hookifies the §9 File rule doctrine: post-edit hook conditionally invokes smell-scanner which detects canonical smells (bare catch, TODO without link, function >30 LoC, cyclomatic >10) on the diff and auto-files issues with dedupe via AgentDB pattern-store cache. 9 AC across 7 slices. Default-off via SMELL_SCAN_ENABLE=1 (ADR-035 pattern). Supersedes the original Brecha #2 collateral-issuer.mjs proposal. Refs #11 #12 #13 #14 #15 #16 #17. Co-Authored-By: claude-flow <ruv@ruv.net>
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.
Closes #1
Summary
Wires the upstream
rtkbinary (github.com/rtk-ai/rtk, v0.34.3) into RuFlo via a PreToolUse hook for 60-90% token reduction on Bash tool outputs. RTK is treated as an optional external CLI dependency (install viabreworcargo install --git), invoked from the hook verbatim, never absorbed into this repo.PRD
Authoritative spec lives in
docs/plans/260511-gpoapa-rtk-external-cli-integration.md.Architectural decision
ADR-032 — Status: Proposed. Clarifies that ADR-027's "absorb-not-install" policy applies to Claude Code plugins, while RTK (a standalone CLI binary) follows the inverse "install-not-absorb" pattern, same as
git,jq, orripgrep.Negative reference
9router/open-sse/rtk/reimplemented rtk in JavaScript inside a MITM proxy (~1000 LOC owned, no upstream tests, marketing-grade "20-40%" claim with no benchmark). We invoke the upstream binary instead.Test plan
Bash(git diff)toBash(rtk git diff)when rtk >= 0.23.0 is installedbash .claude/hooks/rtk-rewrite.sh < /dev/null→ no error)CLAUDE.md§ RTK lists three valid install commands + explicit warning againstcargo install rtkADR-032documents alternatives, relation to ADR-027, and verification commandrtk gainreports 60-90% compression after two real Claude Code sessions (deferred to post-merge)ruflo-rtk-integration.drawioshows the hook + external-deps architectureFiles changed
.claude/hooks/rtk-rewrite.sh(new, verbatim from upstream).claude/settings.json(PreToolUse Bash matcher: rtk hook added next to existing pre-bash)CLAUDE.md(RTK Token Reduction section + install warning)docs/adr/ADR-032-rtk-external-cli-dependency.md(new)docs/diagrams/9router-vs-ruflo-token-reduction.drawio(new, comparative)docs/diagrams/ruflo-rtk-integration.drawio(new, final integration)docs/plans/260511-gpoapa-rtk-external-cli-integration.md(new, PRD)Process note
This PR closes a workflow audit gap: the
/grill-mestep happened conversationally and/to-prdran retroactively after the swarm dispatch. The PRD's Further Notes section documents the miss so it does not recur.🤖 Generated with claude-flow