modscode EN

modscode / 図鑑 / tokenbreak

tokenbreak

Opt-in ads for Claude Code: a banner above the prompt and a Theater pane while Claude works. Unofficial, not affiliated with Anthropic.

確かめやすいコードターミナル+デスクトップペインバンドステータスライントーストBoxButtonLinkText

何をするか

  • プロンプトの上の帯・欄・トーストを描く
  • /ads を足す
  • session.attach・session.end・session.start・turn.complete ほか 2 個にフックする
  • ターンをまたいで自分の状態を持つ
  • ネットワークに出る

良いところ

  • プロセスを起こさない
  • TypeScript で書かれている
  • デスクトップ専用の分岐がある
  • エラーを扱う

作り始めるためのコード

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

雛形(register.tsx)

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

// Drawn like tokenbreak by Tokenbreak (pane, band, status, toast), as modscode read it from the mod's code:
// https://modscode.com/gallery/steven-3-tokenbreak/
// 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, Link, Button } = $.ui.resolve(e)
    const href = '…'
    const brand = '…'
    const headline = '…'
    const cta = '…'
    return (
      <Box flexDirection="column">
        <Box borderStyle="round" paddingX={1}>
          <Box flexDirection="row" gap={1} flexGrow={1}>
            <Text>
              ▎
            </Text>
            <Text>
              ●
            </Text>
            <Box flexGrow={1} flexShrink={1}>
              <Link href={`${href}`}>
                <Text wrap="truncate-end">
                  <Text bold>
                    {brand}
                  </Text>
                  {"  "}
                  {headline}
                </Text>
              </Link>
            </Box>
            <Link href={`${href}`}>
              <Text bold>
                {` ${cta} ↗ `}
              </Text>
            </Link>
            <Box flexDirection="row" gap={1} marginLeft={1}>
              <Text dimColor>
                sponsored
              </Text>
              <Text dimColor>
                ·
              </Text>
              <Button label="✕" plain dimColor />
            </Box>
          </Box>
        </Box>
        {await next(e)}
      </Box>
    )
  })

  // the pane: open it with $.ui.open({ id: 'my-pane', title: "Tokenbreak" })
  on('ui.render', { component: 'Pane', requestId: 'my-pane' }, async ($, e) => {
    const { Box, Text, Link, Button } = $.ui.resolve(e)
    const glyph = '…'
    const brand = '…'
    const headline = '…'
    const href = '…'
    const cta = '…'
    return (
      <Box flexDirection="column" gap={1}>
        <Box flexDirection="row" gap={1}>
          <Text bold>
            {`${glyph} ${brand}`}
          </Text>
          <Text dimColor>
            sponsored
          </Text>
        </Box>
        <Text>
          {headline}
        </Text>
        <Box flexDirection="row" gap={2}>
          <Link href={`${href}`}>
            <Text bold>
              {` ${cta} ↗ `}
            </Text>
          </Link>
          <Button label="🔊 mute" plain />
        </Box>
        <Text dimColor>
          Closes when Claude finishes · /ads pause hides ads
        </Text>
      </Box>
    )
  })

  on('session.start', async ($, e, next) => {
    const latest = '…'
    await $.ui.toast(`Tokenbreak ${latest} is required to keep earning. /ads update shows how.`)
    return next(e)
  })
}

Mod 自身のコード

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

