modscode EN

modscode / 図鑑 / session-hud

session-hud

Session Tracker above the prompt box: context window with a /compact recommendation, 5-hour plan limit, prompt clocks and session cost.

確かめやすいコードターミナル+デスクトップバンドトーストBoxText

何をするか

  • プロンプトの上の帯・トーストを描く
  • ツールの呼び出しを見張る
  • prompt.submit・session.compact・session.start・turn.completeにフックする

良いところ

  • ネットワークに出ない
  • プロセスを起こさない
  • 小さい(243 行)
  • TypeScript で書かれている

作り始めるためのコード

2 種類あります。上のデザインから modscode が書いた雛形と、その Mod 自身のコードのうち描いている部分です。

雛形(register.tsx)

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

// Drawn like session-hud by Ofek Levy (band, toast), as modscode read it from the mod's code:
// https://modscode.com/gallery/ofeklevy11-session-hud/
// 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 } = $.ui.resolve(e)
    return (
      <Box flexDirection="column">
        <Text bold color="blueBright" wrap="truncate">
          ⚡ Session Tracker
        </Text>
        {await next(e)}
      </Box>
    )
  })

  on('session.start', async ($, e, next) => {
    const compactAt = '…'
    const clock = '…'
    await $.ui.toast(`💡 Context passed ${compactAt} tokens: Compact recommended, type /compact`)
    await $.ui.toast(`✅ Turn finished in ${clock}`)
    return next(e)
  })
}

Mod 自身のコード

Mod のライセンス(MIT)に従って載せています。全文は下にあります。写すときは著作権表示を残してください。

