SLOPSHOPPER

palette

A side pane listing the session's agents, skills and commands; click one to put it in the prompt box.

panebandcommandtoastpromptagents
v0.4.2Apache-2.0updated 2026-10-14vampik33/claude-plugins/plugins/palette
A shopper browsing a rack in a slop shop
Preview · a replayed session in a sandbox
claude · ~/work/app · palette
│ ┃ Palette ✕ › fix the failing auth test and add an audit log call │ ┃ Click to put it in the prompt ↻ │ ┃ ⏺ Read(src/auth.ts) │ ┃ Search: : type to filter ⏎ put first ⎿ Read 6 lines │ ┃ ⏺ Update(src/auth.ts) │ ┃ ▾ undefined (1) ⎿ Added 2 lines, removed 1 line │ ┃ ⏺ Bash(bun test) │ ┃ /palette ⎿ 3 pass, 1 fail │ ┃ Show or hide the pane listing this sessi │ ● Done. refresh now rejects expired claims and logs an audit event. │ │ ✻ Worked for 42s · done 4:20 PM │ │ › /palette │ ⎿ palette: Palette opened. │ │ ⟨Claude Code's own drawing⟩ palette [ hide ] ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── › ? for shortcuts

Draws

Band
⟨Claude Code's own drawing⟩ palette [ hide ]
Pane · Palette
Click to put it in the prompt ↻ Search: : type to filter ⏎ put first ▾ undefined (1) /palette Show or hide the pane listing this session's agents…
README

palette

A side pane listing this session's agents, skills and commands. Click one to put it in the prompt box, ready to finish and send.

Click to put it in the prompt ↻

Search: type to filter

▾ most used (2)

  /think
    Meta-cognitive reasoning …

  @rust-engineer
    Expert Rust developer …

▾ project (2)

  @reviewer
    Reviews diffs for …

  /deploy
    Deploy the current branch

▸ plugin:hookify (5)

Installation

claude plugin install palette@vampik-plugins

Behaviour

  • /palette shows or hides the pane, with the keyboard on the search field so you can type right away. It docks beside the transcript in the fullscreen layout (110+ columns), inline above the prompt otherwise.
  • A palette show line always sits above the prompt: show / hide toggles the pane (hotkey p once the band has the keys, ctrl+x tab or a click).
  • A command or skill goes to the start of the prompt as /<name> (a slash command only runs from there), replacing a leading command and keeping the rest of your draft.
  • An agent goes in at the cursor as @agent-<name> .
  • Nothing is sent: you finish the prompt and press Enter.
  • Type in the search field (click it, or focus the pane) to filter: an item stays when its name or description holds every word you typed, any case. Groups with no match hide, folded ones with a match open. Enter puts the first match in the prompt; ✕ clears the search.
  • Click a group header to fold it; ↻ re-reads the lists (after /reload-plugins, say).

Groups: most used on top (the 10 items used most, also still listed under their source), then project (.claude/ in the project root), user, one per plugin, and mcp. Built-in commands and agents are left out.

How It Works

Commands and skills come from $.command.list(); custom agents from the context breakdown of $.session.usage(). That listing has no agent descriptions: they fill in from agent.offer once the model has been offered the agents (after the first prompt). A user-source item is put under project when .claude/commands/<name>.md or .claude/skills/<name>/SKILL.md exists under the project root.

Uses are counted from command.run, skill.prompt and agent.spawn (so a skill the model calls through the Skill tool, or an agent it spawns, counts too) and kept in the plugin's $.store, shared by every session. A typed skill raises both command.run and skill.prompt: a second use of one item within 5 seconds is not counted.

Where an organization manages Claude Code, skill.prompt runs only for plugins the organization lists, so there a skill the model calls is not counted; a typed /skill still is, through command.run.

Needs function hooks (CLAUDE_CODE_ENABLE_FUNCTION_HOOKS=1).

