modscode JA

modscode / Gallery / cache-clock

cache-clock

Shows how long Claude Code's prompt cache stays warm, how many tokens your next message re-sends, and what it costs now versus after the cache expires.

Code you can checkTerminal + desktopPaneBoxText

What it does

  • Draws a pane
  • Adds /cache
  • Hooks classic.SessionStart, session.start, turn.complete, turn.start and 1 more
  • Keeps its own state between turns
  • Calls the network

Good points

  • Starts no processes
  • Written in TypeScript
  • Writes no files

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-clock by XYZ Makes (pane), as modscode read it from the mod's code:
// https://modscode.com/gallery/xyzbuilds-cache-clock/
// 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: "Prompt cache" })
  on('ui.render', { component: 'Pane', requestId: 'my-pane' }, async ($, e) => {
    const { Box, Text } = $.ui.resolve(e)
    const label = '…'
    const why = '…'
    const bar = '…'
    const tokensText = '…'
    const moneyText = '…'
    const moneyText2 = '…'
    const name = '…'
    const o = '…'
    const hit = '…'
    const requests = '…'
    const durationText = '…'
    const cause = '…'
    const shortModel = '…'
    return (
      <Box flexDirection="column" paddingX={1}>
        <Box flexDirection="row" justifyContent="space-between">
          <Text bold>
            ⏱ Prompt cache
          </Text>
          <Text dimColor>
            {`${label} · ${why}`}
          </Text>
        </Box>
        <Text dimColor>
          ────────
        </Text>
        <Text>
          {`${bar} expired`}
        </Text>
        <Box flexDirection="column" marginTop={1}>
          <Text bold color="blue">
            NEXT MESSAGE
          </Text>
          <Text wrap="wrap">
            {`Re-sends ${tokensText} tokens of the ${tokensText} window.`}
          </Text>
          <Text>
            <Text color="green">
              {`cache warm    ${bar} `}
            </Text>
            <Text>
              {moneyText}
            </Text>
          </Text>
          <Text>
            <Text color="red">
              {`cache expired ${bar} `}
            </Text>
            <Text>
              {moneyText2}
            </Text>
          </Text>
          <Text dimColor wrap="wrap">
            {`${name} (price unknown, Opus 5.5 assumed) at API prices, before Claude's reply. Prices: Anthropic's pricing page, read ‹…`}
          </Text>
        </Box>
        <Box flexDirection="column" marginTop={1}>
          <Text bold color="cyan">
            WHAT TO DO
          </Text>
          <Text wrap="wrap">
            {`• ${o}`}
          </Text>
          <Text wrap="wrap">
            {`• ${o}`}
          </Text>
          <Text wrap="wrap">
            {`• ${o}`}
          </Text>
        </Box>
        <Text dimColor>
          ────────
        </Text>
        <Box flexDirection="column">
          <Text bold color="magenta">
            THIS SESSION
          </Text>
          <Text>
            <Text color="red">
              ○
            </Text>
            <Text color="red">
              ○
            </Text>
            <Text color="red">
              ○
            </Text>
          </Text>
          <Text wrap="wrap">
            {`hit ${hit}% · ${requests} requests · ${tokensText} read from cache · ${tokensText} written · ≈ ${moneyText} at API prices`}
          </Text>
          <Box flexDirection="column" marginTop={1}>
            <Text dimColor>
              Rebuilt:
            </Text>
            <Text wrap="wrap">
              {`${durationText} ago · ${tokensText} tokens · ${cause} · ${moneyText}`}
            </Text>
            <Text wrap="wrap">
              {`${durationText} ago · ${tokensText} tokens · ${cause} · ${moneyText}`}
            </Text>
            <Text wrap="wrap">
              {`${durationText} ago · ${tokensText} tokens · ${cause} · ${moneyText}`}
            </Text>
          </Box>
        </Box>
        <Text dimColor>
          ────────
        </Text>
        <Text wrap="wrap">
          <Text bold>
            {"Resets the cache: "}
          </Text>
          <Text>
            /model, fast mode on, adding an MCP server, /compact, a long pause.
          </Text>
        </Text>
        <Text wrap="wrap">
          <Text bold>
            {"Keeps it: "}
          </Text>
          <Text>
            editing files, skills, /rewind, subagents, permission modes.
          </Text>
        </Text>
        <Text dimColor wrap="wrap">
          {`Last request on ${shortModel} · context ${tokensText} tokens.`}
        </Text>
      </Box>
    )
  })
}

The mod's own code

Shown under the mod's licence (MIT); its text is below. Keep the notice if you copy these lines.

hooks/register.tsx lines 383–387 · Pane
  on('ui.render', { component: 'Pane', requestId: PANE }, async ($, e) => {
    const clock = await read($, clockAtom)
    const now = (await read($, nowAtom)) || (await $.clock.now())
    return paneView($, e, clock, now, Math.max(20, e.props.bodyColumns - 2))
  })
