modscode JA

modscode / Gallery / now-playing

now-playing

Now Playing pane, status line and model tool for Apple Music and Spotify on macOS

Code you can checkTerminal + desktopPaneStatus lineToastBoxButtonText

What it does

  • Draws a pane, toasts
  • Adds /music
  • Watches mcp__now-playing__music calls and can refuse them
  • Hooks session.start, ui.close
  • Keeps its own state between turns

Good points

  • No network calls
  • Written in TypeScript
  • Has a desktop-specific branch
  • Handles errors

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 now-playing by Jimmy Hsiao (pane, status, toast), as modscode read it from the mod's code:
// https://modscode.com/gallery/fatmylin-now-playing/
// 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: "Now Playing" })
  on('ui.render', { component: 'Pane', requestId: 'my-pane' }, async ($, e) => {
    const { Box, Button, Text } = $.ui.resolve(e)
    const label = '…'
    const i = '…'
    const formatTime = '…'
    const formatTime2 = '…'
    const repeat = '…'
    const volume = '…'
    return (
      <Box flexDirection="column">
        <Box flexDirection="row" justifyContent="center">
          <Box flexDirection="row" columnGap={3}>
            <Button label={`${label} ♪`} hotkey={`${i}`} plain />
            <Button label={`${label} ♪`} hotkey={`${i}`} plain />
            <Button label={`${label} ♪`} hotkey={`${i}`} plain />
          </Box>
        </Box>
        <Box height={1} />
        <Box flexDirection="row" justifyContent="center" />
        <Box height={1} />
        <Box flexDirection="row" justifyContent="center">
          <Text bold />
        </Box>
        <Box flexDirection="row" justifyContent="center">
          <Text bold />
        </Box>
        <Box flexDirection="row" justifyContent="center">
          <Text bold />
        </Box>
        <Box flexDirection="row" justifyContent="center">
          <Text />
        </Box>
        <Box flexDirection="row" justifyContent="center">
          <Text />
        </Box>
        <Box flexDirection="row" justifyContent="center">
          <Text />
        </Box>
        <Box flexDirection="row" justifyContent="center">
          <Text dimColor />
        </Box>
        <Box flexDirection="row" justifyContent="center">
          <Text dimColor />
        </Box>
        <Box flexDirection="row" justifyContent="center">
          <Text dimColor />
        </Box>
        <Box height={1} />
        <Box flexDirection="row" justifyContent="center">
          <Text dimColor wrap="truncate-end">
            {" "}
          </Text>
        </Box>
        <Box flexDirection="row" justifyContent="center">
          <Text bold wrap="truncate-end">
            {" "}
          </Text>
        </Box>
        <Box flexDirection="row" justifyContent="center">
          <Text dimColor wrap="truncate-end">
            {" "}
          </Text>
        </Box>
        <Box flexDirection="row" justifyContent="center">
          <Text dimColor>
            No synced lyrics
          </Text>
        </Box>
        <Box height={1} />
        <Box flexDirection="row">
          <Text>
            ━━━━━━━━
          </Text>
          <Text bold>
            ╸
          </Text>
          <Text dimColor>
            ────────
          </Text>
        </Box>
        <Box flexDirection="row" justifyContent="space-between">
          <Text dimColor>
            {formatTime}
          </Text>
          <Text dimColor>
            {formatTime2}
          </Text>
        </Box>
        <Box height={1} />
        <Box flexDirection="row" justifyContent="center">
          <Box flexDirection="row" columnGap={4}>
            <Button label="⏮" hotkey="b" plain />
            <Button label="⏸" hotkey="k" plain />
            <Button label="⏭" hotkey="n" plain />
            <Button label="♥" hotkey="f" plain />
          </Box>
        </Box>
        <Box flexDirection="row" justifyContent="center">
          <Box flexDirection="row" columnGap={3}>
            <Box flexDirection="row" columnGap={1}>
              <Text>
                ●
              </Text>
              <Button label="⇄ Shuffle on" hotkey="s" plain />
              <Text>
                {" "}
              </Text>
            </Box>
            <Box flexDirection="row" columnGap={1}>
              <Text>
                ●
              </Text>
              <Button label={`↻ Repeat ${repeat}`} hotkey="r" plain />
            </Box>
          </Box>
        </Box>
        <Box flexDirection="row" justifyContent="center">
          <Box flexDirection="row" columnGap={1}>
            <Button label="−" hotkey="d" plain dimColor />
            <Text dimColor>
              {"vol "}
              {volume}
            </Text>
            <Button label="+" hotkey="u" plain dimColor />
            <Button label="lyrics off" hotkey="l" plain dimColor />
          </Box>
        </Box>
      </Box>
    )
  })

  on('session.start', async ($, e, next) => {
    const app = '…'
    const stderr = '…'
    const what = '…'
    const error = '…'
    await $.ui.toast(`Could not open ${app}: ${stderr}`)
    await $.ui.toast(`${what} failed: ${error}`)
    return next(e)
  })
}

