rtk-ai/rtk

[DevEx] PostToolUse hook: micro-alignment on every edit (cargo check, clippy, shellcheck, shfmt)

Open

#748 aperta il 20 mar 2026

Vedi su GitHub
 (2 commenti) (0 reazioni) (0 assegnatari)Rust (2914 fork)batch import
area:configeffort-mediumenhancementhelp wantedpriority:medium

Metriche repository

Star
 (48.085 star)
Metriche merge PR
 (Merge medio 11g 1h) (45 PR mergiate in 30 g)

Descrizione

Why

Code quality misalignments — compilation errors, lint violations, unsafe shell constructs — are cheap to fix individually but expensive to discover late. When they accumulate across multiple edits, they compound: a broken type cascades into a broken module, a clippy warning multiplies across 10 files, and the developer ends up doing a bulk cleanup pass instead of shipping.

Claude Code edits files frequently and rapidly. Without an inline gate, each Write/Edit is a potential misalignment that silently persists until the developer runs cargo clippy manually or the CI pipeline catches it. In the RTK workflow, that gap can span dozens of tool calls.

The "alignment" principle is simple: the shorter the life of a misalignment, the lower its blast radius. A compilation error caught after one edit costs one fix. The same error caught after twenty edits costs a debugging session.

How

We propose adding a PostToolUse hook that fires on every Write or Edit tool call in Claude Code. It would inspect the modified file, route to the appropriate gates by extension, and either auto-fix or block.

Rust (.rs)

  • cargo check — blocks on type/compilation errors
  • cargo clippy — blocks on errors, warns on warnings (non-blocking)

Shell (.sh)

  • shfmt -w — auto-formats in place (non-blocking)
  • shellcheck — blocks on undefined behavior, unsafe constructs

Behavior

Outcome Hook exit Effect
All gates pass 0 Emits systemMessage to Claude UI (e.g. cargo check: OK)
Auto-fix applied 0 Emits auto-fixed by shfmt | ...
Gate failure 2 Blocks the edit, surfaces error in Claude UI
Tool not installed 0 Degrades gracefully, records not installed

Setup would require copying .claude/settings.json.examplesettings.json. All tool dependencies (cargo, clippy, shfmt, shellcheck) would be declared in .mise/config.toml and auto-installed.

A working implementation is available on branch devex/alignment-claude-hook.

Guida contributor