cs
cs's in-session mod: the rotate band above the prompt, forced rotation past CS_ROTATE_FORCE_CTX, and the wrap key
何をするか
- プロンプトの上の帯・欄・トーストを描く
- /queue・/clear を足す
- prompt.submit・session.start・skill.prompt・turn.complete ほか 1 個にフックする
- プロセスを起こす
良いところ
- ネットワークに出ない
- TypeScript で書かれている
- エラーを扱う
作り始めるためのコード
2 種類あります。上のデザインから modscode が書いた雛形と、その Mod 自身のコードのうち描いている部分です。
雛形(register.tsx)
import type { Register } from 'claude-code'
// Drawn like cs by cs (pane, band, toast), as modscode read it from the mod's code:
// https://modscode.com/gallery/hex-cs/
// 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 cutTask = '…'
const gateElapsed = '…'
const left = '…'
return (
<Box flexDirection="column">
<Box flexDirection="column">
<Box marginTop={1}>
<Box paddingX={1}>
<Text>
{`finishing ${cutTask} · gate ${gateElapsed}`}
</Text>
</Box>
</Box>
</Box>
<Box marginTop={1}>
<Box paddingX={1}>
<Button hotkey="1" plain label="/clear and continue from the handoff" />
<Text dimColor>
{" · "}
</Text>
<Button hotkey="2" plain label="wrap up this session" />
<Text dimColor>
{" · "}
</Text>
<Text bold>
{`/clear in ${left}s`}
</Text>
</Box>
</Box>
{await next(e)}
</Box>
)
})
// the pane: open it with $.ui.open({ id: 'my-pane', title: "Handoff" })
on('ui.render', { component: 'Pane', requestId: 'my-pane' }, async ($, e) => {
const { Box, Text, Markdown } = $.ui.resolve(e)
const text = '…'
const left = '…'
return (
<Box flexDirection="column" paddingX={1}>
<Text bold>
Handoff
</Text>
<Box flexDirection="column" marginTop={1}>
<Markdown text={`${text}`} />
<Text dimColor>
… the rest of the step is in the handoff
</Text>
</Box>
<Box flexDirection="column" marginTop={1}>
<Box>
<Text>
████████░░░░░░░░
</Text>
<Text>
{" "}
</Text>
<Text bold>
{`/clear in ${left}s`}
</Text>
</Box>
<Text dimColor>
press 1 to clear now, or send a prompt to stay
</Text>
</Box>
</Box>
)
})
on('session.start', async ($, e, next) => {
const cutTask = '…'
const force = '…'
const startPercent = '…'
await $.ui.toast(`cs: queued: ${cutTask}`)
await $.ui.toast(`cs: CS_ROTATE_FORCE_CTX=${force} is below this conversation's starting context (${startPercent}%); not forcing a rotation`)
return next(e)
})
}
Mod 自身のコード
Mod のライセンス(MIT)に従って載せています。全文は下にあります。写すときは著作権表示を残してください。
mods/cs/hooks/register.tsx 323〜369 行 · バンド
on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
const drawn = await withGateBand($, e, await next(e))
// The band draws in a new conversation before any of its turns end, so
// the birth is settled here: a later /resume is not mistaken for it.
noteConversation(await $.session.id())
// A survey owns the band; a running turn cannot be rotated out of.
turnRunning = e.props.isWorking
bandIdle = !e.props.hasSurvey && !e.props.isWorking
if (!bandIdle) return drawn
const armed = await handoffArmed($)
const { context } = await $.session.usage()
const percent = context.percent
if (!armed && (percent === undefined || percent < (await threshold($)))) return drawn
if (!(await ownsRotation($))) return drawn
const wrapped = !armed && (await wrapFinished($))
const fill = surfaceColor(await $.env.get("CS_TERM_BG_RGB"))
const { Box, Text, Button } = await $.ui.resolve(e)
// One capsule in the status bar's idiom: the keys on the bar's own fill,
// a blank line above them so the band reads apart from the transcript.
// The context percentage is the bar's to carry; the band does not repeat
// it. The keyed box lights coral under the pointer; the engine restyles it
// without running the hook.
return (
<Box flexDirection="column">
{drawn}
<Box marginTop={1}>
<Box key="cs-rotate-band" paddingX={1} backgroundColor={fill}>
{/* The engine draws a plain button as "1: label", and it draws
that prefix whether or not the label is empty (measured live:
a hand-drawn digit beside an empty-label button prints the
hotkey twice), so the label stays on the button. */}
{armed
? <Button key="cs-rotate" hotkey="1" plain label="/clear and continue from the handoff"
onPress={() => clearAndContinue($)} />
: <Button key="cs-rotate" hotkey="1" plain label="rotate this conversation"
onPress={() => rotate($)} />}
{/* a Button is a block: nested in a Text the engine refuses the whole tree (measured), so the separator stands beside it */}
{!armed && !wrapped && <Text dimColor>{' \u00b7 '}</Text>}
{!armed && !wrapped && <Button key="cs-wrap" hotkey="2" plain label="wrap up this session" onPress={() => askToWrap($)} />}
{/* the forced rotation's grace: the seconds left before the mod runs the /clear itself */}
{armed && left !== undefined && <Text dimColor>{' \u00b7 '}</Text>}
{armed && left !== undefined && <Text bold color={await rampColor($, left)}>{`/clear in ${left}s`}</Text>}
</Box>
</Box>
</Box>
)
})mods/cs/hooks/register.tsx 915〜930 行 · バンド
async function withGateBand($: EngineInterface, e: Parameters<EngineInterface['ui']['resolve']>[0], drawn: unknown) {
if (finishGate === undefined) return drawn
const { Box, Text } = await $.ui.resolve(e)
const fill = surfaceColor(await $.env.get("CS_TERM_BG_RGB"))
const secs = Math.max(0, Math.floor((await $.clock.now()) / 1000) - finishGate.since)
return (
<Box flexDirection="column">
{drawn}
<Box marginTop={1}>
<Box paddingX={1} backgroundColor={fill}>
<Text>{`finishing ${cutTask(finishGate.task)} · gate ${gateElapsed(secs)}`}</Text>
</Box>
</Box>
</Box>
)
}mods/cs/hooks/register.tsx 373〜399 行 · ペイン
on('ui.render', { component: 'Pane' }, async ($, e, next) => {
if (e.requestId !== PREVIEW_PANE || preview === undefined) return next(e)
const { Box, Text, Markdown } = await $.ui.resolve(e)
// With one pane open the engine draws no title, so the pane carries its
// own, in the session's colour; the step is drawn as a reply's markdown is.
const own = paletteColor(await sessionColor($))
const color = left === undefined ? undefined : await rampColor($, left)
return (
<Box flexDirection="column" paddingX={1}>
<Text key="header" bold color={own}>Handoff</Text>
<Box flexDirection="column" marginTop={1}>
<Markdown key="step" text={preview.text} />
{preview.cut && <Text key="cut" dimColor>… the rest of the step is in the handoff</Text>}
</Box>
{left !== undefined && (
<Box flexDirection="column" marginTop={1}>
<Box>
<Text key="bar" color={color}>{countdownBar(left)}</Text>
<Text>{' '}</Text>
<Text key="count" bold color={color}>{`/clear in ${left}s`}</Text>
</Box>
<Text dimColor>press 1 to clear now, or send a prompt to stay</Text>
</Box>
)}
</Box>
)
})ライセンスの全文(MIT)
MIT License Copyright (c) 2025 cs-tool contributors 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 に読んだコミット 0d28619de59b のソースから。最初のまとまりが載せる条件で、残りは自分で判断するための材料です。後のコミットは、次に読むまで見ていません。
| 載せる条件: 確かめやすいコード | |
|---|---|
| 入口を読んだ | hooks/hooks.json が名指すモジュールをすべて読んだ。mods/cs/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/… などは無い)。mods/cs/hooks/register.tsx:893 kill(Windows にない) |
| 通信 | fetch の送り先(https のホスト)がコードに書いてあるか。通信なし |
| プログラム | 起動するプログラムの名前がコードに書いてあり、シェル・インタプリタ・通信用の道具でないか。mods/cs/hooks/register.tsx:255 実行時に決まるプログラム; mods/cs/hooks/register.tsx:763 実行時に決まるプログラム |
| 読んで送る | ファイルや環境変数を読み、かつ通信するか。通信しない |
| ソースの鍵 | ソースに 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 のデザイン「hex-cs」をコードごと読んで、同じようなペインを作って似たデザイン
-
Claude に頼む…Question guideAwaiting answer Questions from Claude (3)Freeform answer1/3p ◀ Previousn Next ▶l Latesta AI explanation: ONh Hide historyCloseAI tokens this session: 3$1.24▍Your recent instructions▍Claude's preceding explanationCancelledFreeform answerExplainf Full context✦ AI explanation (instructions, context, effects, recommendation)compact context42%Generating… (you can keep answering)Freeform answerCould not generate an explanation: Freeform answerOFF (enable for the next question with [a])────────Past questions and answers31/3 ▶ Selected[Freeform answer] Question guide → Awaiting answer[Freeform answer] Question guide → Awaiting answer[Freeform answer] Question guide → Awaiting answer→ Freeform: Explain31/3 ▶ Selected[Freeform answer] Question guide → Awaiting answer[Freeform answer] Question guide → Awaiting answer[Freeform answer] Question guide → Awaiting answer→ Freeform: Explain31/3 ▶ Selected[Freeform answer] Question guide → Awaiting answer[Freeform answer] Question guide → Awaiting answer[Freeform answer] Question guide → Awaiting answer→ Freeform: Explain
-
Claude に頼む…Skins0 Your promptadd rate limiting to the hub api0 Tool rows: finished, running, failedYour prompt Spinner0 Folded group of reads and searches●main · note 3 · note 3 · note 30 Edit diff cardDesktop only; the terminal keeps Claude Code's diff.0 Shell output cardDesktop only.0 Code block cardDesktop only; the terminal keeps Claude Code's markdown.0 TableAccentAccentAccentAccentAccentAccentAccentAccentAccentAccentAccentAccentCopyAccentAccentAccentAccentAccentAccentAccentAccentAccentAccentAccentAccentCopyAccentAccentAccentAccentAccentAccentAccentAccentAccentAccentAccentAccentCopy0 SpinnerAccent SpinnerSpinnerSpinner… 2h 10m0 Band above the prompt: normal, then nudging to compact█████░░░ 42% build█████░░░ 42% build█████░░░ 42% buildContext is 42% full0 Compact now0 Band above a questionTable BashBashBash0 Turn footer (terminal)3 build in 2h 10m · Grep · +3 −3
-
Claude に頼む…Glossary BrowserGlossary openContextsContextsContexts▲ prevWrite1/Glossary▼ nextContexts
-
Claude に頼む…envbuildbuildbuild+ .env.localsrc/app.ts is not in .gitignoreWriteNo .env files in the project root yet.K = paste the value, Enter saves saveNew key: NAME, Enter to continuegenerate randomcancelMissing compared with Write:KKK
-
何をするか
- 欄・プロンプトの上の帯を描く
- Bash の呼び出しを見張る(止めることがある)
- classic.CwdChanged・classic.SessionStart・classic.SubagentStart・classic.UserPromptSubmit ほか 5 個にフックする
- ターンをまたいで自分の状態を持つ
-
Claude に頼む…────────Clear doneClaude⋯└─ buildCancelCancelCancel└─ buildCancelCancelCancel└─ buildCancelCancelCancel