plugins/tokenbreak/hooks/register.tsx 695〜805 行 · バンド
  on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
    if (e.viewport !== undefined) {
      run.seen = {
        columns: e.viewport.columns,
        rows: e.viewport.rows,
        isFullscreen: e.viewport.isFullscreen,
        maxRows: e.props.maxRows,
      }
    }

    const until = await read($, pausedUntil)
    const ad = currentBanner(await read($, ads), await read($, bannerIndex))

    const state = await read($, updateState)

    if (e.props.hasSurvey || until !== null || (ad === undefined && state.kind !== 'required')) {
      run.drawnBanner = undefined

      return next(e)
    }

    if (state.kind === 'required' || ad === undefined) {
      // Too old to earn: the update notice takes the ad's place, and nothing is counted.
      const { Box, Text } = $.ui.resolve(e)

      run.drawnBanner = undefined

      return (
        <Box width={e.props.bodyColumns} marginTop={1} flexDirection="row" gap={1}>
          <Text color={AD_YELLOW}>⬆</Text>
          <Box flexGrow={1} flexShrink={1}>
            <Text wrap="truncate-end">
              <Text bold>Update Tokenbreak to keep earning.</Text>
              {state.kind === 'required' ? ` Version ${state.latest} is out; you have ${MOD_VERSION}.` : ''}
            </Text>
          </Box>
          <Text backgroundColor={tint(AD_YELLOW, 0.22)} color={AD_YELLOW} bold>
            {' /ads update '}
          </Text>
        </Box>
      )
    }

    run.drawnBanner = ad.id

    const { Box, Text, Link, Button } = $.ui.resolve(e)
    const Image = e.surface === 'terminal' && arePicturesOn() ? $.ui.resolve(e).Image : undefined
    const style = await read($, bannerStyle)
    const href = linkable(ad.clickUrl)
    const accent = isHex(ad.accent) ? ad.accent : FALLBACK_ACCENT
    const cta = ad.cta ?? 'Learn more'
    // A logo only within LOGO_MAX_BYTES (parseBatch drops bigger ones): the band redraws
    // constantly, and a small picture goes in one short piece that a redraw can't cut.
    const mark =
      Image !== undefined && ad.logo !== undefined ? (
        <Image key="banner-logo" source={{ png: ad.logo.png }} columns={2} rows={1} alt={ad.glyph ?? ' '} />
      ) : (
        <Text color={accent}>{ad.glyph ?? '●'}</Text>
      )
    // Brand and headline are one link, so the whole line opens the ad.
    const words = (
      <Text wrap="truncate-end">
        <Text color={accent} bold>
          {ad.brand}
        </Text>
        {'  '}
        {ad.headline}
      </Text>
    )
    const action =
      href === undefined ? undefined : style === 'pill' ? (
        // The brand color on a dark tint of itself: reads as a button without a solid block of color.
        <Link href={href}>
          <Text backgroundColor={tint(accent, 0.22)} color={accent} bold>
            {` ${cta} ↗ `}
          </Text>
        </Link>
      ) : (
        <Link href={href}>
          <Text color={accent} bold underline>
            {`${cta} →`}
          </Text>
        </Link>
      )
    const row = (
      <Box flexDirection="row" gap={1} flexGrow={1}>
        {style === 'rule' && <Text color={accent}>▎</Text>}
        {mark}
        <Box flexGrow={1} flexShrink={1}>
          {href === undefined ? words : <Link href={href}>{words}</Link>}
        </Box>
        {action}
        <Box flexDirection="row" gap={1} marginLeft={1}>
          <Text dimColor>sponsored</Text>
          <Text dimColor>·</Text>
          <Button key="hide" label="✕" plain dimColor onPress={() => void hideFor($, 3_600_000)} />
        </Box>
      </Box>
    )

    // marginTop keeps a blank row between the banner and the spinner or transcript above it.
    return style === 'card' ? (
      <Box width={e.props.bodyColumns} borderStyle="round" borderColor={accent} paddingX={1}>
        {row}
      </Box>
    ) : (
      <Box width={e.props.bodyColumns} marginTop={1}>
        {row}
      </Box>
    )
  })