The mod's own code

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

plugins/now-playing/hooks/register.tsx lines 508–631 · Pane
  on('ui.render', { component: 'Pane', requestId: PANE }, async ($, e) => {
    const players = await read($, playersAtom)
    const active = await read($, trackAtom)
    const picked = await read($, sourceAtom)
    const covers = await read($, coversAtom)
    const artMode = await read($, artModeAtom)
    await read($, tickAtom) // subscribes the pane to the 1 s redraw
    const lyricsOn = await read($, lyricsOnAtom)
    await read($, lyricsRevAtom) // redraws when a lyrics fetch lands
    const now = await $.clock.now()
    const width = Math.max(1, e.props.bodyColumns)

    // An empty list means no poll has answered yet, which is not the same as
    // a poll that found nothing installed.
    const installed = players.filter(p => p.isInstalled)
    const shown: PlayerApp = picked ?? active?.app ?? installed[0]?.app ?? 'Music'
    const player = players.find(p => p.app === shown)
    const track = player?.track ?? null

    // The pane redraws on success; a control that failed says so in a toast.
    const press = (action: Action, value?: number) => async () => {
      try {
        const result = await control($, action, shown, value)
        if (!result.startsWith(`${shown} is playing`) && !result.startsWith(`${shown} is paused`)) $.ui.toast(result)
      } catch (error) {
        $.ui.toast(`${action} failed: ${String(error)}`)
      }
    }

    const cover = covers[shown]
    const hasCover = track !== null && cover !== undefined && cover.trackId === track.id
    const accent = readable(hasCover && cover.accent !== undefined ? cover.accent : NEUTRAL)
    const layout = layoutFor(width)

    const state: PaneView['state'] =
      players.length > 0 && installed.length === 0 ? 'none-installed' : player === undefined || !player.isRunning ? 'closed' : track === null ? 'stopped' : 'track'

    const position = track === null ? 0 : positionNow(track, polledAt[track.app] ?? now, now)
    let lyrics: PaneView['lyrics'] = { status: 'off' }
    if (track !== null && state === 'track' && lyricsOn) {
      const entry = lyricsCache.get(track.id)
      lyrics =
        entry === undefined
          ? { status: 'loading' }
          : entry.status === 'none'
            ? { status: 'none' }
            : { status: 'found', ...lyricWindow(entry.lines, position) }
    }
    isTicking = state === 'track' && track?.state === 'playing'
    isPaneOpen = true

    // The sleeve: the cover, with the record peeking out from behind it.
    // Image and Raster are the terminal's alone; the engine draws an Image
    // only where it detects kitty graphics, so half-block cells are the default.
    record = null
    let sleeve = null
    if (track !== null && state === 'track' && e.surface === 'terminal' && layout.art !== 0) {
      const { Box, Image, Raster } = $.ui.resolve(e)
      const size = layout.art
      const artRows = size / 2
      const cells = hasCover ? cover.cells[`${size}`] : undefined
      const art =
        hasCover && (artMode === 'image' || cells === undefined) ? (
          <Image
            key="cover"
            source={{ file: cover.file, format: 'png', generation: cover.generation }}
            columns={size}
            rows={artRows}
            alt={`${track.album} cover (try /music art blocks)`}
          />
        ) : cells !== undefined ? (
          <Raster key="cover" columns={size} rows={artRows} cells={cells} />
        ) : null
      if (art !== null) {
        record = layout.peek > 0 ? { columns: layout.peek, rows: artRows, label: accent, isPlaying: track.state === 'playing' } : null
        sleeve = (
          <Box flexDirection="row">
            {art}
            {record !== null && (
              <Raster key="record" columns={record.columns} rows={record.rows} cells={recordCells(record.columns, record.rows, theta, accent)} />
            )}
          </Box>
        )
      }
    }

    const view: PaneView = {
      width,
      tabs: installed.map(({ app }) => ({
        app,
        label: LABELS[app],
        isShown: app === shown,
        isPlaying: players.find(p => p.app === app)?.track?.state === 'playing',
      })),
      shown,
      shownLabel: LABELS[shown],
      canFavorite: shown === 'Music' && track?.favorited !== undefined,
      state,
      track,
      position,
      lyrics,
      accent,
      layout,
      sleeve,
      handlers: {
        toggleLyrics: () => void setLyricsOn($, !lyricsOn),
        pickTab: app => void update($, sourceAtom, () => app),
        open: () => void openApp($, shown),
        press,
        toggleShuffle: () => playModeBusy.shuffle || void notify($, setPlayMode($, 'shuffle', undefined, shown), 'Shuffle'),
        cycleRepeat: () => playModeBusy.repeat || void notify($, setPlayMode($, 'repeat', undefined, shown), 'Repeat'),
        toggleFavorite: () =>
          void (async () => {
            try {
              const result = await setFavorite($, !(track?.favorited ?? false))
              if (!result.startsWith('Added') && !result.startsWith('Removed')) $.ui.toast(result)
            } catch (error) {
              $.ui.toast(`Favorite failed: ${String(error)}`)
            }
          })(),
      },
    }
    return paneTree($.ui.resolve(e), view)
  })
