SLOPSHOPPER

effort-phase

Sets main-loop effort per model request from the phase of the skill flow (judgment, mechanical, polling) and writes a per-step usage ledger

statusprompt
★ 1v0.1.0MITupdated 2026-10-10alienfast/claude/mods/effort-phase
A shopper browsing a rack in a slop shop
README

effort-phase

A hooks-only mod that sets the main loop's effort per model request from the phase of the skill flow, and writes one ledger row per request. Subagent requests are never touched.

Lanes

LaneWhenDefault effort
judgmentThe turn's default, and again after any skill not listed as mechanical expands (start, spec, quality-review, auto, full, do, ...)the session's own (session)
mechanicalAfter a mechanical skill expands in the turn (finish, checkpoint, pr-update, exec-summary, merge-queue, reap-worktrees, reap-tmp, update, fleet-status, fleet-stop), and for the one request that follows a Bash command naming finish-*.sh, linear-post.sh, linear-set-state.sh, mark-ready-for-release.sh, or git pushhigh
pollingThe request that follows a step made only of wait-shaped tool calls (Monitor, ScheduleWakeup, TaskStop, or a Bash command with sleep, until [, tail -f, wait)low

The phase resets to judgment when a main-loop turn completes, not when one starts: a typed /finish expands before turn.start fires, so a reset there would undo the phase the skill had just set (the first live run showed every step left in judgment for that reason). The signal is the skill.prompt event, which fires whether the skill was typed as /finish or called through the Skill tool, so no text classifier and no model call is involved.

Configuration

userConfig in .claude-plugin/plugin.json: enabled, judgment_effort (session or a level), mechanical_effort, polling_effort, max_switches_per_turn (0 = unlimited), ledger. The effort-probe mod measured an effort switch as cache-safe on Opus 5.5 with Claude Code 2.1.295, which is why the cap ships at 0.

Ledger

<session root>/tmp/effort-ledger-<sessionId>.jsonl, one row per main-loop request:

{"ts":"...","session":"...","event":"step","turnId":"...","index":3,"lane":"mechanical","effortIn":"xhigh","effortOut":"high","model":"claude-opus-5-5[1m]","answeredBy":"claude-opus-5-5","usage":{"input_tokens":2,"output_tokens":74,"cache_read_input_tokens":59638,"cache_creation_input_tokens":3644,"model":"claude-opus-5-5"},"tools":["Bash"],"commands":["git push origin main"]}

Each skill expansion adds a skill row ({"event":"skill","skill":"finish","lane":"mechanical"}), which the retro skips when counting requests. The root is resolved once at session start, so a later worktree move does not split the file. The reaper ages it out with ordinary scratch.

Loading

Installed user-wide by update.sh on every machine that pulls the repo, and loaded in place from this folder, so an edit takes effect at the next session start or /reload-plugins. On a machine without the install, claude --plugin-dir ~/.claude/mods/effort-phase loads it for one session. The retro reads the ledger: fleet-metrics.py reports an Effort lanes line, effort_lanes in its JSON, and a rewr% column in the cross-run trend.

Checks

claude plugin validate mods/effort-phase
claude plugin test mods/effort-phase
mods/typecheck.sh mods/effort-phase
Source 2 files
hooks/register.ts 89 lines
1import type { Register } from 'claude-code'
2import { POLL_STREAK, commandsOf, dotGitOf, effortFor, isMechanicalCommand, isWaitShaped, owningCheckout, phaseForSkill, readOptions, type Lane, type Phase } from './phase'
3
4let phase: Phase = 'judgment'
5let waitStreak = 0
6let mechanicalNext = false
7let lastSent: unknown = undefined
8let switches = 0
9let sessionId = ''
10let ledgerPath = ''
11let rows: string[] = []
12let active = false
13
14type Writer = { readonly fs: { readonly write: (path: string, text: string) => Promise<void> } }
15
16async function record($: Writer, row: Record<string, unknown>): Promise<void> {
17  if (!active) return
18  rows.push(JSON.stringify({ ts: new Date().toISOString(), session: sessionId, ...row }))
19  await $.fs.write(ledgerPath, rows.join('\n') + '\n')
20}
21
22export const register: Register = (on, options) => {
23  const opts = readOptions(options)
24  active = opts.enabled && opts.ledger
25
26  on('session.start', async ($, e, next) => {
27    sessionId = await $.session.id()
28    if (active) {
29      // Resolved once, to the owning checkout: a worktree move later in the session, or a resume inside one, would otherwise split
30      // the ledger across two tmp/ dirs.
31      const reported = await $.session.root()
32      ledgerPath = `${owningCheckout(reported, await dotGitOf((path) => $.fs.read(path), reported))}/tmp/effort-ledger-${sessionId}.jsonl`
33      if (await $.fs.exists(ledgerPath)) rows = (await $.fs.read(ledgerPath)).split('\n').filter((line) => line !== '')
34    }
35    return next(e)
36  })
37
38  on('turn.start', async ($, e, next) => {
39    waitStreak = 0
40    mechanicalNext = false
41    lastSent = undefined
42    switches = 0
43    return next(e)
44  })
45
46  // A typed `/finish` expands before turn.start, so the phase is reset when the turn ends, never when it begins.
47  on('turn.complete', async ($, e, next) => {
48    if (e.agentId === undefined) phase = 'judgment'
49    return next(e)
50  })
51
52  on('skill.prompt', async ($, e, next) => {
53    const next_ = phaseForSkill(e.skill)
54    if (next_ !== phase) {
55      phase = next_
56      if (opts.enabled) $.ui.status(`effort-phase: ${phase} (${e.skill})`)
57    }
58    await record($, { event: 'skill', skill: e.skill, lane: phase })
59    return next(e)
60  })
61
62  on('turn.step', async function* ($, e, next) {
63    if (e.agentId !== undefined || !opts.enabled) return yield* next(e)
64    const lane: Lane = waitStreak >= POLL_STREAK ? 'polling' : mechanicalNext ? 'mechanical' : phase
65    const want = effortFor(lane, opts.map, e.effort) ?? e.effort
66    let effortOut = want
67    if (opts.cap > 0 && lastSent !== undefined && want !== lastSent && switches >= opts.cap) effortOut = lastSent as typeof want
68    if (lastSent !== undefined && effortOut !== lastSent) switches += 1
69    const result = yield* next(effortOut === e.effort ? e : { ...e, effort: effortOut })
70    lastSent = effortOut
71    waitStreak = isWaitShaped(result.toolUses) ? waitStreak + 1 : 0
72    mechanicalNext = isMechanicalCommand(result.toolUses)
73    await record($, {
74      event: 'step',
75      turnId: e.turnId,
76      index: e.index,
77      lane,
78      effortIn: e.effort ?? null,
79      effortOut: effortOut ?? null,
80      model: e.model,
81      answeredBy: result.usage?.model ?? null,
82      usage: result.usage,
83      tools: result.toolUses.map((t) => t.name),
84      commands: commandsOf(result.toolUses),
85    })
86    return result
87  })
88}
89
hooks/phase.ts 120 lines
1export type Phase = 'judgment' | 'mechanical'
2export type Lane = Phase | 'polling'
3export type Effort = 'low' | 'medium' | 'high' | 'xhigh' | 'max'
4export type ToolUse = { readonly name: string; readonly input: unknown }
5
6export const EFFORTS: readonly Effort[] = ['low', 'medium', 'high', 'xhigh', 'max']
7
8// The checkout a ledger belongs to. A session resumed inside a /start wt worktree reports the worktree as its root — measured
9// 2026-10-10: three fleet sessions resumed at 14:22Z wrote their later rows under <worktree>/tmp, where /finish deletes them and
10// fleet-metrics.py never looked — so a linked worktree (its `.git` is a file naming the owning repo's worktrees dir) resolves to
11// the checkout that owns it. Anything else, a main checkout's `.git` directory included, keeps the root as reported.
12export function owningCheckout(root: string, dotGit: string | null): string {
13  const target = /^gitdir:\s*(.+?)\s*$/m.exec(dotGit ?? '')?.[1]
14  if (target === undefined) return root
15  const gitdir = (/^(?:\/|[A-Za-z]:[\\/])/.test(target) ? target : `${root}/${target}`).replace(/\\/g, '/')
16  const at = gitdir.indexOf('/.git/worktrees/')
17  if (at === -1) return root
18  const out: string[] = []
19  for (const seg of gitdir.slice(0, at).split('/')) {
20    if (seg === '..') out.pop()
21    else if (seg !== '.' && (seg !== '' || out.length === 0)) out.push(seg)
22  }
23  return out.join('/')
24}
25
26// A main checkout's `.git` is a directory, which the read rejects; a linked worktree's is a one-line file.
27export async function dotGitOf(read: (path: string) => Promise<string>, root: string): Promise<string | null> {
28  try {
29    return await read(`${root}/.git`)
30  } catch {
31    return null
32  }
33}
34
35// Skills whose expansion marks the rest of the turn as bookkeeping: Linear posts, git, merges, reaping. Everything else
36// (start, spec, quality-review, auto, full, do, ...) is judgment, so an unknown skill never lowers effort.
37export const MECHANICAL_SKILLS: ReadonlySet<string> = new Set([
38  'finish',
39  'checkpoint',
40  'pr-update',
41  'exec-summary',
42  'merge-queue',
43  'reap-worktrees',
44  'reap-tmp',
45  'update',
46  'fleet-status',
47  'fleet-stop',
48])
49
50export function phaseForSkill(skill: string): Phase {
51  return MECHANICAL_SKILLS.has(skill) ? 'mechanical' : 'judgment'
52}
53
54// The polling lane needs this many consecutive wait-shaped steps first: the step right after a single wait is usually
55// the one that reads the result and acts on it, and only a sustained loop is the blind-sleep signature.
56export const POLL_STREAK = 2
57
58const WAIT_TOOLS: ReadonlySet<string> = new Set(['Monitor', 'ScheduleWakeup', 'TaskStop'])
59// A wait as a command of its own, at the start or after a separator, so `grep wait file` or a path carrying the word does not match.
60const WAIT_COMMAND = /(^|[;&|(]\s*)(do\s+|then\s+)?(sleep\s+\d|until\s+\[|tail\s+-f|wait\b)/
61
62function commandOf(input: unknown): string {
63  if (typeof input !== 'object' || input === null) return ''
64  const command = (input as { command?: unknown }).command
65  return typeof command === 'string' ? command : ''
66}
67
68export function isWaitShaped(uses: readonly ToolUse[]): boolean {
69  if (uses.length === 0) return false
70  return uses.every((u) => WAIT_TOOLS.has(u.name) || (u.name === 'Bash' && WAIT_COMMAND.test(commandOf(u.input))))
71}
72
73// A bookkeeping command outside any mechanical skill (a Linear post from /start, a push from an interactive turn):
74// the request that reads its result is mechanical, and the one after that returns to the phase.
75const MECHANICAL_COMMAND = /(^|[\s\/;&|(])(finish-[a-z-]+\.sh|linear-post\.sh|linear-set-state\.sh|mark-ready-for-release\.sh)\b|\bgit\s+push\b/
76
77export function isMechanicalCommand(uses: readonly ToolUse[]): boolean {
78  return uses.some((u) => u.name === 'Bash' && MECHANICAL_COMMAND.test(commandOf(u.input)))
79}
80
81export function commandsOf(uses: readonly ToolUse[]): string[] {
82  return uses.filter((u) => u.name === 'Bash').map((u) => commandOf(u.input).slice(0, 160))
83}
84
85export type EffortMap = {
86  readonly judgment: Effort | 'session'
87  readonly mechanical: Effort
88  readonly polling: Effort
89}
90
91export function effortFor(lane: Lane, map: EffortMap, session: Effort | number | undefined): Effort | number | undefined {
92  const pick = map[lane]
93  return pick === 'session' ? session : pick
94}
95
96export function asEffort(value: unknown, fallback: Effort): Effort {
97  return typeof value === 'string' && (EFFORTS as readonly string[]).includes(value) ? (value as Effort) : fallback
98}
99
100export type Options = {
101  readonly enabled: boolean
102  readonly map: EffortMap
103  readonly cap: number
104  readonly ledger: boolean
105}
106
107export function readOptions(raw: Readonly<Record<string, unknown>>): Options {
108  const judgment = raw.judgment_effort
109  return {
110    enabled: raw.enabled !== false,
111    map: {
112      judgment: typeof judgment === 'string' && (EFFORTS as readonly string[]).includes(judgment) ? (judgment as Effort) : 'session',
113      mechanical: asEffort(raw.mechanical_effort, 'high'),
114      polling: asEffort(raw.polling_effort, 'low'),
115    },
116    cap: typeof raw.max_switches_per_turn === 'number' && raw.max_switches_per_turn > 0 ? Math.floor(raw.max_switches_per_turn) : 0,
117    ledger: raw.ledger !== false,
118  }
119}
120