Picks low, medium or high effort for each prompt, keeping the prompt cache warm

A Claude Code mod that picks the effort level for each prompt you send. On a subscription, lower effort on easy turns means less thinking, so your usage limits last longer.
When you send a prompt, Haiku reads it along with the last six messages of the conversation and sorts it into one of three levels. Because of the context, a short prompt like "go ahead and implement it" is rated by the plan it refers to.
| Level | For |
|---|---|
low | Questions, explanations, chat, running a command, git chores. No file edits. |
medium | Ordinary code edits and multi-step work. |
high | Hard debugging, design, large refactors, or "still broken" after a failed attempt. |
During the turn the level can only rise, based on what Claude does:
medium.ExitPlanMode), or 15 steps, high.Edits made by subagents don't count. The next prompt starts from Haiku's pick again. A turn you didn't start, such as a background task finishing, keeps the previous level so effort doesn't flip back and forth. With context-meter installed, its band shows the current level; the mod draws nothing itself.
In automatic mode, Explore subagents run at low unless Claude asks for a specific effort. If you pinned a level or turned the mod off, they are left alone. A subagent starts with an empty context, so this costs no cache.
The mod never goes above high. If you set xhigh or max with /effort, or write "ultrathink", it leaves that turn alone.
Once any of your usage windows passes 80%, either the 5-hour or the 7-day one, turns the mod would run at high run at medium instead. context-meter then shows (budget) after the level. A level you pinned yourself isn't capped.
I checked about 40 effort switches across 40 sessions. Switching between low, medium and high kept the cached conversation every time, so raising the level partway through a turn costs nothing extra. Switching to or from max threw the cache away and rewrote 180-250k tokens. The mod never sets max or xhigh, so that cost only comes from /effort or ultrathink.
In case that changes, the mod still checks: if a switch writes more to the cache than it reads, you get a toast once. If it keeps appearing, run /auto-effort off.
/auto-effort show the current state
/auto-effort off stop changing effort
/auto-effort on back to automatic
/auto-effort high pin one level (low, medium or high)
/auto-effort budget 70 start budget mode at 70% instead of 80%
/auto-effort budget off turn budget mode off (budget on brings back 80%)
Each prompt costs one small Haiku call to classify it, with the last six messages included (up to 800 characters each).
/plugin install auto-effort --marketplace noash-xrc/claude-tools
Answer y to add the marketplace, then pick a scope.
claude plugin marketplace update noash-tools
claude plugin update auto-effort@noash-tools
Restart Claude Code to load the new version.
MIT
hooks/register.ts 140 lines1import { atom, update } from 'claude-code'
2import type { Register, SessionMessage } from 'claude-code'
3
4type Level = 'low' | 'medium' | 'high'
5
6// Haiku answers with one label verbatim; the word before the colon is the level.
7const LABELS = [
8 'low: a question, explanation, chat, running a command or a git chore, no file edits',
9 'medium: ordinary code edits or multi-step work',
10 'high: hard debugging, design, a large refactor, or a retry after a failed attempt',
11]
12const LEVELS: readonly string[] = ['low', 'medium', 'high']
13const RANK: Record<Level, number> = { low: 0, medium: 1, high: 2 }
14const EDITS = ['Edit', 'Write', 'MultiEdit', 'NotebookEdit']
15// context-meter reads this to show the effort the mod picked
16const effortAtom = atom({ plugin: 'auto-effort', key: 'effort' } as const, null)
17
18let mode: 'auto' | 'off' | Level = 'auto'
19// the newest prompt's level; a turn with no prompt of its own keeps it, so effort doesn't flap
20let level: Level | undefined
21let last: { model: string; effort: Level } | undefined
22let warned = false
23// what the current turn has done so far; it can only raise the level
24let turn: string | undefined
25let edited = new Set<string>()
26let planned = false
27// budget mode: past this share of any usage window, high turns run at medium
28let budget: number | 'off' = 80
29let used = 0
30const budgetOn = () => budget !== 'off' && used >= budget
31
32// "implement the plan above" says nothing alone, so Haiku also reads the last few messages
33const clip = (s: string, n: number) => (s.length > n ? `${s.slice(0, n / 2)}\n…\n${s.slice(-n / 2)}` : s)
34const describe = (m: SessionMessage) =>
35 `${m.role}: ${clip(m.text, 800)}${m.toolUses.length ? ` [${m.toolUses.map(t => t.name).join(', ')}]` : ''}`
36const withContext = (prompt: string, messages: SessionMessage[]) => {
37 const before = messages.slice(-6).map(describe).join('\n\n')
38 const ask = `Rate the work the new prompt asks for.\n\nNew prompt:\n${clip(prompt, 4000)}`
39 return before ? `Conversation so far:\n${before}\n\n${ask}` : ask
40}
41
42// edits to several files, a plan being carried out, or a long run of steps mean the turn is bigger than its prompt
43const observed = (index: number): Level =>
44 edited.size >= 4 || planned || index >= 15 ? 'high' : edited.size > 0 ? 'medium' : 'low'
45
46export const register: Register = on => {
47 on('session.start', async ($, e, next) => {
48 await $.command.register({
49 name: 'auto-effort',
50 description: 'Show or set automatic effort: on, off, pin low|medium|high, or budget on|off|<percent>',
51 argumentHint: '[on | off | low | medium | high | budget on|off|<percent>]',
52 })
53 return next(e)
54 })
55
56 on('command.run', { command: 'auto-effort' }, async ($, e) => {
57 const arg = e.args.trim().toLowerCase().replace(/^pin\s+/, '')
58 const b = /^budget(?:\s+(on|off|\d{1,3})%?)?$/.exec(arg)
59 if (b) budget = b[1] === 'off' ? 'off' : b[1] === 'on' || !b[1] ? 80 : Math.min(100, Number(b[1]))
60 else if (arg === 'on') mode = 'auto'
61 else if (arg === 'off' || LEVELS.includes(arg)) mode = arg as typeof mode
62 else if (arg) return { text: `Unknown argument "${arg}". Use on, off, low, medium or high.` }
63 if (mode === 'off') await update($, effortAtom, () => null)
64 const now = mode === 'auto' ? `on${level ? `, last pick ${level}` : ''}` : mode === 'off' ? 'off' : `pinned to ${mode}`
65 const limit = budget === 'off' ? 'off' : `at ${budget}%, ${Math.round(used)}% of the fullest usage window used`
66 return { text: `auto-effort is ${now}. Budget mode is ${limit}.` }
67 })
68
69 // Typed prompts only: a message delivered into a running turn shouldn't re-pick its effort.
70 on('prompt.submit', async ($, e, next) => {
71 if (mode === 'auto' && e.turnId === undefined && !e.text.startsWith('/')) {
72 const messages = await $.session.messages().catch(() => [])
73 const label = await $.model.classify(withContext(e.text, messages), LABELS, { model: 'haiku' }).catch(() => undefined)
74 const picked = label?.split(':')[0]
75 // a failed or garbled answer clears the last prompt's pick, so the default applies
76 level = picked && LEVELS.includes(picked) ? (picked as Level) : undefined
77 }
78 return next(e)
79 }).catch(($, e, next) => next(e))
80
81 // rateLimits is the whole list each time, so the fullest window is recomputed, not accumulated
82 on('session.measure', ($, e, next) => {
83 used = Math.max(0, ...e.rateLimits.map(r => r.percentUsed))
84 return next(e)
85 })
86
87 // Search subagents start with no context, so a lower effort there loses no cache.
88 on('tool.call', { tool: 'Agent' }, ($, e, next) =>
89 mode === 'auto' && e.subagent_type === 'Explore' && e.effort === undefined ? next({ ...e, effort: 'low' }) : next(e),
90 ).catch(($, e, next) => next(e))
91
92 // Only the main loop's tools count: a subagent's edits don't make the main turn harder.
93 on('tool.call', ($, e, next) => {
94 if (e.agentId === undefined) {
95 const { file_path, notebook_path } = e as { file_path?: string; notebook_path?: string }
96 const file = file_path ?? notebook_path
97 if (EDITS.includes(e.tool) && file) edited.add(file)
98 if (e.tool === 'ExitPlanMode') planned = true
99 }
100 return next(e)
101 })
102
103 on('turn.step', async function* ($, e, next) {
104 // xhigh, max or a number came from /effort or ultrathink: more than the mod would pick, so it stands
105 if (e.agentId !== undefined || mode === 'off') return yield* next(e)
106 if (!LEVELS.includes(String(e.effort))) {
107 // stand aside, and clear the last pick so the band shows the effort this step really runs at
108 await update($, effortAtom, () => null)
109 return yield* next(e)
110 }
111 if (e.turnId !== turn) {
112 turn = e.turnId
113 edited = new Set()
114 planned = false
115 }
116 // Switches among low, medium and high kept the cache in real sessions, so rising mid-turn is cheap.
117 const seen = observed(e.index)
118 const auto = (seen === 'low' || (level && RANK[level] >= RANK[seen])) ? level : seen
119 // a pin is the person's choice, so budget mode only caps automatic picks
120 const effort = mode !== 'auto' ? mode : auto === 'high' && budgetOn() ? 'medium' : auto
121 if (!effort) {
122 await update($, effortAtom, () => null)
123 return yield* next(e)
124 }
125
126 await update($, effortAtom, () => `${effort}${mode !== 'auto' ? ' (pinned)' : budgetOn() ? ' (budget)' : ''}`)
127 const result = yield* next({ ...e, effort })
128
129 // Writing more than it read right after a switch means the change went out top-level and rebuilt the cache.
130 const u = result.usage
131 const switched = last !== undefined && last.model === e.model && last.effort !== effort
132 if (switched && u && !warned && u.cache_creation_input_tokens > u.cache_read_input_tokens) {
133 warned = true
134 $.ui.toast(`auto-effort: switching to ${effort} rebuilt the prompt cache. If this keeps happening, run /auto-effort off.`)
135 }
136 last = { model: e.model, effort }
137 return result
138 })
139}
140types/index.d.ts 9 lines1// the effort the last main-thread step ran at, with " (pinned)" or " (budget)"; null while the mod stands aside
2export type AutoEffortEffort = string | null
3
4declare module 'claude-code' {
5 interface PluginState {
6 'auto-effort': { effort: AutoEffortEffort }
7 }
8}
9