plugins/now-playing/hooks/pane.tsx lines 39–169 · Pane
export function paneTree(ui: Pick<Elements['desktop'], 'Box' | 'Text' | 'Button'>, view: PaneView) {
  const { Box, Text, Button } = ui
  const row = (key: string, ...children: RenderChildren[]) => (
    <Box key={key} flexDirection="row" justifyContent="center" width={view.width}>
      {children}
    </Box>
  )
  const tabs =
    view.tabs.length > 1
      ? row(
          'row-tabs',
          <Box flexDirection="row" columnGap={3}>
            {view.tabs.map((t, i) => (
              <Button
                key={`tab-${t.app}`}
                label={t.isPlaying ? `${t.label} ♪` : t.label}
                hotkey={String(i + 1)}
                plain
                dimColor={!t.isShown}
                onPress={() => view.handlers.pickTab(t.app)}
              />
            ))}
          </Box>,
        )
      : null
  const label = view.shownLabel

  if (view.state === 'none-installed') {
    return (
      <Box flexDirection="column">
        {row('row-message', <Text dimColor>Install Apple Music or Spotify to use this player.</Text>)}
      </Box>
    )
  }
  if (view.state === 'closed') {
    return (
      <Box flexDirection="column" rowGap={1}>
        {tabs}
        {row('row-message', <Text dimColor>{label} is closed.</Text>)}
        {row('row-action', <Button key="open" label={`Open ${label}`} hotkey="o" plain onPress={view.handlers.open} />)}
      </Box>
    )
  }
  if (view.state === 'stopped' || view.track === null) {
    return (
      <Box flexDirection="column" rowGap={1}>
        {tabs}
        {row('row-message', <Text dimColor>{label} is stopped.</Text>)}
        {row(
          'row-action',
          <Button
            key="toggle"
            label="▶ Play"
            hotkey="k"
            plain
            onPress={view.handlers.press('play')}
          />,
        )}
      </Box>
    )
  }

  const track = view.track
  const isPlaying = track.state === 'playing'
  const isShuffle = track.shuffle === true
  const isRepeat = track.repeat === 'all' || track.repeat === 'one'
  const played = track.duration > 0 ? Math.min(view.width - 1, Math.floor((view.position / track.duration) * view.width)) : 0
  return (
    <Box flexDirection="column">
      {tabs}
      <Box height={1} />
      {view.sleeve !== null && row('row-sleeve', view.sleeve as RenderChildren)}
      <Box height={1} />
      {wrapLines(track.name, view.width).map((line, i) => row(`row-title-${i}`, <Text bold>{line}</Text>))}
      {wrapLines(track.artist, view.width).map((line, i) => row(`row-artist-${i}`, <Text>{line}</Text>))}
      {wrapLines(track.album, view.width).map((line, i) => row(`row-album-${i}`, <Text dimColor>{line}</Text>))}
      {view.lyrics.status !== 'off' && <Box height={1} />}
      {view.lyrics.status === 'found' && row('row-lyric-prev', <Text dimColor wrap="truncate-end">{view.lyrics.prev || ' '}</Text>)}
      {view.lyrics.status === 'found' && row('row-lyric-current', <Text bold color={hex(view.accent)} wrap="truncate-end">{view.lyrics.current || ' '}</Text>)}
      {view.lyrics.status === 'found' && row('row-lyric-next', <Text dimColor wrap="truncate-end">{view.lyrics.next || ' '}</Text>)}
      {(view.lyrics.status === 'none' || view.lyrics.status === 'loading') &&
        row('row-lyric-none', <Text dimColor>{view.lyrics.status === 'none' ? 'No synced lyrics' : 'Looking for lyrics…'}</Text>)}
      <Box height={1} />
      <Box key="row-bar" flexDirection="row" width={view.width}>
        <Text color={hex(view.accent)}>{'━'.repeat(played)}</Text>
        <Text color={hex(view.accent)} bold>╸</Text>
        <Text dimColor>{'─'.repeat(Math.max(0, view.width - played - 1))}</Text>
      </Box>
      <Box key="row-times" flexDirection="row" justifyContent="space-between" width={view.width}>
        <Text dimColor>{formatTime(view.position)}</Text>
        <Text dimColor>{formatTime(track.duration)}</Text>
      </Box>
      <Box height={1} />
      {row(
        'row-transport',
        <Box flexDirection="row" columnGap={4}>
          <Button key="prev" label="⏮" hotkey="b" plain onPress={view.handlers.press('previous')} />
          <Button key="toggle" label={isPlaying ? '⏸' : '▶'} hotkey="k" plain onPress={view.handlers.press('toggle')} />
          <Button key="next" label="⏭" hotkey="n" plain onPress={view.handlers.press('next')} />
          {view.canFavorite && (
            <Button key="fav" label={track.favorited === true ? '♥' : '♡'} hotkey="f" plain onPress={view.handlers.toggleFavorite} />
          )}
        </Box>,
      )}
      {row(
        'row-playmode',
        <Box flexDirection="row" columnGap={3}>
          <Box flexDirection="row" columnGap={1}>
            {isShuffle ? <Text color={hex(view.accent)}>●</Text> : <Text> </Text>}
            <Button key="shuffle" label={`⇄ Shuffle ${isShuffle ? 'on' : 'off'}`} hotkey="s" plain dimColor={!isShuffle} onPress={view.handlers.toggleShuffle} />
            {/* "on" is one column narrower than "off"; keep the row's width fixed */}
            {isShuffle && <Text> </Text>}
          </Box>
          <Box flexDirection="row" columnGap={1}>
            {isRepeat ? <Text color={hex(view.accent)}>●</Text> : <Text> </Text>}
            <Button key="repeat" label={`↻ Repeat ${track.repeat ?? 'off'}`} hotkey="r" plain dimColor={!isRepeat} onPress={view.handlers.cycleRepeat} />
          </Box>
        </Box>,
      )}
      {row(
        'row-volume',
        <Box flexDirection="row" columnGap={1}>
          <Button key="vol-down" label="−" hotkey="d" plain dimColor onPress={view.handlers.press('volume', track.volume - 10)} />
          <Text dimColor>vol {track.volume}</Text>
          <Button key="vol-up" label="+" hotkey="u" plain dimColor onPress={view.handlers.press('volume', track.volume + 10)} />
          <Button key="lyrics" label={view.lyrics.status === 'off' ? 'lyrics off' : 'lyrics on'} hotkey="l" plain dimColor onPress={view.handlers.toggleLyrics} />
        </Box>,
      )}
    </Box>
  )
}
Licence text (MIT)
MIT License

