modscode EN

modscode / 図鑑 / spotify

spotify

Spotify inside Claude Code: player pane with album art and a visualizer, synced lyrics, a Claude DJ that learns your taste, a chime when Claude finishes or needs you, a focus timer, your library, a session recap, and a settings page.

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

何をするか

  • プロンプトの上の帯・欄・ステータス行・トーストを描く
  • /spotify を足す
  • ツールの呼び出しを見張る(止めることがある)
  • classic.Notification・prompt.submit・session.start・turn.complete ほか 2 個にフックする
  • ターンをまたいで自分の状態を持つ

良いところ

  • TypeScript で書かれている
  • デスクトップ専用の分岐がある
  • エラーを扱う
  • ファイルを書かない

作り始めるためのコード

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

雛形(register.tsx)

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

// Drawn like spotify by jewdev (pane, band, status, toast), as modscode read it from the mod's code:
// https://modscode.com/gallery/jewdev-spotify/
// 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, Button } = $.ui.resolve(e)
    const shout = '…'
    const clockLeft = '…'
    const title = '…'
    const artists = '…'
    const clock = '…'
    const clock2 = '…'
    const busyText = '…'
    const line = '…'
    return (
      <Box flexDirection="column">
        <Text bold wrap="wrap">
          {shout}
        </Text>
        <Box flexDirection="row" gap={1}>
          <Text color="yellow" bold>
            ◎ Focus
            {" "}
            {clockLeft}
          </Text>
          <Button label="stop" plain dimColor />
        </Box>
        <Box flexDirection="row" gap={1}>
          <Text>
            ♫
          </Text>
          <Box flexShrink={1}>
            <Text wrap="truncate-end">
              <Text bold>
                {title}
              </Text>
              <Text dimColor>
                {" — "}
                {artists}
              </Text>
            </Text>
          </Box>
          <Text dimColor>
            {clock}
            /
            {clock2}
          </Text>
          <Button label={`${busyText}`} plain />
          <Button label={`${busyText}`} plain />
          <Button label={`${busyText}`} plain />
          <Button label={`${busyText}`} plain />
          <Button label="☰" plain dimColor />
        </Box>
        <Text italic dimColor wrap="truncate-end">
          {"  ♪ "}
          {line}
        </Text>
        {await next(e)}
      </Box>
    )
  })

  // the pane: open it with $.ui.open({ id: 'my-pane', title: "Spotify" })
  on('ui.render', { component: 'Pane', requestId: 'my-pane' }, async ($, e) => {
    const { Box, Button, Text, Input } = $.ui.resolve(e)
    const title = '…'
    const artists = '…'
    const album = '…'
    const clock = '…'
    const clock2 = '…'
    const repeat = '…'
    const line = '…'
    const busyText = '…'
    const message = '…'
    const playLabel = '…'
    const title2 = '…'
    const subtitle = '…'
    const title3 = '…'
    const subtitle2 = '…'
    const title4 = '…'
    const subtitle3 = '…'
    const title5 = '…'
    const subtitle4 = '…'
    const title6 = '…'
    const subtitle5 = '…'
    const title7 = '…'
    const subtitle6 = '…'
    const name = '…'
    const type = '…'
    return (
      <Box flexDirection="column" gap={1}>
        <Box flexDirection="row" flexWrap="wrap" columnGap={1}>
          <Button label="Player" hotkey="1" variant="primary" />
          <Button label="Lyrics" hotkey="2" variant="primary" />
          <Button label="DJ" hotkey="3" variant="primary" />
          <Button label="Recap" hotkey="4" variant="primary" />
          <Button label="Library" hotkey="5" variant="primary" />
          <Button label="Settings" hotkey="6" variant="primary" />
        </Box>
        <Box flexDirection="row" gap={2}>
          <Box flexDirection="column" flexShrink={1}>
            <Text bold wrap="truncate-end">
              {"♫ "}
              {title}
            </Text>
            <Text wrap="truncate-end">
              {artists}
            </Text>
            <Text dimColor wrap="truncate-end">
              {album}
            </Text>
            <Text>
              <Text>
                ━━━━━━━━●────────
              </Text>
              <Text dimColor>
                {" "}
                {clock}
                {" / "}
                {clock2}
              </Text>
            </Text>
            <Text dimColor wrap="truncate-end">
              unknown device
              {" · vol "}
              ?
              {"% · shuffle "}
              on
              {" · repeat "}
              {repeat}
            </Text>
            <Text italic dimColor wrap="truncate-end">
              {"♪ "}
              {line}
            </Text>
          </Box>
        </Box>
        <Box flexDirection="row" flexWrap="wrap" columnGap={1}>
          <Button label={`${busyText}`} hotkey="b" />
          <Button label={`${busyText}`} hotkey="p" variant="primary" />
          <Button label={`${busyText}`} hotkey="n" />
          <Button label={`${busyText}`} hotkey="d" />
          <Button label={`${busyText}`} hotkey="u" />
          <Button label={`${busyText}`} hotkey="s" />
          <Button label={`${busyText}`} hotkey="r" />
          <Button label={`${busyText}`} hotkey="l" />
        </Box>
        <Text wrap="wrap">
          {message}
        </Text>
        <Input label="Search" placeholder="song · artist: … · album: … · playlist: …" submitLabel={`${busyText}`} />
        <Box flexDirection="column">
          <Box flexDirection="row" gap={1}>
            <Text bold>
              Results
            </Text>
            <Button label="clear" plain dimColor />
          </Box>
          <Box flexDirection="row" gap={1}>
            <Button label={`${playLabel}`} plain />
            <Text>
              {" "}
            </Text>
            <Box flexShrink={1}>
              <Text wrap="truncate-end">
                {title2}
                <Text dimColor>
                  {" — "}
                  {subtitle}
                </Text>
              </Text>
            </Box>
          </Box>
          <Box flexDirection="row" gap={1}>
            <Button label={`${playLabel}`} plain />
            <Text>
              {" "}
            </Text>
            <Box flexShrink={1}>
              <Text wrap="truncate-end">
                {title3}
                <Text dimColor>
                  {" — "}
                  {subtitle2}
                </Text>
              </Text>
            </Box>
          </Box>
          <Box flexDirection="row" gap={1}>
            <Button label={`${playLabel}`} plain />
            <Text>
              {" "}
            </Text>
            <Box flexShrink={1}>
              <Text wrap="truncate-end">
                {title4}
                <Text dimColor>
                  {" — "}
                  {subtitle3}
                </Text>
              </Text>
            </Box>
          </Box>
        </Box>
        <Box flexDirection="column">
          <Text bold>
            Up next
          </Text>
          <Text wrap="truncate-end" dimColor>
            01
            {". "}
            {title5}
            {" — "}
            {subtitle4}
          </Text>
          <Text wrap="truncate-end" dimColor>
            01
            {". "}
            {title6}
            {" — "}
            {subtitle5}
          </Text>
          <Text wrap="truncate-end" dimColor>
            01
            {". "}
            {title7}
            {" — "}
            {subtitle6}
          </Text>
        </Box>
        <Box flexDirection="column">
          <Box flexDirection="row" gap={1}>
            <Text bold>
              Devices
            </Text>
            <Button label={`${busyText}`} plain dimColor />
          </Box>
          <Text>
            {`▶ ${name} (${type})`}
          </Text>
          <Text>
            {`▶ ${name} (${type})`}
          </Text>
          <Text>
            {`▶ ${name} (${type})`}
          </Text>
          <Button label={`${busyText}`} plain />
          <Button label={`${busyText}`} plain />
          <Button label={`${busyText}`} plain />
        </Box>
        <Box>
          <Button label={`${busyText}`} plain dimColor />
        </Box>
      </Box>
    )
  })

  on('session.start', async ($, e, next) => {
    const title = '…'
    const artists = '…'
    const errText = '…'
    await $.ui.status(`♫ ${title} — ${artists}`)
    await $.ui.toast(`Spotify login failed: ${errText}`)
    await $.ui.toast(`♫ ${title} — ${artists}`)
    return next(e)
  })
}

