modscode JA

modscode / Gallery / cache-keeper

cache-keeper

Prompt-cache countdown, cost to re-warm, usage limits, cold-cache warnings and one-click handoff → clear & continue.

Code you can checkTerminal + desktopPaneBandStatus lineToastBoxButtonText

What it does

  • Draws a pane, a band above the prompt, toasts
  • Adds /cache-keeper
  • Hooks session.compact, session.end, session.start, turn.complete and 1 more
  • Keeps its own state between turns

Good points

  • No network calls
  • Starts no processes
  • Written in TypeScript
  • 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)

register.tsx
import type { Register } from 'claude-code'

// Drawn like cache-keeper by etding (pane, band, status, toast), as modscode read it from the mod's code:
// https://modscode.com/gallery/etding-cache-keeper/
// 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: "Cache keeper" })
  on('ui.render', { component: 'Pane', requestId: 'my-pane' }, async ($, e) => {
    const { Box, Text, Button } = $.ui.resolve(e)
    const headline = '…'
    const ttlLabel = '…'
    const ttlSource = '…'
    const formatUsd = '…'
    const priceSource = '…'
    const formatTokens = '…'
    const formatTokens2 = '…'
    const contextPercent = '…'
    const kind = '…'
    const percentLeft = '…'
    const formatUntil = '…'
    const kind2 = '…'
    const percentLeft2 = '…'
    const kind3 = '…'
    const percentLeft3 = '…'
    const formatUsd2 = '…'
    const autoCompactSummary = '…'
    const formatTokens3 = '…'
    return (
      <Box flexDirection="column">
        <Text bold>
          {headline}
        </Text>
        <Text dimColor>
          {"TTL "}
          {ttlLabel}
          {" ("}
          {ttlSource}
          ) · re-warm if cold ≈
          {formatUsd}
          {" ("}
          {priceSource}
          {" price)"}
        </Text>
        <Text>
          {" "}
        </Text>
        <Text>
          {"Context "}
          {formatTokens}
          {" / "}
          {formatTokens2}
          {` (${contextPercent}%)`}
        </Text>
        <Text>
          {kind}
          {" "}
          {percentLeft}
          % left
          {` · resets in ${formatUntil}`}
        </Text>
        <Text>
          {kind2}
          {" "}
          {percentLeft2}
          % left
          {` · resets in ${formatUntil}`}
        </Text>
        <Text>
          {kind3}
          {" "}
          {percentLeft3}
          % left
          {` · resets in ${formatUntil}`}
        </Text>
        <Text>
          {"Session at API rates "}
          {formatUsd2}
        </Text>
        <Box flexDirection="column" marginTop={1}>
          <Text bold>
            Auto-compact
          </Text>
          <Text dimColor>
            {autoCompactSummary}
          </Text>
        </Box>
        <Box flexDirection="row" gap={2}>
          <Button label={`Sooner −${formatTokens}`} />
          <Button label={`Later +${formatTokens}`} />
          <Button label="Turn on" />
          <Button label="Reset to default" />
        </Box>
        <Box flexDirection="column" marginTop={1}>
          <Text bold>
            Actions
          </Text>
          <Box flexDirection="row" gap={2}>
            <Button label="🔥 Keep warm" />
            <Button label="📦 Compact now" />
            <Button label="🤝 Handoff" />
          </Box>
        </Box>
        <Text color="yellow">
          Handoff running…
        </Text>
        <Box flexDirection="row">
          <Text color="green">
            Handoff ready (
            {formatTokens3}
            {" chars) "}
          </Text>
          <Button label="Clear & continue" variant="primary" />
          <Text>
            {" "}
          </Text>
          <Button label="Discard" />
        </Box>
      </Box>
    )
  })

  // the band above the prompt; what else goes there is drawn under it
  on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
    const { Box, Text, Button } = $.ui.resolve(e)
    const text = '…'
    const text2 = '…'
    const text3 = '…'
    return (
      <Box flexDirection="column">
        <Box flexDirection="row" justifyContent="space-between">
          <Box flexDirection="row" flexGrow={1} flexShrink={1} gap={1}>
            <Box flexDirection="row" flexShrink={0} borderStyle="round" borderDimColor paddingX={1} height={1}>
              <Text>
                {"● "}
              </Text>
              <Text dimColor>
                {text}
              </Text>
            </Box>
            <Box flexDirection="row" flexShrink={0} borderStyle="round" borderDimColor paddingX={1} height={1}>
              <Text>
                {"● "}
              </Text>
              <Text dimColor>
                {text2}
              </Text>
            </Box>
            <Box flexDirection="row" flexShrink={0} borderStyle="round" borderDimColor paddingX={1} height={1}>
              <Text>
                {"● "}
              </Text>
              <Text dimColor>
                {text3}
              </Text>
            </Box>
          </Box>
          <Box flexDirection="row" flexShrink={0} gap={1}>
            <Button label="🔥" />
            <Button label="📦" />
            <Button label="🤝" />
            <Button label="📊" />
          </Box>
        </Box>
        {await next(e)}
      </Box>
    )
  })

  on('session.start', async ($, e, next) => {
    const formatCountdown = '…'
    const formatTokens = '…'
    const formatUsd = '…'
    const label = '…'
    const message = '…'
    await $.ui.toast(`Cache goes cold in ${formatCountdown}; re-warming ${formatTokens} tokens would cost ≈${formatUsd}. Keep warm, compact or h…`)
    await $.ui.toast(`cache-keeper: ${label} failed: ${message}`)
    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.

cache-keeper/hooks/register.tsx lines 386–487 · Pane
  on('ui.render', { component: 'Pane', requestId: PANE_ID }, async ($, e) => {
    const { Box, Button, Text } = $.ui.resolve(e)
    const view = await computeView($, config)
    const handoff = await read($, handoffAtom)
    const ttlLabel = view.ttlMs >= TTL_1H_MS ? '1h' : '5m'
    const hasActions = view.phase !== 'running' && view.phase !== 'empty' && handoff.status === 'idle'
    // The − / + buttons and "Turn on" start from the point in force, else this model's default.
    const compactBase = view.compact.at ?? defaultCompactAt(view.contextWindow) ?? COMPACT_FLOOR_TOKENS
    const compactCeiling = view.contextWindow > 0 ? view.contextWindow : Number.POSITIVE_INFINITY

    return (
      <Box flexDirection="column">
        <Text bold color={PHASE_COLOR[view.phase]}>
          {headline(view)}
        </Text>
        <Text dimColor>
          TTL {ttlLabel} ({view.ttlSource}) · re-warm if cold ≈{formatUsd(view.rewarmUsd)} ({view.priceSource} price)
        </Text>
        <Text> </Text>
        <Text>
          Context {formatTokens(view.contextTokens)} / {formatTokens(view.contextWindow)}
          {view.contextPercent !== undefined ? ` (${view.contextPercent}%)` : ''}
        </Text>
        {view.rateLimits.map(limit => (
          <Text>
            {LIMIT_LABEL[limit.kind] ?? limit.kind} {percentLeft(limit)}% left
            {formatUntil(limit.resetsAt, view.now) ? ` · resets in ${formatUntil(limit.resetsAt, view.now)}` : ''}
          </Text>
        ))}
        {view.costUsd !== undefined && <Text>Session at API rates {formatUsd(view.costUsd)}</Text>}

        {/* Auto-compact gets its own titled section so its buttons don't read as part of the actions below. */}
        <Box flexDirection="column" marginTop={1}>
          <Text bold>Auto-compact</Text>
          <Text dimColor>{autoCompactSummary(view)}</Text>
        </Box>
        <Box flexDirection="row" gap={2}>
          <Button
            key="compact-less"
            label={`Sooner −${formatTokens(COMPACT_STEP_TOKENS)}`}
            onPress={() =>
              runAction($, 'auto-compact', () =>
                setSessionCompact($, Math.max(COMPACT_STEP_TOKENS, compactBase - COMPACT_STEP_TOKENS)),
              )
            }
          />
          <Button
            key="compact-more"
            label={`Later +${formatTokens(COMPACT_STEP_TOKENS)}`}
            onPress={() =>
              runAction($, 'auto-compact', () =>
                setSessionCompact($, Math.min(compactCeiling, compactBase + COMPACT_STEP_TOKENS)),
              )
            }
          />
          <Button
            key="compact-toggle"
            label={view.compact.at === null ? 'Turn on' : 'Turn off'}
            onPress={() =>
              runAction($, 'auto-compact', () => setSessionCompact($, view.compact.at === null ? compactBase : 'off'))
            }
          />
          {view.compact.source === 'session' && (
            <Button
              key="compact-reset"
              label="Reset to default"
              onPress={() => runAction($, 'auto-compact', () => setSessionCompact($, null))}
            />
          )}
        </Box>

        {hasActions && (
          <Box flexDirection="column" marginTop={1}>
            <Text bold>Actions</Text>
            <Box flexDirection="row" gap={2}>
              <Button key="warm" label="🔥 Keep warm" onPress={() => runAction($, 'keep warm', () => keepWarm($))} />
              <Button key="compact" label="📦 Compact now" onPress={() => runAction($, 'compact', () => compactNow($))} />
              <Button
                key="handoff"
                label="🤝 Handoff"
                onPress={() => runAction($, 'handoff', () => startHandoff($, config))}
              />
            </Box>
          </Box>
        )}
        {handoff.status === 'pending' && <Text color="yellow">Handoff running…</Text>}
        {handoff.status === 'ready' && (
          <Box flexDirection="row">
            <Text color="green">Handoff ready ({formatTokens(handoff.text.length)} chars) </Text>
            <Button
              key="continue"
              label="Clear & continue"
              variant="primary"
              onPress={() => runAction($, 'clear & continue', () => clearAndContinue($))}
            />
            <Text> </Text>
            <Button key="discard" label="Discard" onPress={() => runAction($, 'discard', () => discardHandoff($))} />
          </Box>
        )}
      </Box>
    )
  })
cache-keeper/hooks/register.tsx lines 489–551 · Band
  on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
    if (e.props.hasSurvey) return next(e)
    const view = await computeView($, config)
    const handoff = await read($, handoffAtom)

    const { Box, Button, Text } = $.ui.resolve(e)
    if (handoff.status === 'ready') {
      return (
        <Box flexDirection="row" justifyContent="space-between">
          <Text color="green">Handoff ready.</Text>
          <Box flexDirection="row" flexShrink={0} gap={1}>
            <Button
              key="band-continue"
              label="Clear & continue"
              variant="primary"
              onPress={() => runAction($, 'clear & continue', () => clearAndContinue($))}
            />
            <Button key="band-discard" label="Discard" onPress={() => runAction($, 'discard', () => discardHandoff($))} />
          </Box>
        </Box>
      )
    }

    // Always-on bar: the figures at a glance, then the actions (hidden before the first reply and while a turn runs).
    const hasActions = view.phase !== 'empty' && view.phase !== 'running' && handoff.status === 'idle'

    // Figures on the left (growing to fill the row), buttons pinned to the right edge.
    return (
      <Box flexDirection="row" justifyContent="space-between">
        {/*
          One outlined pill per group: a faint rounded border, gray text, a small colored dot for status.
          height={1} holds the pill to one text row; without it the desktop pads the border well above and below the text.
        */}
        <Box flexDirection="row" flexGrow={1} flexShrink={1} gap={1}>
          {[...bandChips(view), ...(handoff.status === 'pending' ? [{ text: 'handoff running…', tone: 'warn' as const }] : [])].map(
            chip => (
              <Box flexDirection="row" flexShrink={0} borderStyle="round" borderDimColor paddingX={1} height={1}>
                {TONE_DOT_COLOR[chip.tone] && <Text color={TONE_DOT_COLOR[chip.tone]}>● </Text>}
                <Text dimColor>{chip.text}</Text>
              </Box>
            ),
          )}
        </Box>
        {/* One-glyph buttons to save width; the Details pane carries the same actions with word labels. */}
        <Box flexDirection="row" flexShrink={0} gap={1}>
          {hasActions && view.phase !== 'cold' && (
            <Button key="band-warm" label="🔥" onPress={() => runAction($, 'keep warm', () => keepWarm($))} />
          )}
          {hasActions && (
            <Button key="band-compact" label="📦" onPress={() => runAction($, 'compact', () => compactNow($))} />
          )}
          {hasActions && (
            <Button
              key="band-handoff"
              label="🤝"
              onPress={() => runAction($, 'handoff', () => startHandoff($, config))}
            />
          )}
          <Button key="band-details" label="📊" onPress={() => runAction($, 'details', () => openPane($))} />
        </Box>
      </Box>
    )
  })