Copyright (c) 2026 Jimmy Hsiao

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

runs programsenv varstool callsremembers

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 89d6e13a9fa8 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.plugins/now-playing/hooks/register.tsx
ParsesEvery file parses as TypeScript or JavaScript.6 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.listed in its repository's .claude-plugin/marketplace.json: installs from there
Programs on WindowsWhether every program it starts through $.process exists on Windows (tail, date, open, osascript, /usr/… do not).plugins/now-playing/hooks/register.tsx:164 mkdir (not on Windows); plugins/now-playing/hooks/register.tsx:316 open (not on Windows)
NetworkWhether every fetch names its https host in the code.no network
ProgramsWhether every program it starts is named in the code and is not a shell, an interpreter or a network tool.plugins/now-playing/hooks/register.tsx:76 osascript (a shell or interpreter); plugins/now-playing/hooks/register.tsx:80 curl (reaches the network)
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 is its marketplace. Add that marketplace (in the terminal with these commands, or in the desktop app's plugin settings) and install the mod from it:

/plugin marketplace add Fatmylin/now-playing
/plugin install now-playing@now-playing

This installs the marketplace's latest commit, which may not be the one read here (89d6e13a9fa8). Compare them before you install.

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 "fatmylin-now-playing" with its code and make me a pane like it

Search them from Claude: the MCP connector

Similar designs