Source 3 files
hooks/register.tsx 296 lines
1import { atom, read, update } from "claude-code";
2import type { EngineInterface, Register } from "claude-code";
3
4import type { PaletteGroup, PaletteItem, Usage } from "../types";
5import {
6  buildGroups,
7  filterGroups,
8  fillFor,
9  label,
10  MOST_USED,
11  mostUsed,
12  projectPaths,
13  recordUse,
14} from "./core.ts";
15
16const PANE = "palette";
17const SEARCH = "palette-search";
18const SELF = "palette";
19
20const groups = atom(
21  { plugin: "palette", key: "groups" } as const,
22  [] as PaletteGroup[],
23);
24const pane = atom({ plugin: "palette", key: "pane" } as const, false);
25const folded = atom(
26  { plugin: "palette", key: "folded" } as const,
27  [] as string[],
28);
29const agentInfo = atom(
30  { plugin: "palette", key: "agentInfo" } as const,
31  {} as Record<string, string>,
32);
33const usage = atom({ plugin: "palette", key: "usage" } as const, {} as Usage);
34const USAGE = "usage";
35const query = atom({ plugin: "palette", key: "query" } as const, "");
36
37const stored = async ($: EngineInterface) =>
38  ((await $.store.get(USAGE)) as Usage | undefined) ?? {};
39
40/** Counts one use in the store (shared by every session) and in `usage`. */
41async function addUse($: EngineInterface, key: string): Promise<void> {
42  const was = await stored($);
43  const now = recordUse(was, key, await $.clock.now());
44  if (now !== was) await $.store.set(USAGE, now);
45  await update($, usage, () => now);
46}
47
48// one at a time, so parallel spawns don't overwrite each other's count
49let counting = Promise.resolve();
50function countUse($: EngineInterface, key: string): Promise<void> {
51  counting = counting.then(() => addUse($, key)).catch(() => {});
52  return counting;
53}
54
55/** Reads the session's commands, skills and custom agents into `groups`. */
56async function refresh($: EngineInterface): Promise<void> {
57  const commands = await $.command.list().catch(() => []);
58  const usage = await $.session
59    .usage({ breakdown: "summary" })
60    .catch(() => undefined);
61  const agents = usage?.context.breakdown?.agents ?? [];
62  // the project's .claude/ lies under its root, not wherever the session went
63  const root = await $.session.root();
64  const local = await Promise.all(
65    commands
66      .filter((c) => c.source === "user")
67      .map(async (c) => {
68        const hits = await Promise.all(
69          projectPaths(c.name).map((p) =>
70            $.fs.exists(`${root}/${p}`).catch(() => false),
71          ),
72        );
73        return hits.some(Boolean) ? c.name : undefined;
74      }),
75  );
76  const projectNames = new Set(local.filter((n) => n !== undefined));
77  await update($, groups, () =>
78    buildGroups(commands, agents, projectNames, SELF),
79  );
80}
81
82async function openPane($: EngineInterface) {
83  // focus is granted only over an empty prompt; the search field takes it (autoFocus)
84  const opened = await $.ui.open({ id: PANE, title: "Palette", focus: true });
85  await update($, pane, () => opened.isPlaced);
86  await refresh($);
87  return opened;
88}
89
90/** Closes the pane if the stored state says open, opens it if not. */
91async function togglePane($: EngineInterface) {
92  if (await read($, pane)) {
93    await $.ui.close({ id: PANE });
94    await update($, pane, () => false);
95    return undefined;
96  }
97  return openPane($);
98}
99
100async function clearSearch($: EngineInterface) {
101  await update($, query, () => "");
102  // the ✕ goes with the text: give the keys back to the field
103  await $.ui.focus({ requestId: PANE, key: SEARCH }).catch(() => {});
104}
105
106async function press($: EngineInterface, item: PaletteItem) {
107  const box = await $.prompt.read();
108  const filled = await $.prompt.fill(fillFor(item, box.text, box.cursor));
109  if (!filled.isFilled)
110    $.ui.toast(`palette: the prompt box did not take ${label(item)}`);
111}
112
113export const register: Register = (on) => {
114  on("session.start", async ($, e, next) => {
115    const r = await next(e);
116    await $.command.register({
117      name: "palette",
118      description:
119        "Show or hide the pane listing this session's agents, skills and commands",
120    });
121    // a reload keeps an open pane
122    const panes = await $.ui.panes().catch(() => []);
123    const isOpen = panes.some((p) => p.id === PANE && p.isPlaced);
124    await update($, pane, () => isOpen);
125    const kept = await stored($).catch(() => ({}));
126    await update($, usage, () => kept);
127    if (isOpen) await refresh($);
128    return r;
129  });
130
131  on("command.run", { command: "palette" }, async ($) => {
132    const opened = await togglePane($);
133    return {
134      text: !opened
135        ? "Palette closed."
136        : opened.isPlaced
137          ? "Palette opened."
138          : "Palette is waiting for a wider terminal.",
139    };
140  });
141
142  on("command.run", async ($, e, next) => {
143    // counted aside: the store's read and write never hold up the call
144    void countUse($, `command:${e.command}`);
145    return next(e);
146  });
147
148  on("skill.prompt", async ($, e, next) => {
149    // counted aside: the store's read and write never hold up the call
150    void countUse($, `command:${e.skill}`);
151    return next(e);
152  });
153
154  on("agent.spawn", async ($, e, next) => {
155    // counted aside: the store's read and write never hold up the call
156    void countUse($, `agent:${e.subagentType}`);
157    return next(e);
158  });
159
160  // the context's agent listing has no descriptions; the model's offer does
161  on("agent.offer", async ($, e, next) => {
162    const r = await next(e);
163    if ((await read($, agentInfo))[e.agent] !== e.description)
164      await update($, agentInfo, (m) => ({ ...m, [e.agent]: e.description }));
165    return r;
166  });
167
168  on("ui.render", { component: "Pane", requestId: PANE }, async ($, e) => {
169    const els = $.ui.resolve(e);
170    const { Box, Button, Text } = els;
171    const Input = "Input" in els ? els.Input : undefined;
172    const listed = await read($, groups);
173    const top = mostUsed(listed, await read($, usage));
174    const info = await read($, agentInfo);
175    const q = await read($, query);
176    const all = filterGroups(top ? [top, ...listed] : listed, q, info);
177    // while searching every group with a match shows open
178    const shut = new Set(q.trim() ? [] : await read($, folded));
179    const toggle = (id: string) =>
180      update($, folded, (f) =>
181        f.includes(id) ? f.filter((x) => x !== id) : [...f, id],
182      );
183
184    return (
185      <Box flexDirection="column" width={e.props.bodyColumns}>
186        <Box flexDirection="row" columnGap={1}>
187          <Text dimColor>Click to put it in the prompt</Text>
188          <Button
189            key="palette-refresh"
190            plain
191            dimColor
192            onPress={() => refresh($)}
193          >
194            ↻
195          </Button>
196        </Box>
197        {Input && (
198          <Box flexDirection="row" columnGap={1} marginTop={1}>
199            <Input
200              key={SEARCH}
201              label="Search: "
202              placeholder="type to filter"
203              value={q}
204              autoFocus
205              submitLabel="put first"
206              onInput={(v) => update($, query, () => v)}
207              onSubmit={() => {
208                const first = all[0]?.items[0];
209                if (first) void press($, first);
210              }}
211            />
212            {q !== "" && (
213              <Button
214                key="palette-search-clear"
215                plain
216                dimColor
217                onPress={() => clearSearch($)}
218              >
219                ✕
220              </Button>
221            )}
222          </Box>
223        )}
224        {all.length === 0 && (
225          <Text dimColor>
226            {q.trim()
227              ? `Nothing matches "${q.trim()}".`
228              : "No agents, skills or commands."}
229          </Text>
230        )}
231        {all.map((g) => (
232          <Box key={`section:${g.id}`} flexDirection="column" marginTop={1}>
233            <Button key={`group:${g.id}`} plain onPress={() => toggle(g.id)}>
234              {`${shut.has(g.id) ? "▸" : "▾"} ${g.title} (${g.items.length})`}
235            </Button>
236            {!shut.has(g.id) &&
237              g.items.map((item) => {
238                const id = `${g.id === MOST_USED ? "top:" : ""}${item.kind}:${item.name}`;
239                const about = item.description || info[item.name] || "";
240                return (
241                  <Box
242                    key={`row:${id}`}
243                    flexDirection="column"
244                    marginTop={1}
245                    marginLeft={2}
246                  >
247                    <Button key={id} plain onPress={() => press($, item)}>
248                      {label(item)}
249                    </Button>
250                    {about !== "" && (
251                      <Box marginLeft={2}>
252                        <Text dimColor wrap="truncate-end">
253                          {about}
254                        </Text>
255                      </Box>
256                    )}
257                  </Box>
258                );
259              })}
260          </Box>
261        ))}
262      </Box>
263    );
264  });
265
266  // its own line under the other bands: a show/hide toggle
267  on("ui.render", { component: "AbovePrompt" }, async ($, e, next) => {
268    if (e.props.hasSurvey) return next(e);
269    const open = await read($, pane);
270    const below = await next(e);
271    const { Box, Button, Text } = $.ui.resolve(e);
272    return (
273      <Box flexDirection="column">
274        {below}
275        <Box flexDirection="row" columnGap={2} marginTop={1}>
276          <Text dimColor>palette</Text>
277          <Button
278            key="palette-toggle"
279            hotkey="p"
280            dimColor
281            onPress={() => togglePane($)}
282          >
283            {open ? "hide" : "show"}
284          </Button>
285        </Box>
286      </Box>
287    );
288  });
289
290  on("ui.close", { id: PANE }, async ($, e, next) => {
291    const r = await next(e);
292    await update($, pane, () => false);
293    return r;
294  });
295};
296
hooks/core.ts 175 lines
1/**
2 * core.ts — pure logic: the session's commands and agents grouped by where
3 * they come from, and what a press writes into the prompt box.
4 */
5
6import type { PaletteGroup, PaletteItem, Usage } from "../types";
7
8/** One slash command or skill as `$.command.list()` gives it. */
9export type RawCommand = {
10  name: string;
11  description: string;
12  source: "builtin" | "plugin" | "user" | "mcp";
13  plugin?: string;
14};
15
16/** One custom agent as the context breakdown lists it. */
17export type RawAgent = { agentType: string; source: string };
18
19const AGENT_GROUP: Record<string, string> = {
20  projectSettings: "project",
21  localSettings: "project",
22  userSettings: "user",
23};
24
25const pluginOf = (name: string) =>
26  name.includes(":") ? name.slice(0, name.indexOf(":")) : name;
27
28/** Where a user-source command or skill would live in the project's `.claude/`. */
29export function projectPaths(name: string): string[] {
30  const parts = name.split(":");
31  const paths = [`.claude/commands/${parts.join("/")}.md`];
32  if (parts.length === 1) paths.push(`.claude/skills/${name}/SKILL.md`);
33  return paths;
34}
35
36const rank = (id: string) =>
37  id === "project" ? 0 : id === "user" ? 1 : id.startsWith("plugin:") ? 2 : 3;
38
39/**
40 * Groups by source: project, user, each plugin, then anything else (mcp).
41 * Built-in commands and the palette's own entries are left out.
42 */
43export function buildGroups(
44  commands: RawCommand[],
45  agents: RawAgent[],
46  projectNames: ReadonlySet<string>,
47  self: string,
48): PaletteGroup[] {
49  const groups = new Map<string, PaletteItem[]>();
50  const add = (id: string, item: PaletteItem) => {
51    if (id === `plugin:${self}`) return;
52    groups.set(id, [...(groups.get(id) ?? []), item]);
53  };
54
55  for (const a of agents) {
56    const id =
57      a.source === "plugin"
58        ? `plugin:${pluginOf(a.agentType)}`
59        : (AGENT_GROUP[a.source] ?? a.source);
60    // the listing has no descriptions: agent.offer's fill them in when drawn
61    add(id, { kind: "agent", name: a.agentType, description: "" });
62  }
63  for (const c of commands) {
64    if (c.source === "builtin") continue;
65    const id =
66      c.source === "plugin"
67        ? `plugin:${c.plugin ?? pluginOf(c.name)}`
68        : c.source === "user"
69          ? projectNames.has(c.name)
70            ? "project"
71            : "user"
72          : c.source;
73    add(id, { kind: "command", name: c.name, description: c.description });
74  }
75
76  return [...groups]
77    .map(([id, items]) => ({
78      id,
79      title: id,
80      items: items.sort(
81        (a, b) =>
82          Number(a.kind === "command") - Number(b.kind === "command") ||
83          a.name.localeCompare(b.name),
84      ),
85    }))
86    .sort((a, b) => rank(a.id) - rank(b.id) || a.id.localeCompare(b.id));
87}
88
89/** Where an item's uses are kept: `<kind>:<name>`. */
90export const useKey = (item: Pick<PaletteItem, "kind" | "name">) =>
91  `${item.kind}:${item.name}`;
92
93/** A typed skill is reported twice (`command.run`, `skill.prompt`): once counts. */
94export const REPEAT_MS = 5_000;
95
96/** `usage` with one more use of `key` at `now`; unchanged within REPEAT_MS of the last. */
97export function recordUse(usage: Usage, key: string, now: number): Usage {
98  const was = usage[key];
99  if (was && now - was.last < REPEAT_MS) return usage;
100  return { ...usage, [key]: { count: (was?.count ?? 0) + 1, last: now } };
101}
102
103export const MOST_USED = "most used";
104
105/**
106 * The `n` most used items listed in `groups`, most first (ties: the latest
107 * use, then by name); undefined while none has a use.
108 */
109export function mostUsed(
110  groups: PaletteGroup[],
111  usage: Usage,
112  n = 10,
113): PaletteGroup | undefined {
114  const seen = new Map<string, PaletteItem>();
115  for (const item of groups.flatMap((g) => g.items))
116    if (usage[useKey(item)]) seen.set(useKey(item), item);
117  const items = [...seen.values()]
118    .sort((a, b) => {
119      const ua = usage[useKey(a)]!;
120      const ub = usage[useKey(b)]!;
121      return (
122        ub.count - ua.count || ub.last - ua.last || a.name.localeCompare(b.name)
123      );
124    })
125    .slice(0, n);
126  return items.length
127    ? { id: MOST_USED, title: MOST_USED, items }
128    : undefined;
129}
130
131/**
132 * The groups with only the items whose name or description holds every word
133 * of `query` (any case); groups left empty are dropped. A blank query keeps all.
134 */
135export function filterGroups(
136  groups: PaletteGroup[],
137  query: string,
138  info: Record<string, string> = {},
139): PaletteGroup[] {
140  const words = query.toLowerCase().split(/\s+/).filter(Boolean);
141  if (words.length === 0) return groups;
142  const hit = (item: PaletteItem) => {
143    const text =
144      `${item.name} ${item.description || info[item.name] || ""}`.toLowerCase();
145    return words.every((w) => text.includes(w));
146  };
147  return groups
148    .map((g) => ({ ...g, items: g.items.filter(hit) }))
149    .filter((g) => g.items.length > 0);
150}
151
152/** What a row reads: `@<name>` for an agent, `/<name>` for a command or skill. */
153export const label = (item: PaletteItem) =>
154  `${item.kind === "agent" ? "@" : "/"}${item.name}`;
155
156/**
157 * What a press puts in the prompt box. A command or skill goes first (a slash
158 * command only runs from the start), replacing a leading one; an agent
159 * mention goes in at the cursor, spaced from the word before it.
160 */
161export function fillFor(
162  item: PaletteItem,
163  draft: string,
164  cursor: number,
165): { text: string; mode: "replace" | "insert" } {
166  if (item.kind === "command")
167    return {
168      text: `/${item.name} ${draft.replace(/^\/\S+\s*/, "")}`,
169      mode: "replace",
170    };
171  const before = draft.slice(0, cursor);
172  const gap = before === "" || /\s$/.test(before) ? "" : " ";
173  return { text: `${gap}@agent-${item.name} `, mode: "insert" };
174}
175
types/index.d.ts 38 lines
1/** One clickable row: an agent inserts `@agent-<name>`, a command or skill `/<name>`. */
2export type PaletteItem = {
3  kind: "agent" | "command";
4  name: string;
5  description: string;
6};
7
8/** Items of one source: `project`, `user`, `plugin:<name>` or `mcp`. */
9export type PaletteGroup = {
10  id: string;
11  title: string;
12  items: PaletteItem[];
13};
14
15/** How often an item was used, and when last (ms since epoch). */
16export type Use = { count: number; last: number };
17
18/** Uses by `<kind>:<name>` (`command:think`, `agent:rust-engineer`). */
19export type Usage = Record<string, Use>;
20
21declare module "claude-code" {
22  interface PluginState {
23    palette: {
24      groups: PaletteGroup[];
25      /** Whether the pane is open, as the last open or close left it. */
26      pane: boolean;
27      /** Group ids the person folded. */
28      folded: string[];
29      /** Agent descriptions by type, as `agent.offer` last carried them. */
30      agentInfo: Record<string, string>;
31      /** Uses across sessions, as `$.store` keeps them. */
32      usage: Usage;
33      /** What the search field holds; items are filtered by it. */
34      query: string;
35    };
36  }
37}
38