modscode / 図鑑 / session-switcher
session-switcher
A paged, filterable, taggable switcher over your recent Claude Code sessions, with a per-row activity strip showing when each one was busy. Resumes in the session's own directory.
何をするか
- 欄を描く
- session.start・ui.closeにフックする
- ターンをまたいで自分の状態を持つ
- プロセスを起こす
良いところ
- ネットワークに出ない
- TypeScript で書かれている
- エラーを扱う
- ファイルを書かない
作り始めるためのコード
2 種類あります。上のデザインから modscode が書いた雛形と、その Mod 自身のコードのうち描いている部分です。
雛形(register.tsx)
import type { Register } from 'claude-code'
// Drawn like session-switcher by Michael Shatny (pane, status), as modscode read it from the mod's code:
// https://modscode.com/gallery/semanticintent-session-switcher/
// 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: "Sessions" })
on('ui.render', { component: 'Pane', requestId: 'my-pane' }, async ($, e) => {
const { Box, Text, Button } = $.ui.resolve(e)
const length = '…'
const page = '…'
const pages = '…'
const query = '…'
const spark = '…'
const hotkey = '…'
const title = '…'
const ago = '…'
const project = '…'
const branch = '…'
const prompts = '…'
const filesTouched = '…'
const t = '…'
const project2 = '…'
const project3 = '…'
return (
<Box flexDirection="column" paddingX={1}>
<Box justifyContent="space-between">
<Text bold>
Sessions — tag which?
</Text>
<Text dimColor>
{`${length} found page ${page}1/${pages} indexing…`}
</Text>
</Box>
<Box marginBottom={1}>
<Text dimColor>
{`filter: ${query}`}
</Text>
</Box>
<Box flexDirection="column" marginBottom={1}>
<Box>
<Text>
{`${spark} `}
</Text>
<Box flexGrow={1}>
<Button hotkey={`${hotkey}`} plain label={`${title}`} />
</Box>
<Text dimColor>
{` ${ago}`}
</Text>
</Box>
<Box>
<Box flexShrink={0}>
<Text>
{project}
</Text>
</Box>
<Text dimColor wrap="truncate-end">
{` on ${branch}`}
</Text>
<Text dimColor wrap="truncate-end">
{` · ${prompts} prompt, ${filesTouched} files · sampled`}
</Text>
<Box flexShrink={0}>
<Text color="magenta">
{` #${t}`}
</Text>
</Box>
<Box flexShrink={0}>
<Text color="magenta">
{` #${t}`}
</Text>
</Box>
<Box flexShrink={0}>
<Text color="magenta">
{` #${t}`}
</Text>
</Box>
</Box>
</Box>
<Box flexDirection="column" marginBottom={1}>
<Box>
<Text>
{`${spark} `}
</Text>
<Box flexGrow={1}>
<Button hotkey={`${hotkey}`} plain label={`${title}`} />
</Box>
<Text dimColor>
{` ${ago}`}
</Text>
</Box>
<Box>
<Box flexShrink={0}>
<Text>
{project2}
</Text>
</Box>
<Text dimColor wrap="truncate-end">
{` on ${branch}`}
</Text>
<Text dimColor wrap="truncate-end">
{` · ${prompts} prompt, ${filesTouched} files · sampled`}
</Text>
<Box flexShrink={0}>
<Text color="magenta">
{` #${t}`}
</Text>
</Box>
<Box flexShrink={0}>
<Text color="magenta">
{` #${t}`}
</Text>
</Box>
<Box flexShrink={0}>
<Text color="magenta">
{` #${t}`}
</Text>
</Box>
</Box>
</Box>
<Box flexDirection="column" marginBottom={1}>
<Box>
<Text>
{`${spark} `}
</Text>
<Box flexGrow={1}>
<Button hotkey={`${hotkey}`} plain label={`${title}`} />
</Box>
<Text dimColor>
{` ${ago}`}
</Text>
</Box>
<Box>
<Box flexShrink={0}>
<Text>
{project3}
</Text>
</Box>
<Text dimColor wrap="truncate-end">
{` on ${branch}`}
</Text>
<Text dimColor wrap="truncate-end">
{` · ${prompts} prompt, ${filesTouched} files · sampled`}
</Text>
<Box flexShrink={0}>
<Text color="magenta">
{` #${t}`}
</Text>
</Box>
<Box flexShrink={0}>
<Text color="magenta">
{` #${t}`}
</Text>
</Box>
<Box flexShrink={0}>
<Text color="magenta">
{` #${t}`}
</Text>
</Box>
</Box>
</Box>
<Box marginTop={1} columnGap={2} flexWrap="wrap">
<Button hotkey="t" plain dimColor label="resume mode" />
<Button hotkey="p" plain dimColor label="prev" />
<Button hotkey="n" plain dimColor label="next" />
<Box flexShrink={0}>
<Text dimColor>
Esc close
</Text>
</Box>
<Box flexShrink={0}>
<Text dimColor>
· /switcher #tag tags this session
</Text>
</Box>
</Box>
</Box>
)
})
}
Mod 自身のコード
Mod のライセンス(MIT)に従って載せています。全文は下にあります。写すときは著作権表示を残してください。
hooks/register.ts 304〜337 行 · ペイン
on("ui.render", { component: "Pane" }, async ($, e, next) => {
if (e.requestId !== PANE_ID) return next(e);
const table = await $.ui.resolve(e);
// Element tables differ by surface — one without `Input` still gets rows.
const { Box, Text, Button } = table;
const Input = "Input" in table ? table.Input : undefined;
const actions: Actions = {
filter: (value) => { state.query = value; state.page = 0; $.ui.invalidate("ui.render"); },
turnPage: (by) => { state.page = Math.max(0, state.page + by); $.ui.invalidate("ui.render"); },
toggleMode: () => { state.mode = state.mode === "tag" ? "resume" : "tag"; $.ui.invalidate("ui.render"); },
pick: (id) => {
const s = state.sessions.find((x) => x.id === id);
if (!s) return;
if (state.mode === "tag") {
const m = metaFor(s, state.meta);
state.editing = { id, text: [m?.title, ...(m?.tags ?? []).map((t) => "#" + t)].filter(Boolean).join(" ") };
return $.ui.invalidate("ui.render");
}
void resume($, s);
},
editTags: (value) => {
const s = state.editing && state.sessions.find((x) => x.id === state.editing!.id);
if (s && state.store) { setMeta(s, state.meta, value); void saveMeta(state.store, state.meta); }
// Cheap when the edited row isn't this session: the same line re-pins.
void pinStatus($);
state.editing = null;
state.mode = "resume";
$.ui.invalidate("ui.render");
},
};
return view({ Box, Text, Button, Input }, model(), actions);
});hooks/view.ts 77〜146 行 · ペイン
export function view(ui: Elements, model: Model, actions: Actions): RenderElement {
const { Box, Text, Button, Input } = ui;
const rows = model.sessions.filter((s) => matches(s, model.meta, model.query));
const pages = Math.max(1, Math.ceil(rows.length / PAGE));
// Clamped: a filter that shrinks the list must not strand the view on a
// page that no longer exists.
const page = Math.min(Math.max(0, model.page), pages - 1);
const visible = rows.slice(page * PAGE, page * PAGE + PAGE);
const header = Box({
justifyContent: "space-between",
children: [
Text({ bold: true, children: model.mode === "tag" ? "Sessions — tag which?" : "Sessions" }),
Text({ dimColor: true, children: `${rows.length} found page ${page + 1}/${pages}${model.syncing ? " indexing…" : ""}` }),
],
});
const filter = Input ? Input({
key: "filter",
// No label: the surface draws its own separator after one, so "› " came
// out as "› :".
placeholder: "filter by title, project, branch or #tag",
value: model.query,
submitLabel: "filter",
autoFocus: true,
onInput: (value: string) => actions.filter(value),
onSubmit: (value: string) => actions.filter(value),
}) : Text({ dimColor: true, children: model.query ? `filter: ${model.query}` : "filter unavailable on this surface" });
const body = visible.length === 0
? [Text({ dimColor: true, children: `No sessions match “${model.query}”. Clear the filter to see them all.` })]
: visible.map((s, i) => row(ui, s, model, actions, HOTKEYS[i] ?? ""));
const editor = model.editing && Input
? Input({
key: "tags",
label: "Tag or rename",
placeholder: "#wip #mods or a new title or both",
value: model.editing.text,
submitLabel: "save",
autoFocus: true,
onInput: () => {},
onSubmit: (value: string) => actions.editTags(value),
})
// Same squeeze as the meta line: in a narrow pane "Esc close" drew as
// "Esc" / "clos" / "e". Controls wrap onto another line as whole items;
// columnGap, not gap, or the wrapped line lands two blank lines down.
: Box({
marginTop: 1,
columnGap: 2,
flexWrap: "wrap",
children: [
Button({ key: "mode", hotkey: "t", plain: true, dimColor: true,
label: model.mode === "tag" ? "resume mode" : "tag a session",
onPress: () => actions.toggleMode() }),
Button({ key: "prev", hotkey: "p", plain: true, dimColor: true, label: "prev",
onPress: () => actions.turnPage(-1) }),
Button({ key: "next", hotkey: "n", plain: true, dimColor: true, label: "next",
onPress: () => actions.turnPage(1) }),
Box({ flexShrink: 0, children: [Text({ dimColor: true, children: "Esc close" })] }),
Box({ flexShrink: 0, children: [Text({ dimColor: true, children: "· /switcher #tag tags this session" })] }),
],
});
return Box({
flexDirection: "column",
paddingX: 1,
children: [header, Box({ marginBottom: 1, children: [filter] }), ...body, editor],
});
}hooks/view.ts 148〜198 行 · ペイン
function row(ui: Elements, s: Session, model: Model, actions: Actions, hotkey: string): RenderElement {
const { Box, Text, Button } = ui;
const m = metaFor(s, model.meta);
const colour = hue(s.project);
const isEditing = model.editing?.id === s.id;
return Box({
key: s.id,
flexDirection: "column",
marginBottom: isEditing ? 1 : 0,
children: [
Box({
children: [
Text({ color: colour, children: spark(s.activity) + " " }),
Box({
flexGrow: 1,
children: [
Button({
key: `row:${s.id}`,
hotkey,
plain: true,
label: m?.title ?? s.title,
onPress: () => actions.pick(s.id),
}),
],
}),
Text({ dimColor: true, children: " " + ago(s.lastActive) }),
],
}),
// One meta line, not three. Ten rows have to fit the pane alongside the
// filter and the controls, and the opening prompt is still searchable
// whether or not it is drawn.
// When the line is wider than the pane, every child gets squeezed, and a
// squeezed Text wraps inside its own narrow column — "Projects" came out
// as "Project" over "s", and a long branch interleaved with the project.
// So the project and tags never shrink, and the branch truncates instead.
Box({
marginLeft: INDENT,
children: [
Box({ flexShrink: 0, children: [Text({ color: colour, children: s.project })] }),
...(s.branch ? [Text({ dimColor: true, wrap: "truncate-end", children: ` on ${s.branch}` })] : []),
Text({ dimColor: true, wrap: "truncate-end",
children: ` · ${s.prompts} ${s.prompts === 1 ? "prompt" : "prompts"}`
+ (s.filesTouched ? `, ${s.filesTouched} files` : "")
+ (s.partial ? " · sampled" : "") }),
...(m?.tags ?? []).map((t) => Box({ flexShrink: 0, children: [Text({ color: "magenta", children: ` #${t}` })] })),
],
}),
],
});
}ライセンスの全文(MIT)
MIT License Copyright (c) 2026 Michael Shatny 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 に読んだコミット f75d78ce6b43 のソースから。最初のまとまりが載せる条件で、残りは自分で判断するための材料です。後のコミットは、次に読むまで見ていません。
| 載せる条件: 確かめやすいコード | |
|---|---|
| 入口を読んだ | hooks/hooks.json が名指すモジュールをすべて読んだ。hooks/register.ts |
| 解析できる | すべてのファイルが TypeScript か JavaScript として解析できる。6 ファイルを解析 |
| コードが 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 のホスト)がコードに書いてあるか。通信なし |
| プログラム | 起動するプログラムの名前がコードに書いてあり、シェル・インタプリタ・通信用の道具でないか。hooks/register.ts:162 実行時に決まるプログラム |
| 読んで送る | ファイルや環境変数を読み、かつ通信するか。通信しない |
| ソースの鍵 | ソースに API キーや秘密鍵らしきものがあるか。ソースに鍵なし |
| ライセンス | オープンなライセンス(MIT・Apache-2.0・BSD・ISC・Unlicense・0BSD・CC0)で全文があれば、modscode にコードを載せる。違えばリンクだけ。MIT |
コードの文面を読んだだけで、安全の審査ではありません。動かしてはおらず、起動するプログラムの中で何が起きるかも見えません。入れる前の確認はあなたの役目です。 載せる条件
入れる
入れる前に、必ず自分で確かめてください。Mod はサンドボックスなしで、あなたの権限で動きます。modscode はこのコードの安全を保証しません。下のコードを読み(またはフォルダーで claude plugin validate .)、触るものを見て、読んだコミットを入れてください。
リポジトリがそのままマーケットプレイスです。このマーケットプレイスを足し(ターミナルでは次のコマンド、デスクトップアプリではプラグインの設定)、そこから Mod を入れます。
/plugin marketplace add semanticintent/claude-session-switcher/plugin install session-switcher@semanticintent入るのはマーケットプレイスの最新のコミットで、ここで読んだもの(f75d78ce6b43)と違うことがあります。入れる前に見比べてください。
Claude に聞く
modscode のコネクタを入れると、Claude がこのデザイン・コードが触るもの・コードを読んで、それをもとに作れます。たとえば:
modscode のデザイン「semanticintent-session-switcher」をコードごと読んで、同じようなペインを作って似たデザイン
-
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
-
Claude に頼む…great_cto: 3 gate waiting — /gatesGatesmy-app · 3 waiting · checked Gates UTCGates — Fix logina1b2c3dExpensive to undo. To approve, type Gates and press Enter.approve: Gates approveGates — Fix logina1b2c3dExpensive to undo. To approve, type Gates and press Enter.approve: Gates approveGates — Fix logina1b2c3dExpensive to undo. To approve, type Gates and press Enter.approve: Gates approve
-
Claude に頼む…agent-discoverbuildbuildbuildRefreshMCP Browse/3Tab / shift+Tab move · Enter presses · ↑↓ scroll · Esc back to the promptBrowse...Audit asks:DeclineAcceptDeclineCancelAudit asks:DeclineAcceptDeclineCancelAudit asks:DeclineAcceptDeclineCancel
-
何をするか
- /sage-memory を足す
- Bash の呼び出しを見張る(止めることがある)
- agent.spawn・classic.PostToolBatch・classic.SessionStart・prompt.attachment ほか 9 個にフックする
- ターンをまたいで自分の状態を持つ
-
Claude に頼む…Context●context-keeper42% full · 3 left████████░░░░░░░░3 of 3 tokensWhat fills itNo breakdown yet. It fills in after the first turn.build3████████░░░░░░░░build3████████░░░░░░░░Largest memory file: Actions (0)build3████████░░░░░░░░Tips• Checkpoint• Checkpoint• CheckpointActions● Measure nowCheckpoint cCheckpoint + compact kRefresh rCompact, keeping: e.g. the auth refactor and failing tests CompactCheckpointsNone yet. A checkpoint is a handoff note (goal, decisions, files, TODOs) you can reload after /clear.✓2h 10m note at 42%load✓2h 10m note at 42%load✓2h 10m note at 42%load
-
Claude に頼む…guard 3 rulesGuardrails●guardrailsokPresetsFix login 3Fix login 3Fix login 3Rules●Fix loginEdit●Fix loginEdit●Fix loginEditYour own block patterns (regex on shell commands)Read●/All off/remove●/All off/remove●/All off/removeregex, e.g. docker\s+system\s+prune AddRules are best-effort pattern checks, a seatbelt, not a sandbox. Saved for all your sessions.Blocked this session (3)Nothing blocked yet. When a rule stops a command, it shows up here with the rule that caught it.✗ Edit All off: Grep✗ Edit All off: Grep✗ Edit All off: Grep