modscode / 図鑑 / long-live-the-claude
long-live-the-claude
Keeps long-running Claude Code sessions alive: a usage band above the prompt, prompt-cache keep-alive across idle gaps, and a graceful pause at 95% of the 5-hour limit that wakes the session when it resets.
何をするか
- プロンプトの上の帯・トーストを描く
- /long-run を足す
- ツールの呼び出しを見張る
- classic.PostCompact・classic.PostModelSwitch・prompt.submit・session.end ほか 6 個にフックする
- ターンをまたいで自分の状態を持つ
良いところ
- ネットワークに出ない
- プロセスを起こさない
- TypeScript で書かれている
- ファイルを書かない
作り始めるためのコード
2 種類あります。上のデザインから modscode が書いた雛形と、その Mod 自身のコードのうち描いている部分です。
雛形(register.tsx)
import type { Register } from 'claude-code'
// Drawn like long-live-the-claude by Lapis0x0 (band, status, toast), as modscode read it from the mod's code:
// https://modscode.com/gallery/lapis0x0-long-live-the-claude/
// 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 band above the prompt; what else goes there is drawn under it
on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
const { Box, Text, Client, Button } = $.ui.resolve(e)
const rest = '…'
const d = '…'
const d2 = '…'
const d3 = '…'
const d4 = '…'
const d5 = '…'
const d6 = '…'
const k = '…'
const d7 = '…'
const d8 = '…'
const d9 = '…'
const d10 = '…'
const d11 = '…'
const d12 = '…'
const pauseBadge = '…'
const d13 = '…'
const d14 = '…'
const d15 = '…'
return (
<Box flexDirection="column">
<Box alignItems="flex-start">
<Box position="relative" flexGrow={1} flexShrink={1} minWidth={0} paddingRight={3} columnGap={3} alignItems="flex-start">
<Box gap={1} alignItems="flex-start" flexShrink={0}>
<Box>
<Text dimColor>
5h
</Text>
</Box>
<Box flexDirection="column" flexShrink={1} minWidth={0}>
<Box gap={1} alignItems="center">
<Text color="error">
▰▰▰▰▰▰▰▰▱▱▱▱▱▱▱▱
</Text>
<Text>
{`${rest}%`}
</Text>
</Box>
<Text dimColor wrap="truncate-end">
{d}
</Text>
<Text dimColor wrap="truncate-end">
{d2}
</Text>
<Text dimColor wrap="truncate-end">
{d3}
</Text>
</Box>
</Box>
<Box gap={1} alignItems="flex-start" flexShrink={0}>
<Box>
<Text dimColor>
7d
</Text>
</Box>
<Box flexDirection="column" flexShrink={1} minWidth={0}>
<Box gap={1} alignItems="center">
<Text color="error">
▰▰▰▰▰▰▰▰▱▱▱▱▱▱▱▱
</Text>
<Text>
{`${rest}%`}
</Text>
</Box>
<Text dimColor wrap="truncate-end">
{d4}
</Text>
<Text dimColor wrap="truncate-end">
{d5}
</Text>
<Text dimColor wrap="truncate-end">
{d6}
</Text>
</Box>
</Box>
<Box gap={1} alignItems="flex-start" flexShrink={0}>
<Box flexDirection="column" flexShrink={1} minWidth={0}>
<Box gap={1} alignItems="center">
<Text dimColor>
ctx
</Text>
<Text>
{`${k} / ${k}`}
</Text>
</Box>
<Text dimColor wrap="truncate-end">
{d7}
</Text>
<Text dimColor wrap="truncate-end">
{d8}
</Text>
<Text dimColor wrap="truncate-end">
{d9}
</Text>
</Box>
</Box>
<Box gap={1} alignItems="flex-start" flexShrink={0}>
<Box flexDirection="column" flexShrink={1} minWidth={0}>
<Text dimColor wrap="truncate-end">
{d10}
</Text>
<Text dimColor wrap="truncate-end">
{d11}
</Text>
<Text dimColor wrap="truncate-end">
{d12}
</Text>
</Box>
</Box>
<Box position="absolute" top={0} left={0} right={0} bottom={0}>
<Client module="./click-probe.tsx" width="100%" height="100%" />
</Box>
</Box>
<Box gap={1} alignItems="center" flexShrink={0}>
<Box flexShrink={1} minWidth={0}>
<Text color="warning" wrap="truncate-end">
{pauseBadge}
</Text>
</Box>
<Box flexShrink={1} minWidth={0}>
<Text color="warning" wrap="truncate-end">
Retrying
</Text>
</Box>
<Box flexShrink={0}>
<Text dimColor>
Refreshing…
</Text>
</Box>
<Button label="Long run ✓" />
</Box>
</Box>
<Box columnGap={3} flexWrap="wrap" display="none">
<Text dimColor>
{d13}
</Text>
<Text dimColor>
{d14}
</Text>
<Text dimColor>
{d15}
</Text>
</Box>
{await next(e)}
</Box>
)
})
on('session.start', async ($, e, next) => {
const hhmm = '…'
const drop = '…'
await $.ui.toast(`Long run: paused, resumes at ${hhmm}`)
await $.ui.toast(`Long run: wake-up not delivered (${drop}); retrying in 1 minute`)
return next(e)
})
}
Mod 自身のコード
Mod のライセンス(MIT)に従って載せています。全文は下にあります。写すときは著作権表示を残してください。
hooks/register.tsx 920〜924 行 · バンド
on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
if (e.props.hasSurvey) return next(e)
return drawBand($, e)
})hooks/register.tsx 429〜588 行 · バンド
async function drawBand($: Engine, e: ResolveInput) {
const els = $.ui.resolve(e)
const { Box, Button, Text } = els
const Svg = 'Svg' in els ? els.Svg : undefined
const t = (await read($, now)) || Date.now()
const list = await read($, limits)
const hit = await read($, lastHitAt)
const w = await read($, warm)
const lr = await read($, longRun)
const ctx = await read($, context)
const isIdleTooLong = w.lastTurnAt !== null && t - w.lastTurnAt > IDLE_CAP_MS
// Keep-alive is actually working: long-run mode on, not stopped, not idle too long
const isWarming = lr.isOn && !w.isBroken && !isIdleTooLong
const five = list.find(x => x.kind === 'five_hour')
const week = list.find(x => x.kind === 'seven_day')
const left = hit === null ? null : hit + TTL_MS - t
// The ring's color: first whether the cache is near expiry or expired, then whether keep-alive
// is failing; otherwise the keep-alive color while it is on
const cacheTone =
left === null
? MUTED
: left <= 0
? DANGER
: left <= LEAD_MS
? WARN
: isWarming && w.isFailing
? WARN
: isWarming
? WARM
: OK
const dot = isWarming ? (w.isFailing ? WARN : WARM) : null
// SVG on the desktop, characters in the terminal
const meter = (pct: number, label: string, mark?: number) =>
Svg ? (
<Svg source={barSvg(pct, mark)} alt={label} width={BAR_W} height={BAR_H} />
) : (
<Text color={pct <= 20 ? 'error' : undefined} dimColor={pct > 20}>
{barText(pct)}
</Text>
)
const k = (n: number) => (n >= 1e6 ? `${Math.round(n / 1e5) / 10}M` : `${Math.round(n / 1000)}k`)
// ---- Main row: the standing readings and the buttons; its width does not change when expanded ----
const usage = (name: string, win: RateWindow) => {
// Shows what is left; percentUsed has at most one decimal and exceeds 100 past the limit
const rest = Math.max(0, Math.round((100 - win.percentUsed) * 10) / 10)
const resetIn = win.resetsAt === undefined ? null : Date.parse(win.resetsAt) - t
const p = resetIn === null ? null : project(win.kind, win.percentUsed, resetIn)
return (
<Box gap={1} alignItems="center">
{meter(rest, `${name} ${rest}% left`, p === null ? undefined : Math.max(0, p.restAtReset))}
<Text bold={rest <= 20}>{`${rest}%`}</Text>
</Box>
)
}
// Context against the compaction window (the same basis as /context's percentage), with no bar:
// it answers "how far from auto-compaction", not "how much is left"
const contextText = (c: ContextState & { tokens: number }) => {
const used = c.tokens / c.limit
const tone = used >= CONTEXT_DANGER ? 'error' : used >= CONTEXT_WARN ? 'warning' : undefined
return (
<Box gap={1} alignItems="center">
<Text dimColor>ctx</Text>
<Text color={tone} bold={tone === 'error'}>{`${k(c.tokens)} / ${k(c.limit)}`}</Text>
</Box>
)
}
const cacheText = left === null ? '—' : left > 0 ? countdown(left) : 'expired'
// ---- Details: click the band to expand. Where the surface has Client each detail sits right below
// its reading; elsewhere they fall back to a row of their own ----
const resetLines = (win: RateWindow) => {
if (win.resetsAt === undefined) return []
const resetIn = Date.parse(win.resetsAt) - t
const p = project(win.kind, win.percentUsed, resetIn)
// The bar's translucent part already shows what is projected to be left; here we only warn when it runs out early
return [`resets in ${roughly(resetIn)}`, p?.runsOutIn != null ? `runs out in ~${roughly(p.runsOutIn)}` : null]
}
// Long-run pause: a short badge in the main row
const wakeAt = lr.resetsAt === null ? null : lr.resetsAt + WAKE_DELAY_MS
const pauseBadge =
!lr.isOn || wakeAt === null
? null
: lr.phase === 'winding'
? 'Winding down'
: lr.phase === 'paused'
? `Paused · resumes ${hhmm(wakeAt)}${lr.held.length > 0 ? ` · ${lr.held.length} held` : ''}`
: null
// The details below the cache column: two lines at most, each truncated rather than wrapped, so
// they never push the buttons out
const held = lr.held.length
const keeperLines: (string | null)[] = !lr.isOn
? [w.note]
: lr.phase === 'winding' && wakeAt !== null
? [`Winding down · ${lr.isReminded ? 'model asked to wrap up' : 'asks at the next tool call'} · resumes ${hhmm(wakeAt)}`]
: lr.phase === 'paused' && wakeAt !== null
? [`Paused · resumes in ${roughly(wakeAt - t)} (${hhmm(wakeAt)})`, `${held} notification${held === 1 ? '' : 's'} held`]
: w.isBroken || w.isFailing
? [w.note]
: isIdleTooLong
? [`Idle over ${IDLE_CAP_MS / 3600_000}h, stopped`, 'resumes at the next request']
: hit === null
? ['Waiting for the next request']
: [`${lr.isIdle ? '[idle] · keep-alive only' : 'no [idle] · check-ins'} · kept warm ${w.count}×`, w.note]
const compactLine = ctx?.tokens !== undefined ? `${k(Math.max(0, ctx.compactAt - ctx.tokens))} to auto-compact` : null
const isText = (x: unknown): x is string => typeof x === 'string' && x !== ''
// Where the surface has Client, a transparent click probe covers the area left of the buttons:
// a click anywhere toggles the details. Without Client there are no clicks, so we fall back to
// the host's hover: hovering the band shows the details row.
// The probe must not cover the buttons: a probe layered above eats the button's click, and no
// positioning order wins over it
const Client = 'Client' in els ? els.Client : undefined
const isExpanded = await read($, expanded)
const probe = (key: string) =>
Client ? (
<Box position="absolute" top={0} left={0} right={0} bottom={0}>
<Client key={key} module="./click-probe.tsx" props={{ zone: 'band' }} width="100%" height="100%" />
</Box>
) : null
// One column: the standing reading on top and, when expanded, its details below.
// 5h and 7d pass a label: it stands on its own at the left (top-aligned, on the reading's line)
// and the details line up with the bar; ctx and cache pass none: the label is part of the
// reading and the details start at the column's left edge.
// The first three columns' details are no wider than their readings, so expanding does not shift
// the main row; the last column (cache and long run) may shrink and truncate instead of pushing the buttons
type El = ReturnType<typeof usage>
const column = (key: string, label: El | null, main: El, lines: unknown[], isLast = false) => {
const shown = Client && isExpanded ? lines.filter(isText) : []
const body = (
<Box key={`${key}-body`} flexDirection="column" flexShrink={isLast ? 1 : 0} minWidth={isLast ? 0 : undefined}>
{main}
{shown.map((d, i) => (
<Text key={`${key}-${i}`} dimColor wrap={isLast ? 'truncate-end' : undefined}>
{d}
</Text>
))}
</Box>
)
if (label === null) return body
return (
<Box key={key} gap={1} alignItems="flex-start" flexShrink={0}>
{label}
{body}
</Box>
)
}ライセンスの全文(MIT)
MIT License Copyright (c) 2026 Lapis0x0 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.
コードが呼ぶもの
Claude を動かすツール呼び出し保存
コードから読み取ったデザイン
読み取ったコミットのソースから描いたもので、動かした結果ではありません。一覧は 3 回描き、条件はデスクトップアプリで描く最初の分岐を取り、動かしたときにだけ決まる値は仮の例(点線の下線)にするか省きます。色と書体はこのサイトのものです。
コードから読めること
2026-10-06 に読んだコミット d0b535134857 のソースから。最初のまとまりが載せる条件で、残りは自分で判断するための材料です。後のコミットは、次に読むまで見ていません。
| 載せる条件: 確かめやすいコード | |
|---|---|
| 入口を読んだ | hooks/hooks.json が名指すモジュールをすべて読んだ。hooks/register.tsx |
| 解析できる | すべてのファイルが TypeScript か JavaScript として解析できる。2 ファイルを解析 |
| コードが Mod の中で完結 | import は Mod 自身のファイルかエンジンのモジュールだけ。パッケージも require もない。コードはすべて Mod の中 |
| 読める | 圧縮した行・eval・new Function・計算した道の import()・符号化した塊がない。圧縮・eval・符号化した塊なし |
| 呼び出しが見える | 通信とプログラム起動はその場で $.http.fetch・$.process.run と書き、他へ渡さない。外への呼び出しはすべてその場の $ で |
| 入れる前に自分で判断する材料 | |
| 描く場所 | コードから読んだ、描く先。ターミナル・デスクトップアプリ・両方・何も描かない(フックだけ: 見張りやプロンプトの書き換え)のどれか。出すだけで、外す理由にはしない。ターミナルとデスクトップアプリに同じように描く |
| 入れる手順 | リポジトリ自身の .claude-plugin/marketplace.json にこの Mod が載っていて、ページに書いた手順でそのマーケットプレイスから入れられるか。リポジトリの .claude-plugin/marketplace.json に載っており、そこから入れられる |
| Windows のプログラム | $.process で起動するプログラムが Windows にあるか(tail・date・open・osascript・/usr/… などは無い)。Windows にないプログラムを使わない |
| 通信 | fetch の送り先(https のホスト)がコードに書いてあるか。通信なし |
| プログラム | 起動するプログラムの名前がコードに書いてあり、シェル・インタプリタ・通信用の道具でないか。プログラムを起動しない |
| 読んで送る | ファイルや環境変数を読み、かつ通信するか。通信しない |
| ソースの鍵 | ソースに API キーや秘密鍵らしきものがあるか。ソースに鍵なし |
| ライセンス | オープンなライセンス(MIT・Apache-2.0・BSD・ISC・Unlicense・0BSD・CC0)で全文があれば、modscode にコードを載せる。違えばリンクだけ。MIT |
コードの文面を読んだだけで、安全の審査ではありません。動かしてはおらず、起動するプログラムの中で何が起きるかも見えません。入れる前の確認はあなたの役目です。 載せる条件
入れる
入れる前に、必ず自分で確かめてください。Mod はサンドボックスなしで、あなたの権限で動きます。modscode はこのコードの安全を保証しません。下のコードを読み(またはフォルダーで claude plugin validate .)、触るものを見て、読んだコミットを入れてください。
リポジトリがそのままマーケットプレイスです。このマーケットプレイスを足し(ターミナルでは次のコマンド、デスクトップアプリではプラグインの設定)、そこから Mod を入れます。
/plugin marketplace add Lapis0x0/long-live-the-claude/plugin install long-live-the-claude@long-live-the-claude入るのはマーケットプレイスの最新のコミットで、ここで読んだもの(d0b535134857)と違うことがあります。入れる前に見比べてください。
Claude に聞く
modscode のコネクタを入れると、Claude がこのデザイン・コードが触るもの・コードを読んで、それをもとに作れます。たとえば:
modscode のデザイン「lapis0x0-long-live-the-claude」をコードごと読んで、同じようなペインを作って似たデザイン
-
Claude に頼む…Timer● MonAprNo timer runningStopResume last CollapseFri week./meter.tsxUnbilled Wed h$1.24 · expenses MarMayToday, Oct 6This week
-
Claude に頼む…Notes⚠ A team of Never uses your Claude usage much faster.Showing:buildbuildbuildHide completed:buildbuildbuildSet team size:DefaultDefaultDefaultSet model:NotesNotesNotesWorkflowYour next prompt can hand work to Never Notes helpers.● Fix login · Tool agents42% AllCopy failed2h 10m● Fix login · Tool agents42% AllCopy failed2h 10m● Fix login · Tool agents42% AllCopy failed2h 10m
-
Open a file first: /crit-tui file <path>Reopen this one in the crit browser view.Claude に頼む…
-
Auto compact%System tools Compact▲Context is already at 42%, past Weekly%. Auto compact:NowAfter my next compactOnly in new chatsUsage limits show after the first reply.Auto compactToolsbuild42%Toolsbuild42%Toolsbuild42%Context12.4 free of 12.4k42% usedbuild12.4kbuild12.4kbuild12.4kClaude に頼む…claude-code-usage-quota: Compact
-
spending-effort-with-jev: no TypeSafe API key, so effort tips are off. Set it in /plugin.⚠ effort: long run, fuzzy spec → have Claude interview you, then go maxClaude に頼む…
-
✦ explain as pick how Claude answers×3 ● build3 ● build3 ● build▸ VideoClaude に頼む…