">
[go: up one dir, main page]

Habit Hooks

Habit Hooks improves code quality by guiding AI agents to remove code smells 5× more effectively than traditional linters alone.

uv tool install habit-hooks
cd your-project
habit-hooks init

To find out more about how Habit Hooks works, watch a short video on YouTube or read on.

Short introduction to Habit Hooks on YouTube

Why

  • AI coding agents ignore long rule documents. A book's worth of coding advice in the context window makes them worse, not better.
  • Humans don't need it in their head. Repetition turns advice into habit, triggered by an easy-to-spot cue. Agents can't form habits.
  • A bare linter score is a target, and Goodhart's law applies: agents are very good at gaming a target when the target is all they are given.
  • Habit Hooks supplies the missing loop from outside. The linter finding is the cue; the coaching guide is the action.

The effect: better code, better agent performance on the next task, and fewer tokens — good code needs less context to work in.

Does it actually work?

Does coaching actually beat a bare metric, or do both just get gamed? Liina Suoniemi measured it — independently, and pre-registered before any model ran.

Genuine-fix rate by how the instruction is phrased. A coaching prompt reaches 83.3% on both models. The bare linter message reaches 28.9% on Haiku 4.5 and 5.6% on Sonnet 4.6.
  • The bare metric gets gamed. Given only function is too complex (11 > 5), Sonnet 4.6 produced a genuine fix in 5.6% of trials. It gamed the check in 79 of 90 — splitting branches into helpers so the number fell while the code got no simpler.
  • The stronger model gamed it more, not less. Haiku 4.5 managed 28.9% on the same bare metric. Capability does not buy honesty about a target.
  • Coaching fixed it on both. 83.3% genuine — about 5× the bare metric's 17% averaged across both models — and the confidence intervals do not overlap the bare-metric ones on either model.
  • It is the phrasing, not just asking nicely. A control that said only "improve this code" stayed at 25.6% and 34.4%.

18 real Python functions, one known smell each, 5 trials per function per condition, 90 trials per bar. Scored by a deterministic judge — no LLM — checked against blind human labelling at 90% agreement, Cohen's κ 0.85. Method, raw trials and the author's own list of what the judge can miss are all in the repository.

How it works

habit-sensors <scope flags> | habit-mapper

  • habit-sensors runs your linters over the files in scope and emits findings.
  • habit-mapper groups them by smell, renders that smell's coaching guide, and sets the exit code from its severity.

Each sensor translates a tool's raw rule IDs into a tool-independent smell key — max-params, PLR0913 and friends all become too-many-parameters — so the guide is chosen by smell, never by which tool reported it.

Languages

Python ruff, deptry
TypeScript eslint, knip, ts-morph
PHP phpmd
Java pmd
Ruby rubocop
Any line count, jscpd

Each is a separately installable plugin. A project's own config for a wrapped tool always wins — installing Habit Hooks never overrides preferences you already set.

What it catches

oversized-functiontoo-many-parameters high-complexitydeep-nesting oversized-fileunused-variable unused-importloose-equality var-declarationnon-const-binding duplicate-importredundant-type-annotation unused-class-memberunused-file unused-exportunused-dependency test-only-dead-codeparse-error warning-commentexplicit-any non-null-assertionnon-essential-comment duplicated-codeswallowed-exception

Pink fails the run. Grey coaches and exits 0. Either can be overridden per smell.

Starting on an existing codebase

Snooze today's findings, so from then on only new smells surface:

habit-sensors --all | habit-snooze --snooze

Commit the index it writes. Nothing is buried permanently — the ratchet variant brings a file's issues back the moment you touch it.