modscode / Gallery / compact-adviser
compact-adviser
Suggests (or, opt-in, runs) /compact at a completed checkpoint, judged by TypeSafe Jev. Its hooks module activates only when CLAUDE_CODE_ENABLE_FUNCTION_HOOKS is exactly 1 and is otherwise a complete no-op.
What it does
- Draws a pane, the status line, toasts
- Hooks config.describe, session.compact, session.start, turn.complete and 2 more
- Keeps its own state between turns
- Calls the network
Good points
- Starts no processes
- Written in TypeScript
- Has a desktop-specific branch
- Handles errors
Code to start from
Two kinds: a starter modscode writes from the design above, and the lines of the mod's own code that draw it.
Starter (register.tsx)
import type { Register } from 'claude-code'
// Drawn like compact-adviser by Kun Chen (pane, status, toast), as modscode read it from the mod's code:
// https://modscode.com/gallery/kunchenguid-compact-adviser/
// Written by modscode from that reading, not copied from the mod: use it as you like.
// Each value below stands for one the mod works out at run time; put in your own.
export const register: Register = on => {
// the pane: open it with $.ui.open({ id: 'my-pane', title: "Compact adviser (saved for all sessions)" })
on('ui.render', { component: 'Pane', requestId: 'my-pane' }, async ($, e) => {
const { Text } = $.ui.resolve(e)
return (
<Text>
{"Use /compact-adviser, auto, hint, off, status, threshold <tokens|default>, budget <tokens|off>, snooze or dismiss."}
</Text>
)
})
on('session.start', async ($, e, next) => {
const deny = '…'
await $.ui.status(`work appears completed or recorded. Run /compact to save tokens.`)
await $.ui.toast(`Not saved: ${deny}`)
await $.ui.toast(`Advice snoozed for three completed exchanges.`)
return next(e)
})
}
The mod's own code
Shown under the mod's licence (MIT); its text is below. Keep the notice if you copy these lines.
packages/claude-mod/hooks/register.ts lines 841–1000 · Pane
on("ui.render", { component: "Pane" }, async ($, e, next) => {
if (!(await isActivated($)) || e.requestId !== PANE_ID) return next(e);
if (e.surface !== "terminal") {
const { Text } = $.ui.resolve(e);
return Text({ children: USAGE });
}
const { Box, Text, Input, Button } = $.ui.resolve(e);
const column = (children: RenderChildren[]) => Box({ flexDirection: "column", children });
const heading = (crumb?: string) =>
Box({
flexDirection: "row",
marginBottom: 1,
children: [
Text({ bold: true, children: "Compact adviser" }),
Text({ dimColor: true, children: crumb ? ` › ${crumb}` : " saved for all sessions" }),
],
});
const hint = (leave: string) =>
Text({ dimColor: true, children: `↑↓ move · Enter select · Esc ${leave}` });
const closePane = () => void $.ui.close({ id: PANE_ID });
const redraw = async () => {
await $.ui.invalidate("ui.render");
await placeRing($);
};
const run = (action: () => Promise<unknown>) => {
void action()
.catch((error) => $.ui.toast(errorMessage(error), { timeoutMs: 8000 }))
.finally(redraw);
};
const back = () => {
showMenu();
void redraw();
};
let config: Config;
try {
config = await loadConfig($);
} catch (error) {
return column([
heading(),
Text({ color: "error", children: errorMessage(error) }),
Button({
key: "menu:close",
label: "Close",
plain: true,
autoFocus: true,
onPress: closePane,
}),
]);
}
const [rows, key] = await Promise.all([$.config.list(), resolvedKey($)]);
const savedKey = readSavedApiKey(rows, loadedOptions) !== undefined;
/** A list of rows the ring moves through; the one at `focus` takes it first. */
const list = (
entries: { key: string; label: string; onPress: () => void; dim?: boolean }[],
focus: string,
) => {
const width = Math.max(...entries.map((entry) => entry.label.length));
return column(
entries.map((entry) =>
Button({
key: entry.key,
label: entry.label.padEnd(width),
plain: true,
...(entry.dim ? { dimColor: true } : {}),
...(entry.key === focus ? { autoFocus: true } : {}),
onPress: entry.onPress,
}),
),
);
};
/** A view of options: the current one marked; picking it, or Back, only returns. */
const options = <T extends string>(
crumb: string,
current: T,
choices: { value: T; label: string }[],
pick: (value: T) => void,
) =>
column([
heading(crumb),
list(
[
...choices.map((choice) => ({
key: `${view}:${choice.value}`,
label: `${choice.value === current ? "●" : " "} ${choice.label}`,
onPress: () => {
showMenu();
if (choice.value === current) void redraw();
else pick(choice.value);
},
})),
{ key: "back", label: " Back", dim: true, onPress: back },
],
`${view}:${current}`,
),
hint("back"),
]);
if (view === "mode") {
return options(
"Mode",
config.mode,
(["hint", "auto", "off"] as const).map((value) => ({ value, label: MODE_LABELS[value] })),
(mode) => run(() => changeMode($, mode, true)),
);
}
if (view === "logging") {
return options(
"Log TypeSafe requests",
config.logRequests ? "on" : "off",
[
{ value: "off", label: "Off (default)" },
{ value: "on", label: "On" },
],
(value) => run(() => changeLogRequests($, value === "on")),
);
}
if (view === "minimum") {
return column([
heading("Minimum context"),
Input({
key: "minimum",
label: "Tokens",
value: minimumDraft?.text ?? String(config.minContextTokens),
placeholder: String(DEFAULT_MINIMUM),
submitLabel: "save",
autoFocus: true,
onSubmit: (text: string) => {
run(async () => {
try {
if (await changeMinimum($, text)) showMenu();
else minimumDraft = { text };
} catch (error) {
minimumDraft = { text, error: errorMessage(error) };
}
});
},
}),
minimumDraft?.error
? Text({ color: "error", children: minimumDraft.error })
: Text({
dimColor: true,
children: "A token count, not a percentage; no judgment below it.",
}),
list([{ key: "back", label: "Back", dim: true, onPress: back }], ""),
hint("back"),
]);
}
if (view === "key") {
return column([
heading("TypeSafe API key"),
Text({ dimColor: true, wrap: "wrap", children: keyDetail(key.source, savedKey) }),
Input({
key: "typesafeApiKey",
label: "Key",
value: keyDraft?.text ?? "",
placeholder: savedKey ? "paste a key to replace the saved one" : "paste a key to save it",
submitLabel: "save",
autoFocus: true,
onSubmit: (text: string) => {Licence text (MIT)
MIT License Copyright (c) 2026 kunchenguid Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
This code is an example in the code reference: Keep state with $.store
What its code calls
networkwrites filesenv varsremembers
The design, read from code
Drawn from the mod's source at the commit read, not from a run: a list is drawn three times, a condition takes its first branch that draws in the desktop app, and a value only the run time knows is shown as a made-up sample (dotted underline) or left out. Colours and type are this site's.
What its code shows
Read from the source at commit ef216af7cb63 on 2026-10-06. The first group decides whether a mod is listed; the rest is for you to weigh. A later commit is not read until the next crawl.
| Decides the listing: code you can check | |
|---|---|
| Entry read | Every module hooks/hooks.json names was read.packages/claude-mod/hooks/register.ts |
| Parses | Every file parses as TypeScript or JavaScript.9 files parsed |
| All its code is in the mod | Every import is a file of the mod or the engine's own module; no packages, no require.all its code is in the mod |
| Readable | No minified lines, no eval or new Function, no import of a computed path, no encoded blobs.no minified code, no eval, no encoded blobs |
| Calls in the open | Network and programs are reached as $.http.fetch and $.process.run in place, never passed around.every call outside goes through $ in the open |
| For you to weigh before installing | |
| Where it draws | The terminal, the desktop app, both, or nothing (hooks only: a guard or a prompt rewriter), as its code says. Shown, never a reason to leave a mod out.draws in the terminal and the desktop app, the same in both |
| Install line | Whether its repository's own .claude-plugin/marketplace.json lists it, so it installs from that marketplace with the lines on its page.listed in its repository's .claude-plugin/marketplace.json: installs from there |
| Programs on Windows | Whether every program it starts through $.process exists on Windows (tail, date, open, osascript, /usr/… do not).runs no program a Windows PC lacks |
| Network | Whether every fetch names its https host in the code.packages/claude-mod/hooks/register.ts:303 fetch(url) |
| Programs | Whether every program it starts is named in the code and is not a shell, an interpreter or a network tool.starts no programs |
| Reads and sends | Whether it both reads files or environment variables and reaches the network.reads environment variables and files and reaches the network |
| Keys in the source | Whether the source holds what looks like an API key or a private key.no keys in the source |
| Licence | An open licence (MIT, Apache-2.0, BSD, ISC, Unlicense, 0BSD, CC0) with its text lets modscode show its code; otherwise the code is linked.MIT |
This is a reading of the code text, not a security review: it does not run the mod, and it cannot see what a program the mod starts does. The check before installing is yours. How mods are chosen
Install it
Check it yourself before you install it. Mods run unsandboxed, with your permissions, and modscode does not vouch for what this code does. Read the code below (or run claude plugin validate . in its folder), weigh what it reaches, and install the commit you read.
Its repository is its marketplace. Add that marketplace (in the terminal with these commands, or in the desktop app's plugin settings) and install the mod from it:
/plugin marketplace add kunchenguid/compact-adviser/plugin install compact-adviser@compact-adviserThis installs the marketplace's latest commit, which may not be the one read here (ef216af7cb63). Compare them before you install.
Ask Claude about it
With the modscode connector added, Claude can read this design, what its code reaches and its code, and build on them. Ask it like this:
Read the modscode design "kunchenguid-compact-adviser" with its code and make me a pane like itSearch them from Claude: the MCP connector
Similar designs
-
Ask Claude…2h 10m · █████░░░✓ build ✓ build ✓ buildJavaKotlin3 Python■ ok 3 ■ ok 3 ■ ok 3 Razor proven 3 Razor proven 3 Razor proven 3Phases ──────── 3/3build Pythonbuild Pythonbuild Python… 3 more phasesLua ──────── 3/Kotlin■ the whole upgrade Ruby■ build build Ruby■ build build Ruby■ build build Ruby … 3 moreNext ──────── PythonRuby (by hand)Podsclick a button, or ctrl+x tab then Tab, EnterAttention ──────── 3! Scala ! Scala ! Scala … 3 moreSession ──────── okJava
-
Open a file first: /crit-tui file <path>Reopen this one in the crit browser view.Ask Claude…
-
Ask Claude…TodayOct 63 left · Mar overdueRemCTL: Sep✓ All done for today.● build3● Fix login ● ⚑Jul · build✓● Fix login ● ⚑Jul · build✓● Fix login ● ⚑Jul · build✓● build3● Fix login ● ⚑Jul · build✓● Fix login ● ⚑Jul · build✓● Fix login ● ⚑Jul · build✓● build3● Fix login ● ⚑Jul · build✓● Fix login ● ⚑Jul · build✓● Fix login ● ⚑Jul · build✓Updated 14:32UndoRefresh
-
Ask Claude…TO graph› Fix login › Fix login › Fix loginScopeThis featureWhole projectHide done stepsReconnect
-
Ask Claude…Replay TheaterStep Prev1/3 write Next[31][31][31]Prev pNext nClose q────────● Prev● Prev● Prev
-
Ask Claude…great_cto: 3 gate waiting — /gatesGatesmy-app · 3 waiting · checked Gates UTCGates — Fix logina1b2c3dExpensive to undo. To approve, type Gates and press Enter.approve: Gates approveGates — Fix logina1b2c3dExpensive to undo. To approve, type Gates and press Enter.approve: Gates approveGates — Fix logina1b2c3dExpensive to undo. To approve, type Gates and press Enter.approve: Gates approve