modscode EN

modscode / 図鑑 / claude-link

claude-link

See and use Claude Code chats from your other machines

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

何をするか

  • 欄・ステータス行・トーストを描く
  • /link を足す
  • mcp__claude-link__chats・mcp__claude-link__read_chat・mcp__claude-link__search の呼び出しを見張る(止めることがある)
  • session.startにフックする
  • ネットワークに出る

良いところ

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

作り始めるためのコード

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

雛形(register.tsx)

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

// Drawn like claude-link by Lukas Kundelis (pane, status, toast), as modscode read it from the mod's code:
// https://modscode.com/gallery/psykologg-claude-link/
// 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: "Link" })
  on('ui.render', { component: 'Pane', requestId: 'my-pane' }, async ($, e) => {
    const { Box, Button, Text, Markdown } = $.ui.resolve(e)
    const title = '…'
    const machine = '…'
    const project = '…'
    const ago = '…'
    const totalTurns = '…'
    const liveLabel = '…'
    const error = '…'
    const clock = '…'
    const text = '…'
    const toolsLine = '…'
    const omittedTurns = '…'
    const toolsLine2 = '…'
    const toolsLine3 = '…'
    const toolsLine4 = '…'
    return (
      <Box flexDirection="column" gap={1} paddingX={1}>
        <Box gap={2} alignItems="center" flexWrap="wrap">
          <Button plain label="Back" />
          <Button label="Adding..." variant="primary" />
          <Button plain dimColor label="Copying..." />
        </Box>
        <Box flexDirection="column">
          <Text bold wrap="wrap">
            {title}
          </Text>
          <Text wrap="wrap">
            <Text>
              {machine}
            </Text>
            <Text dimColor>
              {`   ${project}   ${ago}   ${totalTurns} turns   ${liveLabel}`}
            </Text>
          </Text>
        </Box>
        <Text color="error" wrap="wrap">
          {error}
        </Text>
        <Box flexDirection="column">
          <Text bold color="claude">
            You
            <Text dimColor>
              {`   ${clock}`}
            </Text>
          </Text>
          <Markdown text={`${text}`} />
          <Text dimColor wrap="truncate-end">
            {toolsLine}
          </Text>
        </Box>
        <Box gap={1} alignItems="center">
          <Text dimColor>
            {`${omittedTurns} turns hidden`}
          </Text>
          <Button plain dimColor label="Loading..." />
        </Box>
        <Box flexDirection="column">
          <Text bold color="claude">
            You
            <Text dimColor>
              {`   ${clock}`}
            </Text>
          </Text>
          <Markdown text={`${text}`} />
          <Text dimColor wrap="truncate-end">
            {toolsLine2}
          </Text>
        </Box>
        <Box flexDirection="column">
          <Text bold color="claude">
            You
            <Text dimColor>
              {`   ${clock}`}
            </Text>
          </Text>
          <Markdown text={`${text}`} />
          <Text dimColor wrap="truncate-end">
            {toolsLine3}
          </Text>
        </Box>
        <Box flexDirection="column">
          <Text bold color="claude">
            You
            <Text dimColor>
              {`   ${clock}`}
            </Text>
          </Text>
          <Markdown text={`${text}`} />
          <Text dimColor wrap="truncate-end">
            {toolsLine4}
          </Text>
        </Box>
      </Box>
    )
  })

  on('session.start', async ($, e, next) => {
    const machines = '…'
    const here = '…'
    const title = '…'
    const machine = '…'
    await $.ui.status(`Link: ${machines}${here}`)
    await $.ui.toast(`Added "${title}" from ${machine}`)
    await $.ui.toast(`Copied the chat as Markdown`)
    return next(e)
  })
}

Mod 自身のコード

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

