Skip to content

feat(hooks-plugin): add bash-antipatterns-teach PostToolUse hook (opt-in)#1308

Merged
laurigates merged 2 commits into
mainfrom
feat/bash-antipatterns-teach-hook
May 12, 2026
Merged

feat(hooks-plugin): add bash-antipatterns-teach PostToolUse hook (opt-in)#1308
laurigates merged 2 commits into
mainfrom
feat/bash-antipatterns-teach-hook

Conversation

@laurigates
Copy link
Copy Markdown
Owner

Summary

  • Add bash-antipatterns-teach.sh: a PostToolUse Bash hook that augments tool output via hookSpecificOutput.updatedToolOutput (Claude Code 2.1.121+) with concrete tool-replacement hints for soft-teach antipatterns (cat/head/tail, find -name, grep/rg, ls *.glob)
  • Wire the hook into hooks-plugin/.claude-plugin/plugin.json as a PostToolUse Bash matcher with timeout: 5000
  • Gate execution behind CLAUDE_HOOKS_ENABLE_BASH_ANTIPATTERNS_TEACH=1 (default disabled; matches event-logger.sh opt-in convention)
  • Existing PreToolUse bash-antipatterns.sh is unchanged

Motivation

W20 friction analysis (~/.claude/rules/friction/2026-W20-frictions.md) measured a 21% same-session repeat-block rate on grep/rg PreToolUse blocks — about 2× the rate for git && (8%) or find -name (12%). The hook teaches less effectively because the agent only sees the corrective message, never the would-have-been-result. Letting the command run and prepending the hint to the tool result gives the agent both the data and the lesson in one response.

Hypothesis: same-session repeat-block rate on grep/rg/find -name/cat/head/tail/ls *.glob drops from ~21% to the established ~10% floor. W21 friction pass (2026-05-18) measures.

Test plan

  • bash -n syntax-check on both scripts
  • jq empty validates plugin.json
  • New test-bash-antipatterns-teach.sh: 17 passed, 0 failed (covers all match patterns, exemptions, and the env-var guard)
  • Existing test-bash-antipatterns.sh: 25 passed, 0 failed (no regression)
  • Hook follows event-logger.sh-style opt-in convention
  • Phase 1 caveat documented: teach hook only fires when PreToolUse didn't block, so observing teach-mode in phase 1 requires also overriding the soft-teach PreToolUse blocks locally

Follow-ups (not in this PR)

  • W21 friction pass measures repeat-block rate on opted-in sessions
  • Phase 2 (W22+) decides whether to flip the env-var default and strip soft-teach blocks from bash-antipatterns.sh
  • Separate issue: invoke hooks-plugin/hooks/test-*.sh from CI

See hooks-plugin/docs/teach-mode-experiment.md for full hypothesis, rollout plan, and success criterion.

🤖 Generated with Claude Code

…-in)

Teach soft-pattern alternatives (cat, find -name, grep, head/tail,
ls *.glob) via output augmentation rather than PreToolUse blocking.
W20 friction analysis showed 21% same-session repeat-block rate on
grep/rg - letting the command run and prepending the corrective
hint to the result should land the lesson concretely.

Phase 1: opt-in only. Enable with
CLAUDE_HOOKS_ENABLE_BASH_ANTIPATTERNS_TEACH=1. Existing
bash-antipatterns.sh blocking is unchanged. W21 friction pass
evaluates whether to promote to default in phase 2.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@laurigates laurigates added the enhancement New feature or request label May 11, 2026
@laurigates laurigates self-assigned this May 11, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Plugin Compliance Review

Plugin plugin.json Frontmatter Body Marketplace Release Config Bash Patterns Descriptions When-to-Use Size Overall
hooks-plugin ⚠️ ⚠️

Recommendations

  • ⚠️ hooks-plugin/hooks-permission-request-hook: SKILL.md is 442 lines (>250) — consider extracting to REFERENCE.md or scripts/ (Anthropic ideal: 200, ceiling: 500)
  • ⚠️ hooks-plugin/hooks-session-start-hook: SKILL.md is 291 lines (>250) — consider extracting to REFERENCE.md or scripts/ (Anthropic ideal: 200, ceiling: 500)
  • ⚠️ hooks-plugin/hooks-configuration: SKILL.md is 312 lines (>250) — consider extracting to REFERENCE.md or scripts/ (Anthropic ideal: 200, ceiling: 500)

@laurigates
Copy link
Copy Markdown
Owner Author

Let's address the recommendations in the comments. Evaluate which pieces of criticism and recommendations are substantive and valid. Act accordingly and refute invalid points.
@claude

@claude
Copy link
Copy Markdown

claude Bot commented May 11, 2026

Claude finished @laurigates's task in 7m 28s —— View job


Evaluating CI Recommendations

Assessment

All three size warnings are valid — every flagged skill was in the 251–500 WARN zone per skill-quality.md. None are false positives. Worth noting: none of these files were modified by this PR; the CI does a full plugin scan on every push, surfacing pre-existing debt.

Skill Before After Change
hooks-permission-request-hook 442 lines 193 lines Script template + test spec → new REFERENCE.md
hooks-session-start-hook 291 lines 179 lines Script template → new REFERENCE.md
hooks-configuration 312 lines 240 lines Prompt/agent hooks + debugging sections → existing REFERENCE.md; best practices compacted to table

All three are now at or below the 200-line ideal. The extracted templates and specs live in REFERENCE.md (no size limit) alongside a pointer in each SKILL.md — the generation skills still produce the same output at runtime, they just read the template via [REFERENCE.md](REFERENCE.md) instead of having it inlined.

Tasks:

  • Read skill-quality rules to understand size limits
  • Read the three flagged skill files to assess their content
  • Evaluate validity of each recommendation
  • Extract hooks-permission-request-hook template to REFERENCE.md
  • Extract hooks-session-start-hook template to REFERENCE.md
  • Move sections from hooks-configuration SKILL.md → REFERENCE.md
  • Commit and push changes
    · Branch

…three skills

hooks-permission-request-hook: 442 → 193 lines (script template + test spec extracted)
hooks-session-start-hook: 291 → 179 lines (script template extracted)
hooks-configuration: 312 → 240 lines (prompt/agent hooks + debugging sections extracted)

All three were in the 251-500 WARN zone per skill-quality.md. Now all are below 200
(permission-request) or near it (session-start, configuration).

Co-authored-by: Lauri Gates <[email protected]>
@laurigates laurigates merged commit edf32fd into main May 12, 2026
@laurigates laurigates deleted the feat/bash-antipatterns-teach-hook branch May 12, 2026 04:52
laurigates-release-please Bot added a commit that referenced this pull request May 12, 2026
🤖 I have created a release *beep* *boop*
---


<details><summary>hooks-plugin: 2.2.0</summary>

##
[2.2.0](hooks-plugin-v2.1.1...hooks-plugin-v2.2.0)
(2026-05-12)


### Features

* **hooks-plugin:** add bash-antipatterns-teach PostToolUse hook
(opt-in)
([#1308](#1308))
([edf32fd](edf32fd))
</details>

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Co-authored-by: laurigates-release-please[bot] <272124289+laurigates-release-please[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant