SLOPSHOPPER

lean-scripts

Scripts worth keeping: scripts-review asks Haiku whether a new script could just be typed again when needed.

guardstatusmodelprocess
v1.26.0MITupdated 2026-10-24bahaospanov/skills/lean-scripts
A shopper browsing a rack in a slop shop
README

bahaospanov

Bakhtiyar Ospanov's agent skills, and Claude Code mods: plugins built on function hooks.

Skills

For any agent the skills CLI supports:

npx skills add bahaospanov/skills --skill <skill>

Or in Claude Code, all of them as one plugin, invoked as /bahaospanov-skills:<skill>:

/plugin marketplace add bahaospanov/skills
/plugin install bahaospanov-skills@bahaospanov

Pick one: installing both leaves every skill twice.

User-invoked

Reachable only when you type them (Claude Code: disable-model-invocation: true; Codex: policy.allow_implicit_invocation: false in agents/openai.yaml).

  • release: Integration branch to production: fold fixup commits into their parent, cut waves around migrations and one-time steps, ship wave by wave with a runbook issue, then tag a SemVer release, note the shipped issues for you to close, and build a phone-sized release album.

Model-invoked

Model- or user-reachable.

  • playbook: How a change goes from issue to merged branch, in parts: issues, branches, commits, merge requests, cleanup. A project states its facts (base branch, issue number format, deviations) in a ### Playbook block of its AGENTS.md. Its MR description is mattpocock/skills pr (MIT), whose Summary visuals come from Dex Horthy's HumanLayer show-me (MIT).
  • presentation: Phone-sized slides of what changed for a product's users, one changed place per slide: its page URL and desktop before/after shots with the change outlined, rendered as 4:5 PNGs with a caption to post in a chat; release builds its release album with it.
  • prototype-stages: mattpocock/skills prototype (MIT), its UI branch reworked: whole flows, options grouped by stage in a one-click panel.
  • scheme: ASCII schematic of a code change: control flow, data flow, before/after, or layers.

Mods

Early access; the API changes between releases.

One mod per purpose. Why each one and each of its rules exists: STORY.md.

ModPurpose
git-gatesGit work happens on the user's word
git-tidyGit history stays tidy
git-cleanupMerged work is cleaned up once it shipped
issue-firstFeature work starts from an issue, and each commit names its own
lean-docsDocs worth keeping
lean-commentsComments worth keeping
lean-scriptsScripts worth keeping
close-countdownA Herdr pane counts down before it closes
traffic-lightThe band says whether the session's work is done

Haiku reviews are gated in code first, so a call that cannot fail the review costs no model call. End-of-turn checks read the git diff of repos the turn touched, Bash edits included, and show at most two one-line notices a session; the report reaches Claude with your next message and is acted on when you ask.

git-gates

Pushing is a deploy, so the agent needs the user's word in the current turn: the prompt that opened it or one typed while it ran. If a consent check itself fails, the call is blocked.

CheckRuns onNeedsThen
consentgit commit, push, with or without git's own options (git -C dir push); opening a PR/MR; PR/MR mergecommit, push, ship, deploy, pr, mr, tag or release typed in the current turn (a message typed while it runs or a background task's report does not withdraw it); a push needs one of them other than commit; opening needs pr, mr, pull request, merge request or ship; merge needs "merge", and "merge request" is not it; a protected branch must be named. A negated keyword ("don't push") does not count, and a no to the act itself refuses it, standing grant included, unless the turn also asks for itCall denied
grantsLater commits in the sessionA message asking for a commit per task, or the grant tool after an authorizing messageCommits spend the grant; pushes never

Protected branches come from a repo's own push policy file. Integration branches are the protected ones; with no policy, the remote's default branch and any of dev, develop, main, master that exist. Deleting a branch on origin needs no keyword when origin's head of it already sits in an integration branch.

git-tidy

The rules' text lives in the playbook; the commit-order, follow-up and feature refusals name the part.