Licence text (MIT)
MIT License

Copyright (c) 2026 etding

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.

What its code calls

drives Clauderemembers

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 6a2ba1b81a49 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 readEvery module hooks/hooks.json names was read.cache-keeper/hooks/register.tsx
ParsesEvery file parses as TypeScript or JavaScript.4 files parsed
All its code is in the modEvery import is a file of the mod or the engine's own module; no packages, no require.all its code is in the mod
ReadableNo 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 openNetwork 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 drawsThe 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 lineWhether its repository's own .claude-plugin/marketplace.json lists it, so it installs from that marketplace with the lines on its page.its repository's .claude-plugin/marketplace.json does not list it: no install line to give
Programs on WindowsWhether every program it starts through $.process exists on Windows (tail, date, open, osascript, /usr/… do not).runs no program a Windows PC lacks
NetworkWhether every fetch names its https host in the code.no network
ProgramsWhether 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 sendsWhether it both reads files or environment variables and reaches the network.reaches no network
Keys in the sourceWhether the source holds what looks like an API key or a private key.no keys in the source
LicenceAn 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's .claude-plugin/marketplace.json does not list it, so there is no install line to give. Read it as code, or follow its author's README.

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 "etding-cache-keeper" with its code and make me a pane like it

Search them from Claude: the MCP connector

Similar designs