Model and thinking effort pickers for the main agent, above the prompt

Pick the model and thinking effort, right above the prompt.
Opus 5.5 ▾ high ▾
/plugin install model-info --marketplace katipally/modz
Update, then restart your sessions (more in the main README):
claude plugin marketplace update modz
claude plugin update model-info@modz
/config's Model row offers your account. Picking one runs Claude Code's own /model./effort offers for the current model, and refreshes after a model switch. Picking one runs /effort./effort says so in a toast.effortLevel from your settings. Until the model is known the tile reads model – · effort –.hooks/register.tsx 182 lines1import { atom, read, update } from 'claude-code'
2import type { Register, BoxProps, ElementConstructor, EngineInterface, RenderElement, RenderNode, SelectOption } from 'claude-code'
3
4import type { Choices, Info } from '../types'
5
6const info = atom({ plugin: 'model-info', key: 'info' } as const, null)
7const choices = atom({ plugin: 'model-info', key: 'choices' } as const, { models: [], efforts: [] })
8const isConfirmed = atom({ plugin: 'model-info', key: 'isConfirmed' } as const, false)
9const openMenu = atom({ plugin: 'model-info', key: 'openMenu' } as const, null)
10const CONFIRM_MS = 1500
11
12const confirm = async ($: EngineInterface) => {
13 await update($, isConfirmed, () => true)
14 $.clock.after(CONFIRM_MS, () => void update($, isConfirmed, () => false))
15}
16const TINT = 'merged'
17
18// /effort's hint reads like "[low|medium|high|max|auto|ultracode [on|off]]": its bare words are the levels.
19const levelsOf = (hint: string) => hint.replace(/^[[<]|[\]>]$/g, '').split('|').filter(w => /^[a-z]+$/.test(w))
20const title = (alias: string) => alias[0]!.toUpperCase() + alias.slice(1)
21
22// "claude-opus-5-5" reads "Opus 5.5"; an id in another shape is shown as given.
23const modelName = (id: string) => {
24 const m = /claude-([a-z]+)-(\d+)(?:-(\d{1,2}))?(?![\d])/.exec(id)
25 return m ? `${m[1]![0]!.toUpperCase()}${m[1]!.slice(1)} ${m[2]}${m[3] ? `.${m[3]}` : ''}` : id
26}
27
28// Every modz mod places its tile in one shared band: a lead column (the bot), then a column of tiles, then an optional
29// right column. A column with no tiles is not drawn, and columns wrap under each other when the width runs out.
30const BAND = 'modz-band'
31const SLOTS: Record<string, 'lead' | 'left' | 'right'> = {
32 buddy: 'lead',
33 'usage-limits': 'left',
34 'cache-timer': 'left',
35 'model-info': 'left',
36 orchestrator: 'left',
37}
38const ORDER = Object.keys(SLOTS)
39const keyOf = (n: RenderNode) => (typeof n !== 'string' && n.type === 'Box' ? String(n.props?.key ?? '') : '')
40const rank = (n: RenderNode) => {
41 const i = ORDER.indexOf(keyOf(n))
42 return i < 0 ? ORDER.length : i
43}
44const pack = (Box: ElementConstructor<BoxProps>, below: RenderElement, tile: RenderElement) => {
45 const isEmpty = below.type === 'Box' && !below.children?.length
46 const tiles = keyOf(below) === BAND
47 ? (below.type === 'Box' ? below.children ?? [] : []).flatMap(col => (typeof col !== 'string' && col.type === 'Box' ? col.children ?? [] : [col]))
48 : isEmpty ? [] : [below]
49 const all = [...tiles, tile].sort((a, b) => rank(a) - rank(b))
50 const [lead, left, right] = (['lead', 'left', 'right'] as const).map(slot => all.filter(n => (SLOTS[keyOf(n)] ?? 'left') === slot))
51 return (
52 <Box key={BAND} flexDirection="row" flexWrap="wrap" columnGap={3}>
53 {lead!.length > 0 && <Box key="modz-lead" flexDirection="column" justifyContent="center">{lead}</Box>}
54 {left!.length > 0 && <Box key="modz-left" flexDirection="column" flexGrow={right!.length > 0 ? 1 : 0}>{left}</Box>}
55 {right!.length > 0 && <Box key="modz-right" flexDirection="column" alignItems="flex-end">{right}</Box>}
56 </Box>
57 )
58}
59
60
61// The session binds around session.start, so these reads wait for next(e) and a rejected one is retried a few times.
62// The model row of /config lists what this account can pick; listing the commands asks /effort for its hint.
63// The engine has no effort getter, so the configured level shows until the first turn reports the live one.
64const RETRY_MS = 2000
65const RETRIES = 3
66const load = async ($: EngineInterface) => {
67 const [model, settings, rows, commands] = await Promise.allSettled([$.session.model(), $.settings.read(), $.config.list(), $.command.list()])
68 if (model.status === 'fulfilled') {
69 const level = settings.status === 'fulfilled' ? settings.value.effortLevel : undefined
70 await update($, info, i => ({ ...i, model: model.value, effort: i?.effort ?? (typeof level === 'string' ? level : undefined) }))
71 }
72 if (rows.status === 'fulfilled') {
73 const options = rows.value.find(r => r.key === 'model')?.options ?? []
74 await update($, choices, c => ({ ...c, models: [...options] }))
75 }
76 return [model, rows, commands].every(r => r.status === 'fulfilled')
77}
78const start = async ($: EngineInterface, attempt = 0) => {
79 if (!(await load($)) && attempt < RETRIES) $.clock.after(RETRY_MS, () => void start($, attempt + 1).catch(err => $.ui.log(`model-info: ${err}`, { to: 'debug' })))
80}
81
82export const register: Register = on => {
83 on('session.start', async ($, e, next) => {
84 const started = await next(e)
85 await start($)
86 return started
87 })
88
89 // The classic start event names the model before the session binds, and a resumed or forked session may run another than
90 // the tile last showed. Not where an organization manages Claude Code; there the model read above is the first source.
91 on('classic.SessionStart', async ($, e, next) => {
92 const started = await next(e)
93 const model = e.model
94 if (model) await update($, info, i => ({ ...i, model }))
95 return started
96 }).catch(($, e, next) => next(e))
97
98 on('command.describe', { command: 'effort' }, async ($, e, next) => {
99 if (e.argumentHint) {
100 const efforts = levelsOf(e.argumentHint)
101 await update($, choices, c => ({ ...c, efforts }))
102 }
103 return next(e)
104 })
105
106 on('turn.step', async function* ($, e, next) {
107 if (e.agentId === undefined) {
108 await update($, info, () => ({ model: e.model, effort: e.effort === undefined ? undefined : String(e.effort) }))
109 }
110 return yield* next(e)
111 })
112
113 on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
114 const below = await next(e)
115 if (e.props.hasSurvey) return below
116 const [i, c, ok, menu] = await Promise.all([read($, info), read($, choices), read($, isConfirmed), read($, openMenu)])
117 const elements = $.ui.resolve(e)
118 const { Box, Text } = elements
119 if (!i) return pack(Box, below, <Box key="model-info" flexDirection="row"><Text dimColor>model – · effort –</Text></Box>)
120
121 // Both run Claude Code's own /model and /effort, so the change is the session's, not a display.
122 const run = async (command: string, args: string) => {
123 const { text } = await $.command.run({ command, args })
124 if (text) $.ui.toast(text)
125 }
126 const setModel = async (alias: string) => {
127 await run('model', alias)
128 const model = await $.session.model()
129 await update($, info, cur => ({ ...cur, model }))
130 await $.command.list()
131 await confirm($)
132 }
133 const setEffort = async (effort: string) => {
134 await run('effort', effort)
135 await update($, info, cur => ({ model: cur?.model ?? i.model, effort }))
136 await confirm($)
137 }
138
139 const plain = (
140 <Box key="model-info" flexDirection="row">
141 <Text bold color={TINT}>{modelName(i.model)}</Text>
142 {i.effort && <Text dimColor> · {i.effort}</Text>}
143 </Box>
144 )
145 if (!('Select' in elements)) return pack(Box, below, plain)
146 const { Button, Select } = elements
147 // In the terminal a Select answers only the keyboard, so there a dropdown is a button that opens a row of
148 // option buttons a click can pick from; every other surface keeps its native Select.
149 const dropdown = (key: string, value: string | undefined, options: readonly SelectOption[], onSelect: (v: string) => unknown) => {
150 if (e.surface !== 'terminal') return <Select key={key} value={value} options={options} onSelect={onSelect} />
151 const isShown = menu === key
152 const labelOf = (v: string | undefined) => options.find(o => o.value === v)?.label ?? v ?? '…'
153 return (
154 <Box flexDirection="row" columnGap={1}>
155 <Button key={key} plain label={`${labelOf(value)} ${isShown ? '▴' : '▾'}`} onPress={() => update($, openMenu, m => (m === key ? null : key))} />
156 {isShown && options.filter(o => o.value !== value).map(o => (
157 <Button key={`${key}:${o.value}`} plain dimColor label={o.label ?? o.value} onPress={async () => {
158 await update($, openMenu, () => null)
159 await onSelect(o.value)
160 }} />
161 ))}
162 </Box>
163 )
164 }
165
166 // The alias the current model answers to; "default" only when nothing more specific matches.
167 const current = c.models.find(a => a !== 'default' && i.model.includes(a.replace(/\[.*\]$/, ''))) ?? i.model
168 const models = c.models.includes(current) ? c.models : [current, ...c.models]
169 const efforts = !i.effort || c.efforts.includes(i.effort) ? c.efforts : [i.effort, ...c.efforts]
170
171 return pack(Box, below, (
172 <Box key="model-info" flexDirection="row" flexWrap="wrap" columnGap={2}>
173 {dropdown('model', current, models.map(a => ({ value: a, label: a === current ? modelName(i.model) : title(a) })), setModel)}
174 {efforts.length > 0
175 ? dropdown('effort', i.effort, efforts.map(level => ({ value: level })), setEffort)
176 : i.effort && <Text dimColor>{i.effort}</Text>}
177 {ok && <Text color="success">✓</Text>}
178 </Box>
179 ))
180 })
181}
182types/index.d.ts 10 lines1export type Info = { model: string; effort?: string }
2
3export type Choices = { models: string[]; efforts: string[] }
4
5declare module 'claude-code' {
6 interface PluginState {
7 'model-info': { info: Info | null; choices: Choices; isConfirmed: boolean; openMenu: string | null }
8 }
9}
10