playpen
The sessions you are working in right now as small cards above the prompt: a status lamp, a short label, what just happened, and one press to answer or jump there.
何をするか
- プロンプトの上の帯・トーストを描く
- /board を足す
- AskUserQuestion の呼び出しを見張る(止めることがある)
- classic.Notification・classic.PermissionRequest・classic.PostModelSwitch・prompt.context ほか 8 個にフックする
- ターンをまたいで自分の状態を持つ
良いところ
- ネットワークに出ない
- TypeScript で書かれている
- デスクトップ専用の分岐がある
- エラーを扱う
作り始めるためのコード
2 種類あります。上のデザインから modscode が書いた雛形と、その Mod 自身のコードのうち描いている部分です。
雛形(register.tsx)
import type { Register } from 'claude-code'
// Drawn like playpen by Joel Rönnqvist (band, toast), as modscode read it from the mod's code:
// https://modscode.com/gallery/kytioisacat-playpen/
// 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 label = '…'
const title = '…'
const text = '…'
const n = '…'
const label2 = '…'
const label3 = '…'
const suggestion = '…'
const title2 = '…'
const text2 = '…'
const label4 = '…'
const label5 = '…'
const label6 = '…'
const suggestion2 = '…'
const title3 = '…'
const text3 = '…'
const label7 = '…'
const label8 = '…'
const label9 = '…'
const suggestion3 = '…'
const title4 = '…'
const text4 = '…'
const label10 = '…'
const label11 = '…'
const label12 = '…'
const suggestion4 = '…'
const title5 = '…'
const text5 = '…'
const label13 = '…'
const label14 = '…'
const label15 = '…'
const suggestion5 = '…'
const title6 = '…'
const text6 = '…'
const label16 = '…'
const label17 = '…'
const label18 = '…'
const suggestion6 = '…'
return (
<Box flexDirection="column">
<Box flexDirection="row" flexWrap="wrap" columnGap={1}>
<Box flexDirection="column" paddingX={1} borderStyle="round">
<Box flexDirection="row" justifyContent="space-between">
<Box flexDirection="row" gap={1} overflow="hidden">
<Text>
●
</Text>
<Button plain label={`${label}`} />
</Box>
<Box flexDirection="row" gap={1}>
<Button variant="primary" label="hand off" />
<Button plain label="►" />
<Button plain dimColor label="×" />
</Box>
</Box>
<Text color="red" wrap="truncate-end">
asks you
</Text>
<Box flexDirection="column">
<Text bold wrap="wrap">
{title}
</Text>
<Text color="red" wrap="wrap">
{text}
</Text>
<Box flexDirection="row" gap={1}>
<Button plain hotkey={`${n}`} label={`[${n}1]`} />
<Box>
<Text wrap="wrap">
{label}
</Text>
</Box>
</Box>
<Box flexDirection="row" gap={1}>
<Button plain hotkey={`${n}`} label={`[${n}1]`} />
<Box>
<Text wrap="wrap">
{label2}
</Text>
</Box>
</Box>
<Box flexDirection="row" gap={1}>
<Button plain hotkey={`${n}`} label={`[${n}1]`} />
<Box>
<Text wrap="wrap">
{label3}
</Text>
</Box>
</Box>
<Box flexDirection="row" gap={1}>
<Button variant="primary" label="send" />
<Box>
<Text wrap="wrap">
{suggestion}
</Text>
</Box>
</Box>
</Box>
<Box position="absolute" flexDirection="column" paddingX={1} borderStyle="round" borderColor="red" display="none">
<Text bold wrap="wrap">
{title2}
</Text>
<Text color="red" wrap="wrap">
{text2}
</Text>
<Box flexDirection="row" gap={1}>
<Button plain hotkey={`${n}`} label={`[${n}1]`} />
<Box>
<Text wrap="wrap">
{label4}
</Text>
</Box>
</Box>
<Box flexDirection="row" gap={1}>
<Button plain hotkey={`${n}`} label={`[${n}1]`} />
<Box>
<Text wrap="wrap">
{label5}
</Text>
</Box>
</Box>
<Box flexDirection="row" gap={1}>
<Button plain hotkey={`${n}`} label={`[${n}1]`} />
<Box>
<Text wrap="wrap">
{label6}
</Text>
</Box>
</Box>
<Box flexDirection="row" gap={1}>
<Button variant="primary" label="send" />
<Box>
<Text wrap="wrap">
{suggestion2}
</Text>
</Box>
</Box>
</Box>
</Box>
<Box flexDirection="column" paddingX={1} borderStyle="round">
<Box flexDirection="row" justifyContent="space-between">
<Box flexDirection="row" gap={1} overflow="hidden">
<Text>
●
</Text>
<Button plain label={`${label}`} />
</Box>
<Box flexDirection="row" gap={1}>
<Button variant="primary" label="hand off" />
<Button plain label="►" />
<Button plain dimColor label="×" />
</Box>
</Box>
<Text color="red" wrap="truncate-end">
asks you
</Text>
<Box flexDirection="column">
<Text bold wrap="wrap">
{title3}
</Text>
<Text color="red" wrap="wrap">
{text3}
</Text>
<Box flexDirection="row" gap={1}>
<Button plain hotkey={`${n}`} label={`[${n}1]`} />
<Box>
<Text wrap="wrap">
{label7}
</Text>
</Box>
</Box>
<Box flexDirection="row" gap={1}>
<Button plain hotkey={`${n}`} label={`[${n}1]`} />
<Box>
<Text wrap="wrap">
{label8}
</Text>
</Box>
</Box>
<Box flexDirection="row" gap={1}>
<Button plain hotkey={`${n}`} label={`[${n}1]`} />
<Box>
<Text wrap="wrap">
{label9}
</Text>
</Box>
</Box>
<Box flexDirection="row" gap={1}>
<Button variant="primary" label="send" />
<Box>
<Text wrap="wrap">
{suggestion3}
</Text>
</Box>
</Box>
</Box>
<Box position="absolute" flexDirection="column" paddingX={1} borderStyle="round" borderColor="red" display="none">
<Text bold wrap="wrap">
{title4}
</Text>
<Text color="red" wrap="wrap">
{text4}
</Text>
<Box flexDirection="row" gap={1}>
<Button plain hotkey={`${n}`} label={`[${n}1]`} />
<Box>
<Text wrap="wrap">
{label10}
</Text>
</Box>
</Box>
<Box flexDirection="row" gap={1}>
<Button plain hotkey={`${n}`} label={`[${n}1]`} />
<Box>
<Text wrap="wrap">
{label11}
</Text>
</Box>
</Box>
<Box flexDirection="row" gap={1}>
<Button plain hotkey={`${n}`} label={`[${n}1]`} />
<Box>
<Text wrap="wrap">
{label12}
</Text>
</Box>
</Box>
<Box flexDirection="row" gap={1}>
<Button variant="primary" label="send" />
<Box>
<Text wrap="wrap">
{suggestion4}
</Text>
</Box>
</Box>
</Box>
</Box>
<Box flexDirection="column" paddingX={1} borderStyle="round">
<Box flexDirection="row" justifyContent="space-between">
<Box flexDirection="row" gap={1} overflow="hidden">
<Text>
●
</Text>
<Button plain label={`${label}`} />
</Box>
<Box flexDirection="row" gap={1}>
<Button variant="primary" label="hand off" />
<Button plain label="►" />
<Button plain dimColor label="×" />
</Box>
</Box>
<Text color="red" wrap="truncate-end">
asks you
</Text>
<Box flexDirection="column">
<Text bold wrap="wrap">
{title5}
</Text>
<Text color="red" wrap="wrap">
{text5}
</Text>
<Box flexDirection="row" gap={1}>
<Button plain hotkey={`${n}`} label={`[${n}1]`} />
<Box>
<Text wrap="wrap">
{label13}
</Text>
</Box>
</Box>
<Box flexDirection="row" gap={1}>
<Button plain hotkey={`${n}`} label={`[${n}1]`} />
<Box>
<Text wrap="wrap">
{label14}
</Text>
</Box>
</Box>
<Box flexDirection="row" gap={1}>
<Button plain hotkey={`${n}`} label={`[${n}1]`} />
<Box>
<Text wrap="wrap">
{label15}
</Text>
</Box>
</Box>
<Box flexDirection="row" gap={1}>
<Button variant="primary" label="send" />
<Box>
<Text wrap="wrap">
{suggestion5}
</Text>
</Box>
</Box>
</Box>
<Box position="absolute" flexDirection="column" paddingX={1} borderStyle="round" borderColor="red" display="none">
<Text bold wrap="wrap">
{title6}
</Text>
<Text color="red" wrap="wrap">
{text6}
</Text>
<Box flexDirection="row" gap={1}>
<Button plain hotkey={`${n}`} label={`[${n}1]`} />
<Box>
<Text wrap="wrap">
{label16}
</Text>
</Box>
</Box>
<Box flexDirection="row" gap={1}>
<Button plain hotkey={`${n}`} label={`[${n}1]`} />
<Box>
<Text wrap="wrap">
{label17}
</Text>
</Box>
</Box>
<Box flexDirection="row" gap={1}>
<Button plain hotkey={`${n}`} label={`[${n}1]`} />
<Box>
<Text wrap="wrap">
{label18}
</Text>
</Box>
</Box>
<Box flexDirection="row" gap={1}>
<Button variant="primary" label="send" />
<Box>
<Text wrap="wrap">
{suggestion6}
</Text>
</Box>
</Box>
</Box>
</Box>
</Box>
<Box height={0} />
{await next(e)}
</Box>
)
})
on('session.start', async ($, e, next) => {
const label = '…'
const text = '…'
await $.ui.toast(`Could not open the session; its link is on the clipboard`)
await $.ui.toast(`Sent to ${label}: ${text}`)
return next(e)
})
}
Mod 自身のコード
Mod のライセンス(MIT)に従って載せています。全文は下にあります。写すときは著作権表示を残してください。
hooks/register.tsx 1213〜1372 行 · バンド
on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
if (e.props.hasSurvey || isCollapsed || deck.length === 0) return next(e)
const { Box, Text, Button } = $.ui.resolve(e)
const columns = e.props.bodyColumns
// three cards across; each is two rows inside a thin frame: the lamp,
// label, hand-off, reply and ×, then the gist
const cardWidth = Math.max(MIN_CARD, Math.min(MAX_CARD, Math.floor((columns - (PER_ROW - 1)) / PER_ROW)))
const perRow = Math.max(1, Math.floor((columns + 1) / (cardWidth + 1)))
const inner = cardWidth - 4 // less the frame and its padding
const labelMax = Math.max(8, inner - 8) // room for ✦ ► ×
// The popover: twice a card wide, drawn over the neighbours and never in
// the flow, so no card moves when it shows. The band clips at its own
// edge, so rows are reserved under the cards for the tallest popover
// that may show, and none when no card has one.
const wide = Math.min(columns, cardWidth * 2 + 1)
const wideInner = wide - 4
const rowsOf = (text: string, width: number) => Math.max(1, Math.ceil(text.length / Math.max(1, width)))
const popoverRows = (card: Card) => {
let rows = 2 // the frame
if (trim(card.title, LABEL_MAX) !== card.label) rows += rowsOf(card.title, wideInner)
if (card.permission) {
rows += rowsOf(card.permission, wideInner) + 2
} else if (card.question) {
rows += rowsOf(card.question.text, wideInner)
for (const option of card.question.options) rows += rowsOf(option, wideInner - 4)
} else {
rows += rowsOf(card.snippet || stateWord(card.state), wideInner)
if (card.suggestion) rows += rowsOf(card.suggestion, wideInner - 9)
}
return rows
}
// A red card with a question shows the question and its options in the
// card itself, so the band already has that height, and its popover under
// the pointer is the same content wide. Any card shows the popover while
// open with ►; rows are reserved under the cards only then.
// The desktop app draws the popover over the transcript above the band
// and clips nothing, so there the cards stay two rows and no space is
// kept. The terminal clips at the band's edge: there a red card shows its
// question in the card, and rows are reserved while a card is open.
const isTerminal = e.surface === 'terminal'
const asks = (card: Card) => card.state === 'waiting' && (card.question !== null || !!card.permission)
// The popover is revealed by the pointer alone, which is the one way the
// desktop app draws it whole. A red question has one; ► gives any card
// one for a while, and since the pointer is on the card at the press, it
// shows at once. In a terminal, which clips the popover, the same content
// expands the card in the flow instead.
const hasPopover = (card: Card) => asks(card) || openId === card.id
const expandsInCard = (card: Card) => isTerminal && (asks(card) || openId === card.id)
const cardRowCount = Math.ceil(deck.length / perRow)
// rows kept free under the cards for a terminal's hover popover, which
// hangs below the card and would otherwise be cut at the band's edge
let reserve = 0
if (isTerminal) {
deck.forEach((card, i) => {
if (!hasPopover(card)) return
const rowsBelow = cardRowCount - 1 - Math.floor(i / perRow)
reserve = Math.max(reserve, popoverRows(card) - 1 - rowsBelow * 4)
})
reserve = Math.max(0, Math.min(reserve, e.props.maxRows - cardRowCount * 4))
}
return (
<Box flexDirection="column">
<Box flexDirection="row" flexWrap="wrap" columnGap={1}>
{deck.map((card, i) => {
const isMe = me !== null && card.id === me.id
const isOpen = openId === card.id
const options = card.question?.options ?? []
// a popover that would run past the band's right edge hangs from
// the card's right edge instead
const column = (i % perRow) * (cardWidth + 1)
const anchorRight = column + wide > columns
return (
// a thin frame around the whole card: dim, full strength on this
// session, and the surface brightens it under the pointer by itself
<Box
key={`card:${card.id}`}
flexDirection="column"
width={cardWidth}
paddingX={1}
borderStyle="round"
borderDimColor={!isMe}
hover={{ borderDimColor: false }}
>
<Box flexDirection="row" justifyContent="space-between">
<Box flexDirection="row" gap={1} overflow="hidden">
<Text color={lampColor(card.state)}>●</Text>
<Button
key={`jump:${card.id}`}
plain
label={trim(card.label, labelMax)}
onPress={() => void (isMe ? Promise.resolve() : jump($, card))}
/>
</Box>
<Box flexDirection="row" gap={1}>
{armedId === card.id ? (
<Button
key={`handoff:${card.id}`}
variant="primary"
label="hand off"
onPress={() => pressHandoff($, card, isMe)}
/>
) : (
<Button
key={`handoff:${card.id}`}
plain
dimColor
label="✦"
onPress={() => pressHandoff($, card, isMe)}
/>
)}
<Button
key={`reply:${card.id}`}
plain
dimColor={!isOpen}
label="►"
onPress={() => pressAnswer($, card)}
/>
<Button key={`hide:${card.id}`} plain dimColor label="×" onPress={() => void hide($, card)} />
</Box>
</Box>
{/* Row two is the short form: the gist, red while the session
needs you. A card that asks a question goes on below it with
the question and one row per option, in the card's own
width; the popover shows the same thing wide. */}
<Text
color={card.state === 'waiting' ? 'red' : undefined}
dimColor={card.state !== 'waiting'}
wrap="truncate-end"
>
{card.gist ||
(card.state === 'waiting' ? (card.question ? 'asks you' : card.permission ? 'asks permission' : 'needs you') : stateWord(card.state))}
</Text>
{/* A terminal only: the card expanded in the flow, taller and
never wider. The full title where it adds to the label, then
the question with one row per option, or the latest reply in
full with the suggestion and a send button. */}
{expandsInCard(card) && (
<Box flexDirection="column">
{isOpen && trim(card.title, LABEL_MAX) !== card.label && (
<Text bold wrap="wrap">
{card.title}
</Text>
)}
{card.question && !card.permission && (
<Text color="red" wrap="wrap">
{card.question.text}
</Text>
)}
{card.permission ? (
<Box flexDirection="column">
<Text color="red" wrap="wrap">
{`Asks to run ${card.permission}`}
</Text>
<Text dimColor wrap="wrap">
{isMe
? 'Approve or deny it in the dialog above.'
: 'A permission is answered in its own session; a mod cannot give it.'}
</Text>ライセンスの全文(MIT)
MIT License Copyright (c) 2026 Joel Rönnqvist 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 に読んだコミット d4309b75feb6 のソースから。最初のまとまりが載せる条件で、残りは自分で判断するための材料です。後のコミットは、次に読むまで見ていません。
| 載せる条件: 確かめやすいコード | |
|---|---|
| 入口を読んだ | hooks/hooks.json が名指すモジュールをすべて読んだ。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/… などは無い)。hooks/register.tsx:488 open(Windows にない); hooks/register.tsx:917 open(Windows にない); hooks/register.tsx:964 open(Windows にない) |
| 通信 | fetch の送り先(https のホスト)がコードに書いてあるか。通信なし |
| プログラム | 起動するプログラムの名前がコードに書いてあり、シェル・インタプリタ・通信用の道具でないか。open(通信する) |
| 読んで送る | ファイルや環境変数を読み、かつ通信するか。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 KytioisaCat/playpen/plugin install playpen@kytioisacat入るのはマーケットプレイスの最新のコミットで、ここで読んだもの(d4309b75feb6)と違うことがあります。入れる前に見比べてください。
Claude に聞く
modscode のコネクタを入れると、Claude がこのデザイン・コードが触るもの・コードを読んで、それをもとに作れます。たとえば:
modscode のデザイン「kytioisacat-playpen」をコードごと読んで、同じようなペインを作って似たデザイン
-
Claude に頼む…2h 10m · █████░░░✓ build ✓ build ✓ buildJavaKotlin3 Python■ ok 3 ■ ok 3 ■ ok 3 Razor proven 3 Razor proven 3 Razor proven 3Phases ──────── 3/3build Pythonbuild Pythonbuild Python… 3 more phasesLua ──────── 3/Kotlin■ the whole upgrade Ruby■ build build Ruby■ build build Ruby■ build build Ruby … 3 moreNext ──────── PythonRuby (by hand)Podsclick a button, or ctrl+x tab then Tab, EnterAttention ──────── 3! Scala ! Scala ! Scala … 3 moreSession ──────── okJava
-
could not fill the prompt boxcould not fill:Claude に頼む…
-
▴Token OptimizerCheckpointCheckpointCheckpointbuildStart freshbuildStart freshbuildStart freshbuildCheckpointCheckpointCheckpointCheckpointCheckpointCheckpointCheckpointCheckpointCheckpointbuildbuildbuildTokens savedSaved Clean up tokens in 30 days (chat 2 this session)Claude に頼む…
-
reflect · "Skip" ×3Save to ./CLAUDE.mdGlobal insteadEditSkipreflect · "Skip" ×3Save to ./CLAUDE.mdGlobal insteadEditSkipreflect · "Skip" ×3reflect · +3 more · /reflect-queueSave to ./CLAUDE.mdGlobal insteadEditSkipClaude に頼む…
-
Open a file first: /crit-tui file <path>Reopen this one in the crit browser view.Claude に頼む…
-
✉ 3 unread AMP message ReadHideClaude に頼む…