CheckRuns onNeedsThen
messagesA git commitConventional Commits subject, no Co-Authored-By trailer naming Claude or Anthropic (in the message or a --trailer flag) and no "Generated with Claude Code" lineCommit denied
message adviceA git commitNo reviewer pre-answers ("no X changed"); then Haiku: a body only when the cause is subtleCommit runs; the user gets the advice
fresh baseOpening an MR/PR: gh pr create, glab mr create, a GitLab API POST to merge_requestsThe source branch, as origin has it, contains the target's latest commit, fetched first; skipped when the message says not to rebaseCall denied
landed branchA git pushThe branch's pushed head already sits in a protected branch, and the message names no new MRPush denied
every commit worksA git push of 2 to 15 commits no remote hasSonnet: no commit removes something a later one stops using, or uses something a later one adds; skipped when the message says the order is finePush denied
one commit per changeA git push of new commits to a branch whose commits not yet in an integration branch number 2 to 15, pushed or notNo fixup!, squash! or amend! subject; then Sonnet: no later commit spends most of its diff fixing, reworking or extending lines an earlier one added, or matches an earlier one's API contract change in another app; skipped when the message says to keep the commitsPush held: the agent shows the user the reason and asks; any answer lets the same commits through
one feature per MRA git push of new commits to a branch whose commits not yet in an integration branch number 1 to 15, pushed or notIts commit messages name at most one issue; then Sonnet: no piece of it could ship alone apart from the rest; skipped when the message says one MR or to keep them togetherPush held: the agent shows the user the features, recommends a branch and MR each, and asks; any answer lets the branch through for the session

Integration branches are found as git-gates finds them.

git-cleanup

Merged is not shipped: a branch is cleaned up and its issue filled in only once the pipeline holding the merge has passed. Closing the issue is left to you.

CheckRuns onNeedsThen
merged firstRemoving a branch, local or on origin; removing a worktree keeps its branch and is not heldThe branch sits in an integration branch, a merged PR/MR has it as source branch, or the current turn's message says it merged (or to abandon it)Call denied
pipeline firstRemoving a worktree or branch, local or on origin; rewriting an issue's body (checklist ticks, How to test)The work (the branch, the commit a squash merge landed as, or the newest integration commit naming the issue) landed and a pipeline holding it passed; skipped when the message says not to waitCall denied while it runs or after it failed; a GitLab pipeline parked at manual or skipped holds nothing back
stale workThe end of a turnA branch the session committed to or pushed that sits in an integration branch, its worktree clean, no pipeline holding it still running or failedRemoves the worktree and the branch, local and on origin, fast-forwards a local integration branch behind origin, and prints one line saying what went; the worktree the session works in stays

Integration branches are found as git-gates finds them. A branch sits in an integration branch when its head does, or when every commit of it has a copy there (a rebase merge). Pipelines are read with gh on GitHub and, on GitLab, with the gitlab_token option: a read_api token, asked when the plugin is enabled, kept in the keychain on macOS and in ~/.claude/.credentials.json elsewhere. With no token or no pipeline holding the work, the pipeline check holds nothing back and a log line says why; merged first still applies, and on GitLab sees a squash merge only with the token.

issue-first

