ModsCode / Claude Code Mods / Ranking / context-diet
context-diet
Trims huge tool outputs (logs, JSON, diffs, grep, file lists) before they reach Claude's context, and saves the full text to a file Claude can read
What it does
- Draws a pane, the status line, toasts
- Adds /diet
- Watches tool calls and can refuse them
- Hooks session.append, session.start, ui.close
- Keeps its own state between turns
Good points
- No network calls
- Starts no processes
- Written in TypeScript
- Handles errors
Code to start from
A starter ModsCode writes from the drawing it read, and the mod's own lines that draw, where there are any.
Starter (register.tsx)
import type { Register } from 'claude-code'
// Drawn like context-diet by drkokorev (pane, status, toast), as ModsCode read it from the mod's code:
// https://modscode.com/claude-mods/mods/drkokorev-context-diet/
// 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: "Context Diet" })
on('ui.render', { component: 'Pane', requestId: 'my-pane' }, async ($, e) => {
const { Box, Text, Button } = $.ui.resolve(e)
const fmtTokens = '…'
const plural = '…'
const fmtChars = '…'
const pct = '…'
const upgrades = '…'
const toolName = '…'
const toolName2 = '…'
const plural2 = '…'
const toolName3 = '…'
const plural3 = '…'
const head = '…'
const label = '…'
const kind = '…'
const keptWhat = '…'
const path = '…'
const path2 = '…'
const path3 = '…'
return (
<Box flexDirection="column">
<Box flexDirection="row" gap={1} flexWrap="wrap">
<Text bold color="green">
◇ CONTEXT DIET
</Text>
<Text color="green">
dry run: measuring only
</Text>
<Text dimColor>
{`cuts outputs over ≈${fmtTokens} tokens`}
</Text>
</Box>
<Box flexDirection="row" gap={1} marginTop={1} flexWrap="wrap">
<Text dimColor>
would save
</Text>
<Text bold color="green">
{`≈${fmtTokens} tokens`}
</Text>
<Text dimColor>
{`${plural} · ${fmtChars} → ${fmtChars} chars (−${pct}%)`}
</Text>
</Box>
<Box flexDirection="row" gap={1}>
<Text dimColor>
all-time
</Text>
<Text>
{`≈${fmtTokens} tokens · ${plural}`}
</Text>
</Box>
<Box flexDirection="row" gap={1}>
<Text dimColor>
reopened
</Text>
<Text color="yellow">
{`${plural} Claude opened a full output after a cut`}
</Text>
</Box>
<Box flexDirection="row" gap={1}>
<Text dimColor>
digests
</Text>
<Text>
{`${upgrades} very long outputs shown whole-file, not just the start`}
</Text>
</Box>
<Box flexDirection="column" marginTop={1}>
<Text bold>
BY TOOL
</Text>
<Box flexDirection="row" gap={1}>
<Text>
{toolName}
</Text>
<Text dimColor>
{plural}
</Text>
<Text color="green">
{`≈${fmtTokens} tok`}
</Text>
</Box>
<Box flexDirection="row" gap={1}>
<Text>
{toolName2}
</Text>
<Text dimColor>
{plural2}
</Text>
<Text color="green">
{`≈${fmtTokens} tok`}
</Text>
</Box>
<Box flexDirection="row" gap={1}>
<Text>
{toolName3}
</Text>
<Text dimColor>
{plural3}
</Text>
<Text color="green">
{`≈${fmtTokens} tok`}
</Text>
</Box>
</Box>
<Box flexDirection="column" marginTop={1}>
<Text bold>
LATEST CUTS
</Text>
<Box flexDirection="column">
<Button plain label={`${head} ${label}`} />
<Box flexDirection="column" paddingLeft={2}>
<Text dimColor>
{`${kind} · kept ${keptWhat} · from a subagent`}
</Text>
<Text color="cyan">
{path}
</Text>
<Text dimColor>
{" "}
</Text>
<Text dimColor>
{" "}
</Text>
<Text dimColor>
{" "}
</Text>
</Box>
</Box>
<Box flexDirection="column">
<Button plain label={`${head} ${label}`} />
<Box flexDirection="column" paddingLeft={2}>
<Text dimColor>
{`${kind} · kept ${keptWhat} · from a subagent`}
</Text>
<Text color="cyan">
{path2}
</Text>
<Text dimColor>
{" "}
</Text>
<Text dimColor>
{" "}
</Text>
<Text dimColor>
{" "}
</Text>
</Box>
</Box>
<Box flexDirection="column">
<Button plain label={`${head} ${label}`} />
<Box flexDirection="column" paddingLeft={2}>
<Text dimColor>
{`${kind} · kept ${keptWhat} · from a subagent`}
</Text>
<Text color="cyan">
{path3}
</Text>
<Text dimColor>
{" "}
</Text>
<Text dimColor>
{" "}
</Text>
<Text dimColor>
{" "}
</Text>
</Box>
</Box>
</Box>
<Box flexDirection="row" gap={1} marginTop={1} flexWrap="wrap">
<Button variant="primary" label="Turn off" />
<Button label={`Cut over: ≈${fmtTokens} tok`} />
<Button label="Dry run: on" />
</Box>
</Box>
)
})
on('session.start', async ($, e, next) => {
const sig = '…'
const fmtChars = '…'
const tool = '…'
const fmtTokens = '…'
await $.ui.status(`◇ diet off`)
await $.ui.toast(`Context Diet: Claude kept opening the full output of "${sig}", so it is now cut only past ${fmtChars} characters.`)
await $.ui.toast(`Context Diet (dry run) would trim this ${tool} output: ${fmtChars} → ${fmtChars} chars, ≈${fmtTokens} tokens. Nothing was c…`)
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.
plugins/context-diet/hooks/register.tsx lines 737–737 · Pane
on('ui.render', { component: 'Pane', requestId: PANE }, async ($, e) => drawDiet($, $.ui.resolve(e), e.props.bodyColumns))plugins/context-diet/hooks/register.tsx lines 480–568 · Pane
const drawDiet = async ($: Dollar, els: DietElements, columns: number) => {
const { Box, Text, Button } = els
const s = await read($, stats)
const p = await read($, prefs)
const v = await read($, view)
const saved = s.rawChars - s.keptChars
const pct = Math.round((saved / Math.max(1, s.rawChars)) * 100)
const width = Math.max(30, columns)
const tools = Object.entries(s.byTool).sort((a, b) => b[1].raw - b[1].kept - (a[1].raw - a[1].kept))
const recent = [...s.log].reverse().slice(0, 8)
const nextThreshold = THRESHOLDS[(THRESHOLDS.indexOf(p.threshold) + 1) % THRESHOLDS.length] ?? 8_000
return (
<Box flexDirection="column">
<Box flexDirection="row" gap={1} flexWrap="wrap">
<Text bold color="green">◇ CONTEXT DIET</Text>
<Text color={p.isOn && !p.isDry ? 'green' : 'yellow'}>{p.isOn ? (p.isDry ? 'dry run: measuring only' : 'on') : 'off'}</Text>
<Text dimColor>{`cuts outputs over ≈${fmtTokens(tokensOf(p.threshold))} tokens`}</Text>
</Box>
<Box flexDirection="row" gap={1} marginTop={1} flexWrap="wrap">
<Text dimColor>{p.isDry ? 'would save' : 'saved'}</Text>
<Text bold color="green">{`≈${fmtTokens(tokensOf(saved))} tokens`}</Text>
<Text dimColor>{s.cuts ? `${plural(s.cuts, 'cut')} · ${fmtChars(s.rawChars)} → ${fmtChars(s.keptChars)} chars (−${pct}%)` : 'nothing cut yet'}</Text>
</Box>
<Box flexDirection="row" gap={1}>
<Text dimColor>all-time</Text>
<Text>{`≈${fmtTokens(tokensOf(s.lifetimeSaved))} tokens · ${plural(s.lifetimeCuts, 'cut')}`}</Text>
</Box>
{s.cuts + (s.upgrades ?? 0) ? (
<Box flexDirection="row" gap={1}>
<Text dimColor>reopened</Text>
<Text color={(s.rereads ?? 0) > (s.cuts + (s.upgrades ?? 0)) / 3 ? 'yellow' : undefined}>{`${plural(s.rereads ?? 0, 'time')} Claude opened a full output after a cut`}</Text>
</Box>
) : null}
{s.upgrades ? (
<Box flexDirection="row" gap={1}>
<Text dimColor>digests</Text>
<Text>{`${s.upgrades} very long output${s.upgrades > 1 ? 's' : ''} shown whole-file, not just the start`}</Text>
</Box>
) : null}
{tools.length ? (
<Box flexDirection="column" marginTop={1}>
<Text bold>BY TOOL</Text>
{tools.map(([tool, t]) => (
<Box key={`tool-${tool}`} flexDirection="row" gap={1}>
<Text>{toolName(tool).slice(0, 20).padEnd(20)}</Text>
<Text dimColor>{plural(t.cuts, 'cut').padEnd(8)}</Text>
<Text color="green">{`≈${fmtTokens(tokensOf(t.raw - t.kept))} tok`}</Text>
</Box>
))}
</Box>
) : null}
<Box flexDirection="column" marginTop={1}>
<Text bold>LATEST CUTS</Text>
{recent.length === 0 ? (
<Text dimColor>{`Outputs from Bash, Grep, Glob and MCP tools longer than ${p.threshold.toLocaleString('en-US')} characters are trimmed here; the full text goes to ${DIR}/.`}</Text>
) : (
recent.map(c => {
const isOpen = v.openCut === c.at
const head = `${isOpen ? '▾' : '▸'} ${new Date(c.at).toTimeString().slice(0, 5)} ${toolName(c.tool)} ${c.isUpgrade ? `digest ${fmtChars(c.raw)}` : `${fmtChars(c.raw)}→${fmtChars(c.kept)}`}${c.kind === 'delta' ? ' Δ' : ''}${c.rereads ? ` ↻${c.rereads}` : ''}`
const label = shorten(c.label, Math.max(10, width - head.length - 3))
return (
<Box key={`cut-${c.at}`} flexDirection="column">
<Button key={`cut-${c.at}`} plain label={`${head} ${label}`} onPress={() => toggleCut($, c.at)} />
{isOpen ? (
<Box flexDirection="column" paddingLeft={2}>
<Text dimColor>{`${c.kind} · kept ${c.keptWhat}${c.agentId ? ' · from a subagent' : ''}`}</Text>
<Text color="cyan">{c.path}</Text>
{c.preview
.split('\n')
.slice(0, 8)
.map((line, i) => (
<Text key={`pv-${c.at}-${i}`} dimColor>{shorten(line, width - 4) || ' '}</Text>
))}
</Box>
) : null}
</Box>
)
})
)}
</Box>
<Box flexDirection="row" gap={1} marginTop={1} flexWrap="wrap">
<Button key="toggle" variant={p.isOn ? undefined : 'primary'} label={p.isOn ? 'Turn off' : 'Turn on'} onPress={() => toggleOn($)} />
<Button key="threshold" label={`Cut over: ≈${fmtTokens(tokensOf(p.threshold))} tok`} onPress={() => setThreshold($, nextThreshold)} />
<Button key="dry" label={p.isDry ? 'Dry run: on' : 'Dry run: off'} onPress={() => toggleDry($)} />
</Box>
</Box>
)
}Licence text (MIT)
MIT License Copyright (c) 2026 drkokorev 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.
How to build this: Pane (panel), Deny a tool call
What its code calls
writes filestool callsremembers
What its code shows
Read from the source at commit 689284a893f1 on 2026-10-11. 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.plugins/context-diet/hooks/register.tsx |
| Parses | Every file parses as TypeScript or JavaScript.4 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.no network |
| 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 something of yours (files, environment variables, the transcript, settings) and reaches outside (the network, an MCP server, another session, telemetry).reads files, but reaches nothing outside |
| 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 |
| Settings hooks | Hooks declared in hooks/hooks.json or plugin.json beside the module: a command (a shell when it has no args), an HTTP request, an MCP tool or a model prompt at an event. They run outside $.no settings hooks: its function hooks alone |
| Servers it ships | MCP servers (a program, or a URL; a headersHelper is a shell command; a .mcpb bundle is unpacked at run time), LSP servers, monitors (a shell command for the whole session) and bin/ (on the PATH of the Bash tool).ships no MCP or LSP server, no monitor, no bin/ |
| Skills, commands, agents | What its Markdown declares beyond text: allowed-tools granted for the turn, hooks added when a skill is invoked, a command run before Claude reads the skill.no skills, commands, agents or workflows |
| Tools and MCP | Whether every tool it calls through $.tool.call and $.mcp.call is named in the code, and none is a shell (Bash through the tool runs a shell without $.process).calls no tool, MCP server or command |
| Asks of the model | Completions it runs ($.model.complete, fork, classify), subagents it spawns, prompts it submits as you, and the tools, commands and agents it adds.adds command diet |
| Events it hooks | By what a hook there can do: gates (refuse a tool call, a prompt, a setting, another plugin), shapes (what the model reads: the system prompt, tool descriptions, each request), reads (your input, the events of the settings hooks, every event with *), and the rest.gates: tool.call, session.append, command.run (diet) · also: session.start, ui.close, ui.render (Pane) |
| Reads, by name | The environment variables and files it names, and whether it reads the transcript, settings.json, the prompt box or the mouse selection.files: …/…/.gitignore, a path computed at run time |
| Writes, by name | The files and environment variables it names, and whether it changes settings, the prompt box, the clipboard, the conversation (a row the model reads) or another session.files: …/…/.gitignore, a path computed at run time |
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 its code (or run claude plugin validate . in its folder), weigh what it reaches, and install the commit you read.
From its marketplace
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 drkokorev/context-diet/plugin install context-diet@context-diet/reload-pluginsThis installs the marketplace's latest commit, which may not be the one read here (689284a893f1). Compare them before you install. /reload-plugins loads it into a session that is already open.
Try the commit ModsCode read
No marketplace needed. In a terminal, clone the repository, check out the commit read, validate the mod, and load it for one session:
git clone https://github.com/drkokorev/context-dietgit -C context-diet checkout 689284a893f1aa509b9c6c1c06b91ef1ca52279cclaude plugin validate context-diet/plugins/context-dietclaude --plugin-dir context-diet/plugins/context-dietThe validate line lists the events the mod hooks and what it asks Claude Code to do, without running it. The last line loads the mod for this session only and writes nothing to your settings. If the author has rewritten history, the commit may no longer exist.
Ask Claude about it
With the ModsCode connector added, Claude can read this mod's code and what it reaches, and build on them. Ask it like this:
Read the ModsCode mod "drkokorev-context-diet" with its code and make me one like itSearch them from Claude: the MCP connector
Similar mods
- code-modernizationAnthropic★ 37,653
- crit-tuiTomasz Tomczyk★ 1,196
- remctlFederico Viticci★ 595
- task-orchestrator-modJeff Picklyk★ 208
- replay-theaterHamza Zafar★ 184
- great-ctoAlexander Velikiy★ 103
More by drkokorev
Badge for your README
If this is your mod, paste this into your README. It links to this page.
[](https://modscode.com/claude-mods/mods/drkokorev-context-diet/)