Mod 自身のコード

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

spotify/hooks/register.tsx 1887〜1941 行 · バンド
  on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
    if (e.props.hasSurvey) return next(e)
    const s = await read($, settings)
    const GREEN = accentOf(s)
    const shout = await read($, flash)
    const f = await read($, focus)
    const left = f ? await read($, focusLeft) : 0
    const p = isOn(s, 'band') ? await read($, player) : null
    if (!p && !shout && !f) return next(e)
    const { Box, Text, Button } = $.ui.resolve(e)
    const line = p && isOn(s, 'bandLyrics') ? await currentLyric($) : undefined
    const canControl = (await read($, premium)) !== false
    const busy = await read($, busyKeys)

    return (
      <Box flexDirection="column">
        {shout !== '' && (
          <Text color={GREEN} bold wrap="wrap">
            {shout}
          </Text>
        )}
        {f && (
          <Box flexDirection="row" gap={1}>
            <Text color={f.phase === 'focus' ? GREEN : 'yellow'} bold>
              {f.phase === 'focus' ? '◎ Focus' : '☕ Break'} {clockLeft(left * 1000)}
            </Text>
            <Button key="focus-stop" label="stop" plain dimColor onPress={() => quiet(stopFocus($))} />
          </Box>
        )}
        {p && (
          <Box flexDirection="row" gap={1}>
            <Text color={GREEN}>{p.isPlaying ? '♫' : '⏸'}</Text>
            <Box flexShrink={1}>
              <Text wrap="truncate-end">
                <Text bold>{p.title}</Text>
                <Text dimColor> — {p.artists}</Text>
              </Text>
            </Box>
            {isOn(s, 'bandTime') && e.props.bodyColumns > 70 && <Text dimColor>{clock(p.progressMs)}/{clock(p.durationMs)}</Text>}
            {canControl && isOn(s, 'bandControls') && <Button key="band-prev" label={busyText(busy, 'band-prev', '⏮', '…')} plain onPress={() => quiet(withBusy($, 'band-prev', () => back($)))} />}
            {canControl && isOn(s, 'bandControls') && <Button key="band-toggle" label={busyText(busy, 'band-toggle', p.isPlaying ? '⏸' : '▶', '…')} plain onPress={() => quiet(withBusy($, 'band-toggle', () => toggle($)))} />}
            {canControl && isOn(s, 'bandControls') && <Button key="band-next" label={busyText(busy, 'band-next', '⏭', '…')} plain onPress={() => quiet(withBusy($, 'band-next', () => skip($)))} />}
            {isOn(s, 'bandControls') && <Button key="band-like" label={busyText(busy, 'band-like', p.liked ? '♥' : '♡', '…')} plain onPress={() => quiet(withBusy($, 'band-like', () => like($, undefined)))} />}
            {isOn(s, 'bandControls') && <Button key="band-open" label="☰" plain dimColor onPress={() => quiet(openPane($, undefined))} />}
          </Box>
        )}
        {line !== undefined && p?.isPlaying && (
          <Text italic color={GREEN} dimColor wrap="truncate-end">
            {'  ♪ '}
            {line}
          </Text>
        )}
      </Box>
    )
  })