CheckRuns onNeedsThen
feature issueA feat commitAn issue (#107, #BLK-23) at the end of the subject, or in the branch name (feat/catalog-menu-107), or "no issue" typed by the user in the current turnCommit denied; Claude looks for the issue, else drafts one and asks the user before creating it
issue numberA git commitThe issue or ticket your messages or the branch name, at the end of the subjectCommit runs; the user gets the suggestion

A repo with no remote has no issue tracker: feature issue is skipped, and only a ticket (#BLK-23) counts as an issue. Issues you typed bind only commits in the session's repo and its worktrees; a branch ending in its issue number (perf/mobile-lcp-89) lets the subject end with that one instead. Enabled in a repo's own .claude/settings.json, it applies to everyone working there.

lean-docs

CheckRuns onFlagsThen
docs-reviewA doc grown in a git checkoutHaiku: text nobody reads after the task (runbooks, setup pages, narration)Claude gets the reason
docs-no-repeat-codeA doc line being writtenIdentifiers that already appear together in one code fileClaude gets the hint; the write goes ahead
limit-docsThe end of a turnNew or grown docs, prose outweighing code, doc lines repeating codeA one-line notice; say "trim docs" to act on it

No check reads a skill's folder, the one holding SKILL.md, or anything under it: a skill is read again on every use.

Media and marketing work is out of scope too: a file its own checkout ignores (a local reels/ or renders/ folder) or one under a folder holding a .lean-skip file.

lean-comments

No comments by default: keep the ones that record a measured number, a trap or an invariant, cut the ones that restate the code or narrate the change.

CheckRuns onFlagsThen
limit-editsA Write or EditMore than 3 added comment lines, or a comment-heavy region around an edit that adds commentsClaude gets the guidance
limit-turnsThe end of a turnMore than 3 new comment lines per file in the turn's diffA one-line notice; say "trim comments" to act on it

No check reads a file installed under ~/.agents/skills, ~/.claude/skills or ~/.claude/plugins: it is someone else's code. A link from there into a checkout is followed, and the file is checked.

Media and marketing work is out of scope too: a file its own checkout ignores (a local reels/ or renders/ folder) or one under a folder holding a .lean-skip file.

lean-scripts

CheckRuns onFlagsThen
scripts-reviewA script written or grown in a git checkoutHaiku: scripts you could just type again when neededClaude gets the reason

A script is a shell file, a file in a scripts, bin, tools or ops folder, or one starting with a shebang. A skill's folder is skipped: the skill runs its scripts on every use.

Media and marketing work is out of scope too: a file its own checkout ignores (a local reels/ or renders/ folder) or one under a folder holding a .lean-skip file.

close-countdown

A Herdr subtask closing its own pane shows it first, so whoever watches can stop it.

PartWhat it does
close_pane_later toolCloses this session's Herdr pane, or pane, after seconds (default 60) and returns at once; note is shown beside the countdown
The band⏻ Closing this pane in 42s · <note> [ ✋ Keep open ] [ ❌ Close now ] above the prompt, a draining bar under it
CancelA message typed into the session, ✋ Keep open or /keep-open; ❌ Close now closes the pane at once

It runs herdr pane close, so the session needs herdr on its PATH and a Herdr pane (HERDR_PANE_ID).

traffic-light

A band above the prompt says whether you can leave the session.

LightWhen
🟢 safe to leaveThe PR is merged into dev, develop, main or master and every GitHub Actions run of that push passed; a run a newer push cancelled is judged by the newer one
🟡 waiting on PRThe PR is open, failing checks included, or merged with its pipeline still running
🔴 workingClaude is asking you, a turn is running where the light would be green, the repo holds uncommitted or unpushed work, there is no PR, it closed unmerged or merged elsewhere, the pipeline failed, or work began after the PR merged

The repo is the one Claude last edited a file in. A feature branch is judged by its own PR; on an integration branch, or once the worktree is gone, by the PR a gh pr command last printed. A turn that changes nothing, such as a question, ends green again. A turn that edits a file git does not ignore, or creates a commit, branch, worktree, issue or PR, leaves that merged PR unable to turn the light green: green waits for the new work's PR. The light refreshes after git and gh commands, and every 30 seconds while yellow. /traffic-light prints it; /traffic-light demo shows each color.

It runs git and gh, so the session needs both on its PATH and gh signed in.

Install mods

Mods load only with function hooks enabled, so export this in your shell profile first:

export CLAUDE_CODE_ENABLE_FUNCTION_HOOKS=1

Without it Claude Code skips the mods silently. Then, in Claude Code:

/plugin marketplace add bahaospanov/skills
/plugin install <mod>@bahaospanov

Develop

One folder per mod. tsconfig.json and types/ are shared. An installed mod carries only its own folder, so code two mods share is copied into each one's hooks/shared/.

CLAUDE_CODE_ENABLE_FUNCTION_HOOKS=1 claude --plugin-dir ./<mod> --debug

Saving a file under <mod>/hooks/ reloads the mod. Repeat --plugin-dir to load several.

Check

npm run typecheck                 # tsc over every mod and its tests
npm run check:shared              # hooks/shared/ copies are identical across mods
npm run check:continuations       # every mod sending follow-up prompts is named where git-gates reads them
npm run check:version             # every plugin.json carries package.json's version
claude plugin validate ./<mod>    # what the engine sees the module hook and call
claude plugin test ./<mod>        # the mod's tests/

Types

types/ is written by /plugin-types types, run inside a session started as above. Regenerate, never edit, when:

  • Claude Code updates (head -1 types/claude-code.d.ts vs claude --version)
  • a plugin that adds to $ is enabled or disabled
  • an MCP server is connected or disconnected

Commit the result; git diff types/ shows what the update changed.

Source 5 files
hooks/register.ts 70 lines
1import type { EngineInterface, Register } from 'claude-code'
2import { isScriptPath, isTestFile } from './gates'
3import { SCRIPT_FILE } from './prompts'
4import { dirOf, isDotfileOrTemp, isTrim, MEDIA_CHECK } from './shared/paths'
5import { MODEL, promptFor, SYSTEM, verdictOf, type Review, type Verdict } from './shared/verdict'
6
7const SCRIPTS_REVIEW: Review = { name: 'scripts-review', prompt: SCRIPT_FILE, status: 'judging script' }
8
9const checkoutOf = async ($: EngineInterface, path: string) => {
10  const run = await $.process.run(['git', '-C', dirOf(path), 'rev-parse', '--show-toplevel'])
11  return run.exitCode === 0 ? run.stdout.trim() : undefined
12}
13
14// A skill runs its scripts on every use, so they are never the kind typed again on the spot.
15const inSkillFolder = async ($: EngineInterface, path: string, root: string) => {
16  for (let dir = dirOf(path); dir === root || dir.startsWith(`${root}/`); dir = dirOf(dir)) {
17    if (await $.fs.exists(`${dir}/SKILL.md`)) return true
18    if (dir === root) break
19  }
20  return false
21}
22
23const isMediaWork = async ($: EngineInterface, path: string) =>
24  (await $.process.run(['sh', '-c', MEDIA_CHECK, 'lean', path])).exitCode === 0
25
26// The loader follows $ only into functions of this file, so the model call lives here, not in shared/verdict.ts.
27const judge = async ($: EngineInterface, review: Review, input: object): Promise<Verdict | undefined> => {
28  $.ui.status(review.status)
29  try {
30    const result = await $.model.complete({ model: MODEL, system: SYSTEM, prompt: promptFor(review, input) })
31    const reply = result.isAnswered ? result.text : `(${result.reason})`
32    const verdict = verdictOf(reply)
33    if (verdict === undefined) $.ui.log(`lean-scripts/${review.name}: no verdict: ${reply.slice(0, 120)}`)
34    return verdict
35  } finally {
36    $.ui.status(undefined)
37  }
38}
39
40export const register: Register = (on) => {
41  on('tool.call', { tool: ['Write', 'Edit'] }, async ($, e, next) => {
42    const path = e.file_path
43    if (isTestFile(path) || isDotfileOrTemp(path, await $.env.get('HOME'), await $.env.get('TMPDIR'))) {
44      return next(e)
45    }
46    const result = await next(e)
47    if (result.deny !== undefined || result.isError) return result
48
49    if (e.tool === 'Edit' && isTrim(e.new_string, e.old_string)) return result
50    const isScript =
51      isScriptPath(path) || (e.tool === 'Write' ? e.content : await $.fs.read(path).catch(() => '')).startsWith('#!')
52    const root = isScript ? await checkoutOf($, path) : undefined
53    if (root === undefined || (await inSkillFolder($, path, root)) || (await isMediaWork($, path))) return result
54
55    const tool_input =
56      e.tool === 'Write'
57        ? { file_path: path, content: e.content }
58        : { file_path: path, old_string: e.old_string, new_string: e.new_string, replace_all: e.replace_all }
59    const verdict = await judge($, SCRIPTS_REVIEW, {
60      hook_event_name: 'PostToolUse',
61      tool_name: e.tool,
62      tool_input,
63      cwd: await $.session.cwd(),
64    })
65    if (verdict?.ok !== false) return result
66    $.ui.log(`lean-scripts/scripts-review: ${verdict.reason}`)
67    return { ...result, context: [...(result.context ?? []), `lean-scripts/scripts-review: ${verdict.reason}`] }
68  })
69}
70
hooks/gates.ts 20 lines
1// The prompt's GATE FIRST paragraph as code: a call it would pass with ok=true costs no model call.
2
3const SHELL_EXT = ['.sh', '.bash', '.zsh']
4const SCRIPT_EXT = [...SHELL_EXT, '.py', '.cjs', '.mjs', '.js', '.rb', '.pl']
5// Where a layout keeps the programs it runs on their own; elsewhere a .py or .js file is a module the app imports.
6const SCRIPT_DIR = /\/(scripts?|bin|tools|ops)\//
7
8const extOf = (path: string) => {
9  const base = path.slice(path.lastIndexOf('/') + 1)
10  const dot = base.lastIndexOf('.')
11  return dot > 0 ? base.slice(dot).toLowerCase() : ''
12}
13
14export const isScriptPath = (path: string) =>
15  SHELL_EXT.includes(extOf(path)) || (SCRIPT_EXT.includes(extOf(path)) && SCRIPT_DIR.test(path))
16
17export const isTestFile = (path: string) =>
18  /\/(tests?|__tests__)\//.test(path) ||
19  /\/(test_[^/]*|[^/]*_test\.[^/]+|[^/]*\.(test|spec)\.[^/]+)$/.test(path)
20
hooks/prompts.ts 18 lines
1// `$ARGUMENTS` is the hook input as JSON.
2
3export const SCRIPT_FILE = `Reviewer for a SCRIPT FILE. $ARGUMENTS
4GATE FIRST, and this decides most calls. Judge ONLY when tool_input.file_path is inside a project checkout AND is a standalone runnable program: a shell script (.sh .bash .zsh), a .py .cjs .mjs .js .rb .pl file in a scripts, bin, tools or ops folder, or a file whose content starts with a shebang. Anything else - application source (a module the app imports), a test file, a config, a lockfile, a path under a home-directory dotfile tree, a temp or scratch directory - return ok=true with NO reason and nothing else. Do not judge code quality, style, or correctness. Never judge whether the work should have been done.
5On a Write, judge the whole file. On an Edit, judge only the added lines (new_string): a deletion or a trim is always ok=true, and so is a fix to a script that already earns its place.
6The question, for a whole new file: when this is needed again, could it simply be written again on the spot, correctly? For added lines: is this addition itself the kind of thing someone would just type inline?
7If YES -> ok=false, reason: 'writable on demand - run it inline now instead of committing it'.
8If NO -> ok=true.
9It is NOT writable on demand, so ok=true, when ANY of these hold:
10- something other than a human invokes it: a CI job, a cron entry, a Dockerfile, a compose service, a git hook, another script.
11- it is reached for when its author is absent or under pressure - recovery, restore, on-call, lockout - where composing it fresh is exactly when it gets written wrong.
12- getting it wrong is destructive or irreversible: it deletes, rotates, migrates, or touches production data or DNS, and it encodes the reasoning for WHY an operation is safe.
13- it encodes a non-obvious fact that had to be discovered: a measured threshold, an API's undocumented requirement, a key format, an upstream quirk. Re-deriving it would take real work and would likely come out wrong.
14A ground only counts if the script will plausibly RUN AGAIN. Ask that first. A one-time operation already performed fails no matter how destructive it was or how much was learned doing it - the zone is created, the host is provisioned, the data is migrated. Re-runs bounded by one piece of work fail the same way: a before/after measurement for one change, a check run until one ticket or migration lands, a harness proving one refactor - once that work closes nobody runs it again, so it belongs in a scratch directory or attached to the ticket, not in the checkout. A header, docstring or usage line that names the one ticket, PR or change it serves (before/after #N, until the cutover) is that case: ok=false, however reusable the code looks. The fact worth keeping then belongs in a doc, or in a comment at the thing it explains, not in a runnable file nobody will run. "Touches production" is not a licence on its own: almost every ops script touches something destructive, so that ground decides nothing unless the operation actually recurs.
15ok=false covers: a one-time setup or migration already run; a tool whose re-runs end when one ticket or change is done; a wrapper around a handful of obvious commands; a convenience alias; a thing whose whole body is a documented CLI invocation with the flags spelled out; anything whose value is 'so I do not have to type it again'.
16A long file is not automatically safe and a short one is not automatically doomed - a long reconciler earns its size by proving a delete is safe; a short wrapper around one tool's flags does not.
17Reason: name what makes it writable on demand or bounded to one piece of work, and where the one fact worth keeping should go instead. Under 50 words, no preamble.`
18
hooks/shared/paths.ts 24 lines
1const TEMP_ROOTS = ['/tmp/', '/private/tmp/', '/var/folders/', '/private/var/folders/']
2
3export const dirOf = (path: string) => {
4  const slash = path.lastIndexOf('/')
5  return slash > 0 ? path.slice(0, slash) : slash === 0 ? '/' : '.'
6}
7
8export const isDotfileOrTemp = (path: string, home: string | undefined, tmpdir: string | undefined) =>
9  (home !== undefined && path.startsWith(`${home}/.`)) ||
10  TEMP_ROOTS.some((root) => path.startsWith(root)) ||
11  (tmpdir !== undefined && tmpdir !== '' && path.startsWith(tmpdir))
12
13export const isTrim = (added: string, removed: string) => added.length < removed.length
14
15// `sh -c MEDIA_CHECK lean <path>` exits 0 for media and marketing work (a reel, a brand sheet): the file's own checkout
16// ignores it, or a folder between it and that checkout's root holds a .lean-skip marker. Run from the file's checkout,
17// a worktree under a main repo's ignored .worktrees/ still counts as code.
18export const MEDIA_CHECK = [
19  'd=$(dirname "$1"); while [ ! -d "$d" ]; do d=$(dirname "$d"); done; cd "$d" || exit 1',
20  'git check-ignore -q -- "$1" 2>/dev/null && exit 0',
21  'r=$(git rev-parse --show-toplevel 2>/dev/null) || exit 1; x=$(pwd -P)',
22  'while :; do [ -e "$x/.lean-skip" ] && exit 0; { [ "$x" = "$r" ] || [ "$x" = / ]; } && exit 1; x=$(dirname "$x"); done',
23].join('\n')
24
hooks/shared/verdict.ts 27 lines
1export const MODEL = 'claude-haiku-4-5-20251001'
2
3export const SYSTEM =
4  'You are a hook reviewer. Reply with one JSON object and nothing else: {"ok": true} or {"ok": false, "reason": "..."}.'
5
6export type Verdict = { ok: true } | { ok: false; reason: string }
7
8export type Review = { name: string; prompt: string; status: string }
9
10export const promptFor = (review: Review, input: object) => review.prompt.replace('$ARGUMENTS', () => JSON.stringify(input))
11
12export const verdictOf = (reply: string): Verdict | undefined => {
13  const json = reply.match(/\{[\s\S]*\}/)
14  if (!json) return undefined
15  let parsed: unknown
16  try {
17    parsed = JSON.parse(json[0])
18  } catch {
19    return undefined
20  }
21  if (typeof parsed !== 'object' || parsed === null || !('ok' in parsed) || typeof parsed.ok !== 'boolean') {
22    return undefined
23  }
24  if (parsed.ok) return { ok: true }
25  return { ok: false, reason: 'reason' in parsed && typeof parsed.reason === 'string' ? parsed.reason : '' }
26}
27