session-hud/hooks/register.tsx 111〜222 行 · バンド
  on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
    const below = await next(e)
    if (e.props.hasSurvey) return below

    const st = await read($, hud)
    const now = await $.clock.now()
    const { Box, Text } = $.ui.resolve(e)
    const W = Math.max(20, (e.props.bodyColumns ?? 80) - 6)

    // Section header: the mod's name
    const header = <Text bold color="blueBright" wrap="truncate">{'⚡ Session Tracker'}</Text>
    const five = st.limits.find(l => l.kind === 'five_hour')

    const ctxLeft = st.ctxTokens === null ? st.ctxWindow : Math.max(0, st.ctxWindow - st.ctxTokens)
    // Two clocks: the prompt running now (or the last one), and every prompt of the session added up
    const total = cleanTotal(st.totalSeconds) + (st.isRunning ? st.turnSeconds : 0)
    // Labels in blue, values in their own color
    const label = (t: string) => <Text bold color="blueBright">{t}</Text>

    // Side-by-side cards: each metric is a small titled column, and the cards wrap with the width
    const bar = (cells: number, pct: number | null) => {
      const p = pct ?? 0
      const filled = Math.max(pct === null ? 0 : 1, Math.min(cells, Math.round((p / 100) * cells)))
      return [
        <Text color={tone(p)}>{'█'.repeat(filled)}</Text>,
        <Text dimColor>{'░'.repeat(Math.max(0, cells - filled))}</Text>,
        <Text bold color={tone(p)}>{pct === null ? ' —' : ` ${Math.round(p)}%`}</Text>,
      ]
    }
    const reset5 = five ? inTime(five.resetsAt, now) : ''
    const card = (width: number, ...rowsOfSpans: any[][]) => (
      <Box flexDirection="column" width={width}>
        {rowsOfSpans.map(spans => <Text wrap="truncate">{spans}</Text>)}
      </Box>
    )
    const isOver = st.ctxTokens !== null && st.ctxWindow > 0 && st.ctxTokens >= compactAt(st.ctxWindow)
    const isHard = isOver && st.ctxTokens !== null && st.ctxTokens >= compactHard(st.ctxWindow)
    // Mods cannot press /compact for you here, so the card tells you what to type
    const compactHint = isOver
      ? <Text bold color={isHard ? 'red' : 'yellow'}>{'👉 Type /compact now'}</Text>
      : null
    const ctxNote = st.ctxTokens === null
      ? <Text dimColor>no data yet</Text>
      : isHard
        ? <Text bold color="red">{`⚠ ${short(st.ctxTokens)} · Compact recommended 300-400K+ (if 1M context window)`}</Text>
        : isOver
        ? <Text color="yellow">{`💡 ${short(st.ctxTokens)} · Compact recommended 300-400K+ (if 1M context window)`}</Text>
        : <Text dimColor>{`${short(ctxLeft)} left of ${short(st.ctxWindow)}`}</Text>
    const ctxCard = (w: number) => (
      <Box flexDirection="column" width={w}>
        <Text wrap="truncate">{label('🧠 Context window')}</Text>
        <Text wrap="truncate">{bar(Math.max(4, w - 6), st.ctxPercent)}</Text>
        <Text wrap="truncate">{ctxNote}</Text>
        {compactHint ? <Text wrap="truncate">{compactHint}</Text> : null}
      </Box>
    )
    const fiveCard = (w: number) => card(w,
      [label('⚡ 5-hour limit')],
      five ? bar(Math.max(4, w - 6), five.percent) : [<Text dimColor>after the first reply</Text>],
      [<Text dimColor>{reset5 ? `↻ ${reset5.replace('resets in ', '')}` : ''}</Text>],
    )
    const timeCard = (w: number) => card(w,
      [label('⏱ Prompt time')],
      [<Text dimColor>{st.isRunning ? 'now  ' : 'last  '}</Text>, <Text bold color={st.isRunning ? 'cyan' : undefined}>{clock(st.turnSeconds)}</Text>],
      [<Text dimColor>{'all   '}</Text>, <Text bold>{clock(total)}</Text>],
    )
    const costCard = (w: number) => card(w,
      [label('💵 Session cost')],
      [<Text bold color="green">{usd(st.costUsd)}</Text>],
      [<Text dimColor>{'this session'}</Text>],
    )
    // One line for the clocks and the cost, used when only two cards fit across
    const statsLine = (
      <Text wrap="truncate">
        {label('⏱ ')}<Text bold color={st.isRunning ? 'cyan' : undefined}>{clock(st.turnSeconds)}</Text>
        <Text dimColor>{st.isRunning ? ' now' : ' last'}</Text>
        <Text dimColor>{'  ·  '}</Text>
        {label('⌛ ')}<Text bold>{clock(total)}</Text><Text dimColor>{' all'}</Text>
        <Text dimColor>{'  ·  '}</Text>
        {label('💵 ')}<Text bold color="green">{usd(st.costUsd)}</Text>
      </Text>
    )

    const GAP = 3
    let rows: any[]
    if (W >= 96) {
      // Wide: four cards in one band
      const w = Math.floor((W - GAP * 3) / 4)
      rows = [<Box flexDirection="row" columnGap={GAP}>{ctxCard(w)}{fiveCard(w)}{timeCard(w)}{costCard(w)}</Box>]
    } else if (W >= 40) {
      // Medium and split view: the two gauges side by side, then one stats line
      const w = Math.floor((W - GAP) / 2)
      rows = [<Box flexDirection="row" columnGap={GAP}>{ctxCard(w)}{fiveCard(w)}</Box>, statsLine]
    } else {
      // Very narrow: one compact line per gauge, then the stats
      const cells = Math.max(4, W - 26)
      rows = [
        <Text wrap="truncate">{label('🧠 ')}{bar(cells, st.ctxPercent)}<Text dimColor>{st.ctxTokens === null ? '' : ` ${short(ctxLeft)} left`}</Text></Text>,
        <Text wrap="truncate">{label('⚡ ')}{five ? bar(cells, five.percent) : <Text dimColor>—</Text>}<Text dimColor>{reset5 ? ` ↻ ${reset5.replace('resets in ', '')}` : ''}</Text></Text>,
        statsLine,
      ]
      if (isOver) rows.push(<Text wrap="truncate" bold color={isHard ? 'red' : 'yellow'}>{'💡 Compact recommended · type /compact'}</Text>)
    }

    return (
      <Box flexDirection="column">
        {header}
        {rows}
        {below}
      </Box>
    )
  })
ライセンスの全文(MIT)
MIT License

Copyright (c) 2026 Ofek Levy

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.

コードが呼ぶもの

ツール呼び出し

コードから読み取ったデザイン

読み取ったコミットのソースから描いたもので、動かした結果ではありません。一覧は 3 回描き、条件はデスクトップアプリで描く最初の分岐を取り、動かしたときにだけ決まる値は仮の例(点線の下線)にするか省きます。色と書体はこのサイトのものです。

コードから読めること

2026-10-06 に読んだコミット c90cb1cd1a60 のソースから。最初のまとまりが載せる条件で、残りは自分で判断するための材料です。後のコミットは、次に読むまで見ていません。

載せる条件: 確かめやすいコード
入口を読んだhooks/hooks.json が名指すモジュールをすべて読んだ。session-hud/hooks/register.tsx
解析できるすべてのファイルが TypeScript か JavaScript として解析できる。1 ファイルを解析
コードが 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 ofeklevy11/claude-code-hud
/plugin install session-hud@claude-code-hud

入るのはマーケットプレイスの最新のコミットで、ここで読んだもの(c90cb1cd1a60)と違うことがあります。入れる前に見比べてください。

Claude に聞く

modscode のコネクタを入れると、Claude がこのデザイン・コードが触るもの・コードを読んで、それをもとに作れます。たとえば:

modscode のデザイン「ofeklevy11-session-hud」をコードごと読んで、同じようなペインを作って

Claude から探す: MCP コネクタ

似たデザイン