mod/hooks/register.tsx 564〜723 行 · ペイン
  on('ui.render', { component: 'Pane', requestId: PANE }, async ($, e) => {
    const table = $.ui.resolve(e)
    const { Box, Text, Button, Markdown } = table
    const Input = 'Input' in table ? table.Input : null
    const now = await $.clock.now()
    const busy = await read($, busyState)
    const error = await read($, errorState)
    const detail = await read($, detailState)

    const turnView = (turn: LinkTurn, index: number) => {
      if (turn.role === 'note') {
        return (
          <Text key={`turn-${index}`} dimColor italic>
            {turn.text}
          </Text>
        )
      }
      return (
        <Box key={`turn-${index}`} flexDirection="column">
          <Text bold color={turn.role === 'user' ? 'claude' : undefined}>
            {turn.role === 'user' ? 'You' : 'Claude'}
            <Text dimColor>{turn.at ? `   ${clock(turn.at)}` : ''}</Text>
          </Text>
          {turn.text ? <Markdown text={turn.text} /> : null}
          {turn.tools.length > 0 ? (
            <Text dimColor wrap="truncate-end">
              {toolsLine(turn)}
            </Text>
          ) : null}
        </Box>
      )
    }

    if (detail) {
      const [firstTurn, ...laterTurns] = detail.turns
      return (
        <Box flexDirection="column" gap={1} paddingX={1}>
          <Box gap={2} alignItems="center" flexWrap="wrap">
            <Button key="back" plain label="Back" onPress={() => closeChat($)} />
            <Button key="add" label={busy === Busy.Adding ? 'Adding...' : 'Add to this chat'} variant="primary" onPress={() => addToChat($, detail.chat)} />
            <Button key="copy" plain dimColor label={busy === Busy.Copying ? 'Copying...' : 'Copy'} onPress={press => copyChat($, detail.chat, press.surface)} />
          </Box>
          <Box flexDirection="column">
            <Text bold wrap="wrap">
              {detail.chat.title}
            </Text>
            <Text wrap="wrap">
              <Text color={machineColor(detail.chat.machine)}>{detail.chat.machine}</Text>
              <Text dimColor>{`   ${detail.chat.project}   ${ago(detail.chat.lastAt, now)}   ${detail.totalTurns} turns   ${liveLabel(detail.chat.live)}`}</Text>
            </Text>
          </Box>
          {error ? <Text color="error" wrap="wrap">{error}</Text> : null}
          {firstTurn ? turnView(firstTurn, 0) : <Text dimColor>This chat has no messages yet.</Text>}
          {detail.omittedTurns > 0 ? (
            <Box gap={1} alignItems="center">
              <Text dimColor>{`${detail.omittedTurns} turns hidden`}</Text>
              <Button key="show-all" plain dimColor label={busy === Busy.Opening ? 'Loading...' : 'Show all'} onPress={() => openChat($, detail.chat, 0)} />
            </Box>
          ) : null}
          {laterTurns.map((turn, index) => turnView(turn, index + 1))}
        </Box>
      )
    }

    const status = await read($, statusState)
    const chats = await read($, chatsState)
    const counts = await read($, countsState)
    const scope = await read($, scopeState)
    const filter = await read($, queryState)
    const project = await read($, projectState)
    const expanded = await read($, expandedState)
    const lastOpened = await read($, lastOpenedState)
    const Svg = 'Svg' in table ? table.Svg : null
    const hasPointer = e.surface !== 'terminal'
    const peers = status?.peers ?? []
    const columns = e.props.bodyColumns || 80
    const needle = filter.trim().toLowerCase()
    const visibleChats = needle
      ? chats.filter(chat => `${chat.title} ${chat.project} ${chat.machine}`.toLowerCase().includes(needle))
      : chats
    // With one other machine every row would name the same one, so the name
    // only shows when chats come from several machines.
    const showMachine = new Set(chats.map(chat => chat.origin)).size > 1
    const emptyText = needle
      ? `No chats match "${filter.trim()}".`
      : scope === 'here'
        ? 'No chats about this project on your other machines yet.'
        : 'No chats from other machines yet.'

    // A row like the sidebar's: a circle and the title across the full width,
    // tinted on hover, with prompt count and age revealed only while hovered.
    const chatRow = (chat: LinkChat) => {
      const dot = dotFor(chat.live)
      const live = liveLabel(chat.live)
      const meta = `${showMachine ? `${chat.machine}   ` : ''}${live ? `${live}   ` : ''}${promptLabel(chat.prompts)}   ${ago(chat.lastAt, now)}`
      const isSelected = lastOpened === `${chat.origin}:${chat.ref}`
      const tint = hasPointer ? { hover: { backgroundColor: ROW_HOVER }, ...(isSelected ? { backgroundColor: ROW_SELECTED } : {}) } : {}
      return (
        <Box key={`row-${chat.origin}-${chat.ref}`} gap={1} paddingX={1} alignItems="center" {...tint}>
          {Svg ? (
            <Svg source={dotSvg(dot)} alt={DOT_ALT[dot]} width={9} height={9} />
          ) : (
            <Text color={dot === 'working' ? 'success' : undefined} dimColor={dot !== 'working'}>
              {dot === 'closed' ? TERMINAL_DOT.hollow : TERMINAL_DOT.filled}
            </Text>
          )}
          <Box flexGrow={1} flexShrink={1} minWidth={0} overflow="hidden">
            <Button key={`open-${chat.origin}-${chat.ref}`} plain label={fit(chat.title, columns - 6)} onPress={() => openChat($, chat)} />
          </Box>
          {hasPointer ? (
            <Box flexShrink={0} display="none" hover={{ display: 'flex' }}>
              <Text dimColor>{meta}</Text>
            </Box>
          ) : null}
        </Box>
      )
    }

    const groupView = (group: ChatGroup) => {
      const isExpanded = expanded.includes(group.key) || needle !== ''
      const shown = isExpanded ? group.chats : group.chats.slice(0, GROUP_PREVIEW)
      const hidden = group.chats.length - shown.length
      const canCollapse = expanded.includes(group.key) && needle === '' && group.chats.length > GROUP_PREVIEW
      return (
        <Box key={`group-${group.key}`} flexDirection="column">
          <Box paddingX={1}>
            <Text dimColor wrap="truncate-end">
              {group.hint ? `${group.label}   ${group.hint}` : group.label}
            </Text>
          </Box>
          {shown.map(chatRow)}
          {hidden > 0 || canCollapse ? (
            <Box paddingLeft={3}>
              <Button key={`toggle-${group.key}`} plain dimColor label={hidden > 0 ? `Show ${hidden} more` : 'Show less'} onPress={() => toggleGroup($, group.key)} />
            </Box>
          ) : null}
        </Box>
      )
    }

    return (
      <Box flexDirection="column" gap={1}>
        <Box justifyContent="space-between" alignItems="center" gap={1} paddingX={1}>
          <Box gap={2} flexWrap="wrap" flexShrink={1}>
            {peers.length === 0 ? <Text dimColor>No linked machines yet</Text> : null}
            {peers.map(peer => (
              <Text key={`peer-${peer.machineId || peer.name}`}>
                <Text color={peer.isOnline ? 'success' : undefined} dimColor={!peer.isOnline}>
                  {peer.name}
                </Text>
                <Text dimColor>{peer.isOnline ? `  synced ${ago(peer.lastSyncAt, now) || 'just now'}` : '  offline'}</Text>
              </Text>
            ))}
            {status?.indexing ? <Text dimColor>{status.indexing}</Text> : null}
          </Box>
          <Button key="sync" plain dimColor label={busy === Busy.Syncing ? 'Syncing...' : 'Sync'} onPress={() => syncNow($)} />
        </Box>
        <Box gap={2} alignItems="center" paddingX={1}>
          <Button key="scope-here" plain dimColor={scope !== 'here'} label={tabLabel(fit(project || 'This project', 28), counts.here)} onPress={() => setScope($, 'here')} />
          <Button key="scope-all" plain dimColor={scope !== 'all'} label={tabLabel('All', counts.all)} onPress={() => setScope($, 'all')} />
ライセンスの全文(MIT)
MIT License

Copyright (c) 2026 Lukas Kundelis

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

載せる条件: 確かめやすいコード
入口を読んだhooks/hooks.json が名指すモジュールをすべて読んだ。mod/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 のホスト)がコードに書いてあるか。mod/hooks/register.tsx:94 fetch(`${link.baseUrl}${path}`)
プログラム起動するプログラムの名前がコードに書いてあり、シェル・インタプリタ・通信用の道具でないか。プログラムを起動しない
読んで送るファイルや環境変数を読み、かつ通信するか。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 .)、触るものを見て、読んだコミットを入れてください。

リポジトリの .claude-plugin/marketplace.json にこの Mod が載っていないため、入れる手順は出せません。コードとして読むか、作者の README に従ってください。

Claude に聞く

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

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

Claude から探す: MCP コネクタ

似たデザイン