plugins/tokenbreak/hooks/register.tsx 807〜891 行 · ペイン
  on('ui.render', { component: 'Pane', requestId: 'tokenbreak-theater' }, async ($, e) => {
    const showing = await read($, theater)
    const list = await read($, ads)
    const isSoundOn = await read($, theaterSound)
    const ad = list.find(one => one.id === showing?.adId) ?? theaterOf(list)
    const href = linkable(ad.clickUrl)
    const accent = isHex(ad.accent) ? ad.accent : FALLBACK_ACCENT
    const { Box, Text, Link, Button } = $.ui.resolve(e)
    const isTextOnly = e.surface !== 'terminal' || !arePicturesOn()
    // The same parts as the banner: brand in its color, a dim label, a button in the brand's color.
    const card = (
      <Box flexDirection="column" gap={1}>
        <Box flexDirection="row" gap={1}>
          <Text color={accent} bold>
            {isTextOnly ? `${ad.glyph ?? '●'} ${ad.brand}` : ad.brand}
          </Text>
          <Text dimColor>sponsored</Text>
        </Box>
        <Text>{ad.headline}</Text>
        <Box flexDirection="row" gap={2}>
          {href !== undefined && (
            <Link href={href}>
              <Text backgroundColor={tint(accent, 0.22)} color={accent} bold>
                {` ${ad.cta ?? 'Learn more'} ↗ `}
              </Text>
            </Link>
          )}
          {ad.audio !== undefined && (
            // Mutes or unmutes; a mute is remembered. Sound always stops when the pane closes.
            <Button
              key="sound"
              label={isSoundOn ? '🔊 mute' : '🔇 sound'}
              plain
              dimColor={!isSoundOn}
              onPress={() => void toggleSound($, ad)}
            />
          )}
        </Box>
        <Text dimColor>Closes when Claude finishes · /ads pause hides ads</Text>
      </Box>
    )

    if (isTextOnly || e.surface !== 'terminal') {
      run.drawnCut = undefined

      return card
    }

    const { Image } = $.ui.resolve(e)
    const cuts = hasVideo(ad) ? cutsOf(ad) : []
    const art = cuts.length === 0 && ad.image === undefined ? theaterArt() : undefined
    const shapes =
      cuts.length > 0
        ? cuts.map(cut => ({ width: cut.width, height: cut.height }))
        : [{ width: ad.image?.width ?? art?.width ?? 16, height: ad.image?.height ?? art?.height ?? 9 }]
    // The cut and arrangement that show the biggest picture in this pane, tall or wide.
    const layout = theaterLayout(e.props.bodyColumns, e.props.scroll.bodyRows, shapes)
    const length = cuts.length > 0 ? lengthOf(ad, layout.shape) : 0

    run.drawnCut = cuts.length > 0 ? { adId: ad.id, index: layout.shape } : undefined

    // A video starts on its poster frame, or where playback is; playVideo swaps the rest in.
    const source: ImageSource =
      (length > 0 ? frameSource(ad, layout.shape, Math.max(0, run.frame ?? posterOf(length)) % length) : undefined) ??
      (ad.image !== undefined ? { png: ad.image.png } : { rgba: art?.rgba ?? '', width: shapes[0]?.width ?? 16, height: shapes[0]?.height ?? 9 })
    const picture = (
      <Image key="theater-image" source={source} columns={layout.columns} rows={layout.rows} alt={`${ad.brand}: ${ad.headline}`} />
    )

    return layout.mode === 'side' ? (
      <Box flexDirection="row" gap={2}>
        {picture}
        <Box flexDirection="column" flexGrow={1} flexShrink={1}>
          {card}
        </Box>
      </Box>
    ) : (
      <Box flexDirection="column" gap={1}>
        <Box flexDirection="row" justifyContent="center">
          {picture}
        </Box>
        {card}
      </Box>
    )
  })
ライセンスの全文(MIT)
MIT License

Copyright (c) 2026 Steven Spivak

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 に読んだコミット 289c676eb19c のソースから。最初のまとまりが載せる条件で、残りは自分で判断するための材料です。後のコミットは、次に読むまで見ていません。

載せる条件: 確かめやすいコード
入口を読んだhooks/hooks.json が名指すモジュールをすべて読んだ。plugins/tokenbreak/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 のホスト)がコードに書いてあるか。plugins/tokenbreak/hooks/register.tsx:225 fetch(`${run.endpoint}/api/v1/ads?formats=${FORMATS.join); plugins/tokenbreak/hooks/register.tsx:261 fetch(`${run.endpoint}/api/v1/impressions`)
プログラム起動するプログラムの名前がコードに書いてあり、シェル・インタプリタ・通信用の道具でないか。プログラムを起動しない
読んで送るファイルや環境変数を読み、かつ通信するか。通信するが、ファイルも環境変数も読まない
ソースの鍵ソースに API キーや秘密鍵らしきものがあるか。ソースに鍵なし
ライセンスオープンなライセンス(MIT・Apache-2.0・BSD・ISC・Unlicense・0BSD・CC0)で全文があれば、modscode にコードを載せる。違えばリンクだけ。MIT

コードの文面を読んだだけで、安全の審査ではありません。動かしてはおらず、起動するプログラムの中で何が起きるかも見えません。入れる前の確認はあなたの役目です。 載せる条件

入れる

入れる前に、必ず自分で確かめてください。Mod はサンドボックスなしで、あなたの権限で動きます。modscode はこのコードの安全を保証しません。下のコードを読み(またはフォルダーで claude plugin validate .)、触るものを見て、読んだコミットを入れてください。

リポジトリがそのままマーケットプレイスです。このマーケットプレイスを足し(ターミナルでは次のコマンド、デスクトップアプリではプラグインの設定)、そこから Mod を入れます。

/plugin marketplace add steven-3/tokenbreak
/plugin install tokenbreak@tokenbreak

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

Claude に聞く

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

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

Claude から探す: MCP コネクタ

似たデザイン