rtk-ai/rtk

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

Open

#748 建立於 2026年3月20日

在 GitHub 查看
 (2 留言) (0 反應) (0 負責人)Rust (2,914 fork)batch import
area:configeffort-mediumenhancementhelp wantedpriority:medium

倉庫指標

Star
 (48,085 star)
PR 合併指標
 (平均合併 11天 1小時) (30 天內合併 45 個 PR)

描述

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.

貢獻者指南