diff --git a/.claude-plugin/marketplace.json b/.claude-plugin/marketplace.json index dad506d..edeea29 100644 --- a/.claude-plugin/marketplace.json +++ b/.claude-plugin/marketplace.json @@ -6,14 +6,14 @@ }, "metadata": { "description": "Toolkit of skills, hooks, templates, and guides for bootstrapping AI-agent-friendly projects.", - "version": "0.4.3" + "version": "0.4.4" }, "plugins": [ { "name": "agent-starter", "source": "./", "description": "Skills, hooks, templates, and engineering guides for bootstrapping AI-agent-friendly projects, with a per-project self-improvement loop. Bundles the /new-project and /adopt-project scaffolding skills plus commit, simplify, reflect, remember, and dream.", - "version": "0.4.3", + "version": "0.4.4", "author": { "name": "Nick Sawinyh" }, diff --git a/.claude-plugin/plugin.json b/.claude-plugin/plugin.json index eba6b15..8b5ccf9 100644 --- a/.claude-plugin/plugin.json +++ b/.claude-plugin/plugin.json @@ -1,7 +1,7 @@ { "$schema": "https://json.schemastore.org/claude-code-plugin.json", "name": "agent-starter", - "version": "0.4.3", + "version": "0.4.4", "description": "Skills, hooks, templates, and engineering guides for bootstrapping AI-agent-friendly projects, with a per-project self-improvement loop.", "author": { "name": "Nick Sawinyh" diff --git a/AGENT.md b/AGENT.md index 9ad88f8..986fa04 100644 --- a/AGENT.md +++ b/AGENT.md @@ -158,6 +158,7 @@ Hooks wired by default: - `lint-on-edit.sh` - Biome + ESLint on save; ruff check + format for Python (PostToolUse:Write|Edit) - `check-silent-errors.sh` - block swallowed exceptions (PostToolUse:Write|Edit) - `block-dangerous-commands.sh` - block force-push, `reset --hard`, recursive rm on `/`/`~` (PreToolUse:Bash) +- `suggest-loop-improvements.sh` - on `/loop`, offer tighter drop-in rewrites via an interactive picker before it runs (UserPromptSubmit) Optional: add `--with-read-guard` to also wire `track-reads.sh` + `require-read-before-edit.sh` (force Read before Edit). Recent Claude Code diff --git a/README.md b/README.md index f22be1a..5245907 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ Install everything at once as a **Claude Code plugin** - this repo doubles as a /plugin install agent-starter@agent-starter ``` -That loads all the skills (`/new-project`, `/adopt-project`, `/commit`, `/commit-push-pr`, `/simplify`, `/reflect`, `/remember`, `/dream`) **and** wires the enforcement hooks (file-size, lint-on-edit, silent-error, dangerous-command, codebase-health) from `hooks/hooks.json`. This is the simplest path and the one to recommend. +That loads all the skills (`/new-project`, `/adopt-project`, `/commit`, `/commit-push-pr`, `/simplify`, `/reflect`, `/remember`, `/dream`) **and** wires the enforcement hooks (file-size, lint-on-edit, silent-error, dangerous-command, codebase-health) plus a `/loop` instruction-review hook from `hooks/hooks.json`. This is the simplest path and the one to recommend. The read-before-edit guard pair is left out of the plugin on purpose (recent Claude Code enforces read-before-edit natively); opt into it via `install.sh --with-read-guard` below. diff --git a/TEAM.md b/TEAM.md index 5cc88cf..25befda 100644 --- a/TEAM.md +++ b/TEAM.md @@ -61,7 +61,8 @@ Instead: { "matcher": "Write|Edit", "hooks": [{ "type": "command", "command": "$CLAUDE_PROJECT_DIR/.claude/hooks/check-silent-errors.sh", "timeout": 5, "statusMessage": "Checking error handling..." }] } ], "PreToolUse": [{ "matcher": "Bash", "hooks": [{ "type": "command", "command": "$CLAUDE_PROJECT_DIR/.claude/hooks/block-dangerous-commands.sh", "timeout": 3, "statusMessage": "Checking command safety..." }] }], - "SessionStart":[{ "hooks": [{ "type": "command", "command": "$CLAUDE_PROJECT_DIR/.claude/hooks/check-codebase-health.sh .", "timeout": 15, "statusMessage": "Checking codebase health..." }] }] + "SessionStart":[{ "hooks": [{ "type": "command", "command": "$CLAUDE_PROJECT_DIR/.claude/hooks/check-codebase-health.sh .", "timeout": 15, "statusMessage": "Checking codebase health..." }] }], + "UserPromptSubmit":[{ "hooks": [{ "type": "command", "command": "$CLAUDE_PROJECT_DIR/.claude/hooks/suggest-loop-improvements.sh", "timeout": 10, "statusMessage": "Reviewing loop instructions..." }] }] } } ``` diff --git a/VERSION b/VERSION index 17b2ccd..6f2743d 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.3 +0.4.4 diff --git a/hooks/README.md b/hooks/README.md index 2d25792..b553fdd 100644 --- a/hooks/README.md +++ b/hooks/README.md @@ -158,6 +158,31 @@ Add to `settings.json`: } ``` +### suggest-loop-improvements.sh +**Event:** UserPromptSubmit +**What it does:** When you run `/loop`, injects an instruction that has Claude propose 2-3 improved, drop-in replacements for the command before it runs, then present them with the `AskUserQuestion` tool so you pick one interactively (A / B / C, plus "Run original unchanged") - no copy-paste. Claude runs only the option you select. + +- The hook does **no LLM work and spawns no nested session** - it only injects context, so the already-running model generates the variants. Fast (<50ms), needs no API key. +- Filters by prompt text (`UserPromptSubmit` has no matcher), so it is a silent no-op for every other prompt. +- Each replacement adds only the missing precision - explicit success criteria, a stop condition, bounded scope, a verification step - while preserving your interval and args. +- Non-blocking (exit 0): if the command is already solid, or the session is headless (no interactive prompt), the original runs unchanged. + +**Scoped to `/loop` only, on purpose.** `/loop` hands control to Claude to interpret and act, so the injected "ask first" instruction lands *before* any action and the picker can render. Client-side local commands like `/goal` execute their effect at submit time (the CLI sets the goal and arms its Stop hook before Claude's turn even starts), so an advisory (exit 0) injection cannot intercept them, and `/goal` also explicitly tells Claude not to pause and ask. The hook therefore matches only `/loop*` and ignores `/goal`. Interactive gating like this works only for commands whose effect Claude performs on its turn, not for client-side commands. + +Add to `settings.json`: + +```json +{ + "UserPromptSubmit": [ + { + "hooks": [ + { "type": "command", "command": "~/.claude/hooks/suggest-loop-improvements.sh", "timeout": 10, "statusMessage": "Reviewing loop instructions..." } + ] + } + ] +} +``` + ## Exit Code Behavior - **Exit 0** - success, proceed normally - **Exit 2** - BLOCK the action, stderr shown to Claude as error diff --git a/hooks/hooks.json b/hooks/hooks.json index fcc1f64..5f072f1 100644 --- a/hooks/hooks.json +++ b/hooks/hooks.json @@ -60,6 +60,18 @@ } ] } + ], + "UserPromptSubmit": [ + { + "hooks": [ + { + "type": "command", + "command": "${CLAUDE_PLUGIN_ROOT}/hooks/suggest-loop-improvements.sh", + "timeout": 10, + "statusMessage": "Reviewing loop instructions..." + } + ] + } ] } } diff --git a/hooks/suggest-loop-improvements.sh b/hooks/suggest-loop-improvements.sh new file mode 100755 index 0000000..b8aa24c --- /dev/null +++ b/hooks/suggest-loop-improvements.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env bash +# UserPromptSubmit hook: when the user runs /loop, inject an instruction telling +# Claude to first propose improved, drop-in replacements for the command and let +# the user pick one interactively via AskUserQuestion (no copy-paste), then run +# only the chosen command. +# +# The hook itself does no LLM work and spawns no nested session - it only injects +# context, so the already-running model generates the variants. That keeps it +# fast (<50ms), needs no API key, and no matcher (UserPromptSubmit has none), so +# it filters to /loop by prompt text. Scoped to /loop only: client-side local +# commands like /goal execute their effect at submit time, before Claude's turn, +# so an advisory injection cannot gate them. Non-blocking: every other prompt, +# and any parse failure, passes through untouched (exit 0). +set -euo pipefail + +input="$(cat)" +prompt="$(printf '%s' "$input" | jq -r '.prompt // empty')" + +# Only act on /loop invocations; everything else passes through. +case "$prompt" in + /loop*) ;; + *) exit 0 ;; +esac + +cat < +The user is about to run this command: $prompt + +Before executing it, do this first: +1. Generate 2-3 improved, drop-in replacements for the command. Keep each faithful + to the original intent (preserve the interval and args); only add the missing + precision - explicit success criteria, an explicit stop condition, bounded + scope, and a verification step. +2. Call the AskUserQuestion tool (header "Improve loop?") with: + - one option per replacement, lettered in order: label "A - ", + "B - ", ... and put the full rewritten command plus a one-line + "Why:" in each option's description. + - a final option: label "Run original unchanged", description = the original command. +3. Run ONLY the command the user selects, verbatim. For the last option, run the + original command as-is. + +If the command already has clear success criteria, a stop condition, bounded scope, +and a verification step, skip the question and run it unchanged. If you cannot show +an interactive prompt (headless/non-interactive session), run the original unchanged. + +EOF +exit 0 diff --git a/install.sh b/install.sh index 047dd91..5fca5dc 100755 --- a/install.sh +++ b/install.sh @@ -72,6 +72,7 @@ jq --arg h "$H" --argjson guard "$READ_GUARD" ' | add("PostToolUse"; entry("Write|Edit"; $h + "/check-silent-errors.sh"; 5; "Checking error handling...")) | add("PreToolUse"; entry("Bash"; $h + "/block-dangerous-commands.sh"; 3; "Checking command safety...")) | add("SessionStart"; {hooks: [{type: "command", command: ($h + "/check-codebase-health.sh ."), timeout: 15, statusMessage: "Checking codebase health..."}]}) + | add("UserPromptSubmit"; {hooks: [{type: "command", command: ($h + "/suggest-loop-improvements.sh"), timeout: 10, statusMessage: "Reviewing loop instructions..."}]}) | (if $guard == 1 then add("PostToolUse"; entry("Read"; $h + "/track-reads.sh"; 3; "Tracking reads...")) | add("PreToolUse"; entry("Edit|Write"; $h + "/require-read-before-edit.sh"; 3; "Checking read log...")) diff --git a/skills/new-project/SKILL.md b/skills/new-project/SKILL.md index ebf509c..68681fb 100644 --- a/skills/new-project/SKILL.md +++ b/skills/new-project/SKILL.md @@ -204,6 +204,7 @@ Hook behavior (wired by default): - `check-silent-errors.sh` - blocks writes that introduce swallowed exceptions. - `block-dangerous-commands.sh` - blocks force-push, `git reset --hard`, recursive rm on `/`/`~`, before they run. - `check-codebase-health.sh` - runs at session start. Reports files over 500 lines that need splitting. Silent when healthy. +- `suggest-loop-improvements.sh` - when you run `/loop`, proposes 2-3 tighter drop-in rewrites (explicit success criteria, stop condition, scope, verification) and lets you pick one via an interactive menu. Scoped to `/loop` only (client-side commands like `/goal` run before Claude's turn, so they can't be gated). Optional: `--with-read-guard` also wires `track-reads.sh` + `require-read-before-edit.sh`. Recent Claude Code versions enforce read-before-edit natively, so only add it for older versions.