hooks/register.tsx lines 213–311 · Pane
function paneView($: EngineInterface, e: View, clock: Clock, now: number, width: number) {
  const { Box, Text } = $.ui.resolve(e)
  const rule = '─'.repeat(width)
  const last = clock.last
  const header = (
    <Box flexDirection="row" justifyContent="space-between">
      <Text bold>⏱ Prompt cache</Text>
      <Text dimColor>{`${clock.ttl.label} · ${clock.ttl.why}`}</Text>
    </Box>
  )
  if (!last) {
    return (
      <Box flexDirection="column" paddingX={1}>
        {header}
        <Text dimColor>{rule}</Text>
        <Text dimColor>Nothing cached yet: the first reply starts the clock.</Text>
      </Box>
    )
  }
  const price = priceFor(last.model)
  const next = nextCost(last, price, clock.ttl.ms)
  const phase = phaseOf(last, clock.ttl, clock.isWorking, now)
  const left = Math.max(0, last.at + clock.ttl.ms - now)
  const barWidth = Math.max(10, width - 22)
  const costWidth = Math.max(10, width - 26)
  const t = clock.totals
  const hit = Math.round((100 * t.read) / Math.max(1, t.read + t.write + t.input))
  const fresh = clock.base > 0 ? freshCost(clock.base, price, clock.ttl.ms) : undefined
  const compact = compactCost(last, price)
  const options: string[] =
    phase === 'expired'
      ? [
          `Continue: ≈ ${moneyText(next.cold)} for the next message, then ≈ ${moneyText(next.warm)} a message while warm.`,
          ...(fresh !== undefined ? [`Start fresh with /clear: ≈ ${moneyText(fresh)}. Claude forgets this conversation; save what you need to a file first.`] : []),
          `/compact first: re-reads all ${tokensText(next.tokens)} tokens without the cache to summarize them, then each message is small.`,
        ]
      : [
          `Keep going: ≈ ${moneyText(next.warm)} a short message while warm.`,
          `Stepping away for longer than ${phase === 'working' ? (clock.ttl.ms >= HOUR ? 'an hour' : '5 minutes') : durationText(left)}? /compact now ≈ ${moneyText(compact)}; once cold, the next message is ≈ ${moneyText(next.cold)}.`,
        ]
  return (
    <Box flexDirection="column" paddingX={1}>
      {header}
      <Text dimColor>{rule}</Text>
      <Text color={COLOR[phase]}>
        {phase === 'expired' ? `${bar(0, barWidth)} expired` : `${bar(phase === 'working' ? 1 : left / clock.ttl.ms, barWidth)} ${phase === 'working' ? 'in use' : `${durationText(left)} left`}`}
      </Text>
      <Box flexDirection="column" marginTop={1}>
        <Text bold color="blue">NEXT MESSAGE</Text>
        <Text wrap="wrap">{`Re-sends ${tokensText(next.tokens)} tokens${clock.window ? ` of the ${tokensText(clock.window)} window` : ''}.`}</Text>
        <Text>
          <Text color="green">{`cache warm    ${bar(next.warm / Math.max(next.cold, 1e-9), costWidth)} `}</Text>
          <Text>{moneyText(next.warm)}</Text>
        </Text>
        <Text>
          <Text color="red">{`cache expired ${bar(1, costWidth)} `}</Text>
          <Text>{moneyText(next.cold)}</Text>
        </Text>
        <Text dimColor wrap="wrap">{`${price.name}${price.isGuess ? ' (price unknown, Opus 5.5 assumed)' : ''} at API prices, before Claude's reply. Prices: ${pricedAt ? `Anthropic's pricing page, read ${durationText(now - pricedAt)} ago` : `built-in list of ${BUILT_IN_DATE}`}.`}</Text>
      </Box>
      <Box flexDirection="column" marginTop={1}>
        <Text bold color="cyan">WHAT TO DO</Text>
        {options.map((o, i) => (
          <Text key={`o-${i}`} wrap="wrap">{`• ${o}`}</Text>
        ))}
      </Box>
      <Text dimColor>{rule}</Text>
      <Box flexDirection="column">
        <Text bold color="magenta">THIS SESSION</Text>
        <Text>
          {clock.history.map((r, i) => (
            <Text key={`h-${i}`} color={r.isMiss ? 'red' : 'green'}>
              {r.isMiss ? '○' : '●'}
            </Text>
          ))}
        </Text>
        <Text wrap="wrap">{`hit ${hit}% · ${t.requests} requests · ${tokensText(t.read)} read from cache · ${tokensText(t.write)} written · ≈ ${moneyText(t.usd)} at API prices`}</Text>
        {clock.misses.length > 0 && (
          <Box flexDirection="column" marginTop={1}>
            <Text dimColor>Rebuilt:</Text>
            {clock.misses.map((m, i) => (
              <Text key={`m-${i}`} wrap="wrap">{`${durationText(now - m.at)} ago · ${tokensText(m.write)} tokens · ${m.cause ?? 'unknown'} · ${moneyText(m.usd)}`}</Text>
            ))}
          </Box>
        )}
      </Box>
      <Text dimColor>{rule}</Text>
      <Text wrap="wrap">
        <Text bold>Resets the cache: </Text>
        <Text>/model, fast mode on, adding an MCP server, /compact, a long pause.</Text>
      </Text>
      <Text wrap="wrap">
        <Text bold>Keeps it: </Text>
        <Text>editing files, skills, /rewind, subagents, permission modes.</Text>
      </Text>
      <Text dimColor wrap="wrap">{`Last request on ${shortModel(last.model)} · context ${tokensText(contextOf(last))} tokens.`}</Text>
    </Box>
  )
}
Licence text (MIT)
MIT License

Copyright (c) 2026 XYZ Makes LLC

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

networkenv 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 1447f239ed52 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.hooks/register.tsx
ParsesEvery file parses as TypeScript or JavaScript.3 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.https://platform.claude.com
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.reads environment variables and reaches the 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 "xyzbuilds-cache-clock" with its code and make me a pane like it

Search them from Claude: the MCP connector

Similar designs