spotify/hooks/register.tsx 1944〜2103 行 · ペイン
  on('ui.render', { component: 'Pane', requestId: PANE }, async ($, e) => {
    const ui = $.ui.resolve(e)
    const { Box, Text, Button } = ui
    const width = Math.max(20, e.props.bodyColumns)
    paneColumns = width
    const height = e.viewport?.rows ?? 30
    const isAuthed = await read($, authed)
    const message = await read($, notice)
    const busy = await read($, busyKeys)
    const s = await read($, settings)
    const GREEN = accentOf(s)
    const good = message.startsWith('✓')
    const messageLine = message !== '' && (
      <Text color={good ? GREEN : undefined} dimColor={!good} wrap="wrap">
        {message}
      </Text>
    )

    if (!isAuthed) {
      return (
        <Box flexDirection="column" gap={1}>
          <Text bold color={GREEN}>Spotify</Text>
          <Text>Not connected.</Text>
          <Box flexDirection="column">
            <Text dimColor wrap="wrap">1. Create an app at developer.spotify.com/dashboard (Web API, redirect URI {REDIRECT_URI})</Text>
            <Text dimColor>2. /spotify setup &lt;client-id&gt;</Text>
            <Text dimColor>3. Press Log in, or run /spotify login</Text>
          </Box>
          <Box>
            <Button key="login" label={busyText(busy, 'login', 'Log in', 'Opening browser…')} variant="primary" hotkey="l" onPress={() => quiet(withBusy($, 'login', () => pressLogin($)))} />
          </Box>
          {messageLine}
        </Box>
      )
    }

    const current = await read($, tab)
    const p = await read($, player)
    const free = (await read($, premium)) === false
    const tabButton = (key: SpotifyTab, label: string, hotkey: string) => (
      <Button
        key={`tab-${key}`}
        label={label}
        hotkey={hotkey}
        variant={current === key ? 'primary' : undefined}
        dimColor={current !== key}
        onPress={() => quiet(showTab($, key))}
      />
    )
    const tabs = (
      <Box flexDirection="row" flexWrap="wrap" columnGap={1}>
        {tabButton('player', 'Player', '1')}
        {tabButton('lyrics', 'Lyrics', '2')}
        {tabButton('dj', 'DJ', '3')}
        {tabButton('recap', 'Recap', '4')}
        {tabButton('library', 'Library', '5')}
        {tabButton('settings', 'Settings', '6')}
      </Box>
    )
    const header = p ? (
      <Text wrap="truncate-end">
        <Text color={GREEN}>{p.isPlaying ? '♫ ' : '⏸ '}</Text>
        <Text bold>{p.title}</Text>
        <Text dimColor> — {p.artists}</Text>
      </Text>
    ) : (
      <Text dimColor>Nothing playing.</Text>
    )
    const playLabel = (key: string, isCurrent: boolean) => busyText(busy, key, free ? '↗' : isCurrent && p?.isPlaying ? '♫' : '▶', '…')

    // ----- lyrics tab -----
    if (current === 'lyrics') {
      const l = await read($, lyrics)
      const idx = await read($, lyricIndex)
      const offset = await read($, lyricOffset)
      const room = Math.max(5, Math.min(24, height - 10))
      let body
      if (!isOn(s, 'lyrics')) body = <Text dimColor>Lyrics are off. Turn them on in Settings (6).</Text>
      else if (!p) body = <Text dimColor>Start a track to see its lyrics.</Text>
      else if (!l || l.trackId !== p.id || l.status === 'loading') body = <Text dimColor>Looking up lyrics…</Text>
      else if (l.status === 'instrumental') body = <Text dimColor>♪ Instrumental ♪</Text>
      else if (l.status === 'missing') body = <Text dimColor>No lyrics found on LRCLIB for this track.</Text>
      else if (l.status === 'error') body = <Text dimColor>Could not reach LRCLIB.</Text>
      else if (l.status === 'plain') {
        body = (
          <Box flexDirection="column">
            <Text dimColor italic>Unsynced lyrics</Text>
            {l.lines.slice(0, room).map(x => <Text wrap="wrap">{x.text || ' '}</Text>)}
          </Box>
        )
      } else {
        const start = Math.max(0, Math.min(Math.max(0, idx) - Math.floor(room / 3), l.lines.length - room))
        body = (
          <Box flexDirection="column">
            {l.lines.slice(start, start + room).map((x, k) => {
              const i = start + k
              return (
                <Button
                  key={`ly-${i}`}
                  plain
                  label={`${i === idx ? '▶ ' : '  '}${x.text || '♪'}`}
                  dimColor={i !== idx}
                  onPress={() => quiet(seekTo($, x.t - offset))}
                />
              )
            })}
            <Box flexDirection="row" columnGap={1}>
              <Text dimColor>timing{offset !== 0 ? ` ${offset > 0 ? '+' : ''}${offset / 1000}s` : ''}:</Text>
              <Button key="ly-earlier" label="earlier" hotkey="z" plain dimColor onPress={() => quiet(nudgeLyrics($, 500))} />
              <Button key="ly-later" label="later" hotkey="x" plain dimColor onPress={() => quiet(nudgeLyrics($, -500))} />
              {offset !== 0 && <Button key="ly-reset" label="reset" hotkey="c" plain dimColor onPress={() => quiet(nudgeLyrics($, null))} />}
            </Box>
            <Text dimColor>press a line to jump there · lyrics from lrclib.net</Text>
          </Box>
        )
      }
      return (
        <Box flexDirection="column" gap={1}>
          {tabs}
          {header}
          {body}
        </Box>
      )
    }

    // ----- DJ tab -----
    if (current === 'dj') {
      const d = await read($, dj)
      const auto = isOn(s, 'autopilot')
      return (
        <Box flexDirection="column" gap={1}>
          {tabs}
          {header}
          <Box flexDirection="column">
            <Text bold>Claude DJ</Text>
            {d.status === 'idle' && <Text dimColor wrap="wrap">Picks music for what you are working on in this session, then plays or queues it.</Text>}
            {d.status === 'thinking' && <Text color={GREEN}>Reading the session and digging through crates…</Text>}
            {d.status === 'error' && <Text color="yellow" wrap="wrap">{d.reason}</Text>}
            {d.status === 'done' && (
              <Box flexDirection="column">
                <Text>
                  <Text color={GREEN} bold>{d.vibe}</Text>
                  <Text dimColor> · {d.source === 'autopilot' ? 'autopilot' : 'on request'} at {hhmm(d.at)}</Text>
                </Text>
                <Text italic wrap="wrap">{d.reason}</Text>
              </Box>
            )}
          </Box>
          {d.picks.length > 0 && (
            <Box flexDirection="column">
              {d.picks.map((x, i) => (
                <Box flexDirection="row" gap={1}>
                  <Button key={`dj-play-${i}`} label={playLabel(`dj-play-${i}`, p?.uri === x.uri)} plain onPress={() => quiet(withBusy($, `dj-play-${i}`, () => playPick($, x)))} />
                  <Box flexShrink={1}>
                    <Text wrap="truncate-end">
                      {x.title}
                      <Text dimColor> — {x.subtitle}</Text>
                    </Text>
                  </Box>
                </Box>
ライセンスの全文(MIT)
MIT License

Copyright (c) 2026 jewdev

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

載せる条件: 確かめやすいコード
入口を読んだhooks/hooks.json が名指すモジュールをすべて読んだ。spotify/hooks/register.tsx
解析できるすべてのファイルが TypeScript か JavaScript として解析できる。5 ファイルを解析
コードが 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 のホスト)がコードに書いてあるか。spotify/hooks/register.tsx:484 fetch(`${ACCOUNTS}/api/token`); spotify/hooks/register.tsx:654 fetch(`${API}${path}`); spotify/hooks/register.tsx:656 fetch(`${API}${path}`)
プログラム起動するプログラムの名前がコードに書いてあり、シェル・インタプリタ・通信用の道具でないか。spotify/hooks/register.tsx:340 powershell.exe(シェル・インタプリタ); spotify/hooks/register.tsx:358 powershell.exe(シェル・インタプリタ); spotify/hooks/register.tsx:539 powershell.exe(シェル・インタプリタ); spotify/hooks/register.tsx:558 powershell.exe(シェル・インタプリタ); spotify/hooks/register.tsx:959 powershell.exe(シェル・インタプリタ)
読んで送るファイルや環境変数を読み、かつ通信するか。reads environment variables and files and reaches the network
ソースの鍵ソースに API キーや秘密鍵らしきものがあるか。ソースに鍵なし
ライセンスオープンなライセンス(MIT・Apache-2.0・BSD・ISC・Unlicense・0BSD・CC0)で全文があれば、modscode にコードを載せる。違えばリンクだけ。MIT

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

入れる

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

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

/plugin marketplace add jewdev/claude-spotify-mod
/plugin install spotify@claude-spotify-mod

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

Claude に聞く

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

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

Claude から探す: MCP コネクタ

似たデザイン