loc-split
Lines changed against main, split into code, comments, tests, docs and generated files, in a row above the prompt that expands into a per-commit table
何をするか
- プロンプトの上の帯を描く
- /loc-split を足す
- ツールの呼び出しを見張る
- session.start・turn.completeにフックする
- ターンをまたいで自分の状態を持つ
良いところ
- ネットワークに出ない
- TypeScript で書かれている
- デスクトップ専用の分岐がある
- エラーを扱う
作り始めるためのコード
2 種類あります。上のデザインから modscode が書いた雛形と、その Mod 自身のコードのうち描いている部分です。
雛形(register.tsx)
import type { Register } from 'claude-code'
// Drawn like loc-split by Roman Hotsiy (band), as modscode read it from the mod's code:
// https://modscode.com/gallery/romanhotsiy-loc-split/
// 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 titleOf = '…'
const offset = '…'
const length = '…'
const name = '…'
const name2 = '…'
const name3 = '…'
const sha = '…'
const subject = '…'
const added = '…'
const removed = '…'
const added2 = '…'
const removed2 = '…'
const added3 = '…'
const removed3 = '…'
const sha2 = '…'
const subject2 = '…'
const added4 = '…'
const removed4 = '…'
const added5 = '…'
const removed5 = '…'
const added6 = '…'
const removed6 = '…'
const sha3 = '…'
const subject3 = '…'
const added7 = '…'
const removed7 = '…'
const added8 = '…'
const removed8 = '…'
const added9 = '…'
const removed9 = '…'
const older = '…'
const added10 = '…'
const removed10 = '…'
const added11 = '…'
const removed11 = '…'
const added12 = '…'
const removed12 = '…'
const shortRef = '…'
const added13 = '…'
const removed13 = '…'
const added14 = '…'
const removed14 = '…'
const added15 = '…'
const removed15 = '…'
const toggleLabel = '…'
const LABELS = '…'
const added16 = '…'
const removed16 = '…'
const LABELS2 = '…'
const added17 = '…'
const removed17 = '…'
const LABELS3 = '…'
const added18 = '…'
const removed18 = '…'
return (
<Box flexDirection="column" paddingLeft={1}>
<Box flexDirection="column" marginBottom={1}>
<Box flexDirection="row" justifyContent="space-between">
<Text bold wrap="truncate">
{titleOf}
</Text>
<Box flexShrink={0} marginLeft={2}>
<Text dimColor>
{`${offset}1`}
–
{`${offset}${length}`}
{" of "}
{length}
</Text>
</Box>
</Box>
<Box flexDirection="row">
<Box flexGrow={1} flexShrink={1} />
<Box flexShrink={0} justifyContent="flex-end">
<Text dimColor>
{name}
</Text>
</Box>
<Box flexShrink={0} justifyContent="flex-end">
<Text dimColor>
{name2}
</Text>
</Box>
<Box flexShrink={0} justifyContent="flex-end">
<Text dimColor>
{name3}
</Text>
</Box>
<Box width={3} flexShrink={0} justifyContent="center">
<Button plain label="↑" />
</Box>
</Box>
<Box flexDirection="row" marginTop="0">
<Box flexGrow={1} flexShrink={1} minWidth={0} overflow="hidden">
<Box flexDirection="row" minWidth={0} overflow="hidden">
<Box width={9} flexShrink={0}>
<Text dimColor>
{sha}
</Text>
</Box>
<Box flexShrink={1} minWidth={0} overflow="hidden" marginRight={1}>
<Text wrap="truncate-end">
{subject}
</Text>
</Box>
</Box>
</Box>
<Box flexShrink={0} justifyContent="flex-end">
<Text>
<Text color="success">
+
{added}
</Text>
{" "}
<Text color="error">
−
{removed}
</Text>
</Text>
</Box>
<Box flexShrink={0} justifyContent="flex-end">
<Text>
<Text color="success">
+
{added2}
</Text>
{" "}
<Text color="error">
−
{removed2}
</Text>
</Text>
</Box>
<Box flexShrink={0} justifyContent="flex-end">
<Text>
<Text color="success">
+
{added3}
</Text>
{" "}
<Text color="error">
−
{removed3}
</Text>
</Text>
</Box>
<Box width={3} flexShrink={0} justifyContent="center">
<Text>
•
</Text>
</Box>
</Box>
<Box flexDirection="row" marginTop="0">
<Box flexGrow={1} flexShrink={1} minWidth={0} overflow="hidden">
<Box flexDirection="row" minWidth={0} overflow="hidden">
<Box width={9} flexShrink={0}>
<Text dimColor>
{sha2}
</Text>
</Box>
<Box flexShrink={1} minWidth={0} overflow="hidden" marginRight={1}>
<Text wrap="truncate-end">
{subject2}
</Text>
</Box>
</Box>
</Box>
<Box flexShrink={0} justifyContent="flex-end">
<Text>
<Text color="success">
+
{added4}
</Text>
{" "}
<Text color="error">
−
{removed4}
</Text>
</Text>
</Box>
<Box flexShrink={0} justifyContent="flex-end">
<Text>
<Text color="success">
+
{added5}
</Text>
{" "}
<Text color="error">
−
{removed5}
</Text>
</Text>
</Box>
<Box flexShrink={0} justifyContent="flex-end">
<Text>
<Text color="success">
+
{added6}
</Text>
{" "}
<Text color="error">
−
{removed6}
</Text>
</Text>
</Box>
<Box width={3} flexShrink={0} justifyContent="center">
<Text>
•
</Text>
</Box>
</Box>
<Box flexDirection="row" marginTop="0">
<Box flexGrow={1} flexShrink={1} minWidth={0} overflow="hidden">
<Box flexDirection="row" minWidth={0} overflow="hidden">
<Box width={9} flexShrink={0}>
<Text dimColor>
{sha3}
</Text>
</Box>
<Box flexShrink={1} minWidth={0} overflow="hidden" marginRight={1}>
<Text wrap="truncate-end">
{subject3}
</Text>
</Box>
</Box>
</Box>
<Box flexShrink={0} justifyContent="flex-end">
<Text>
<Text color="success">
+
{added7}
</Text>
{" "}
<Text color="error">
−
{removed7}
</Text>
</Text>
</Box>
<Box flexShrink={0} justifyContent="flex-end">
<Text>
<Text color="success">
+
{added8}
</Text>
{" "}
<Text color="error">
−
{removed8}
</Text>
</Text>
</Box>
<Box flexShrink={0} justifyContent="flex-end">
<Text>
<Text color="success">
+
{added9}
</Text>
{" "}
<Text color="error">
−
{removed9}
</Text>
</Text>
</Box>
<Box width={3} flexShrink={0} justifyContent="center">
<Text>
•
</Text>
</Box>
</Box>
<Box flexDirection="row">
<Box flexGrow={1} />
<Box width={3} flexShrink={0} justifyContent="center">
<Button plain label="↓" />
</Box>
</Box>
<Text dimColor>
{"… "}
{older}
{" older commit"}
{" not listed"}
</Text>
<Box flexDirection="row">
<Box flexGrow={1} flexShrink={1} minWidth={0} overflow="hidden">
<Text color="warning">
✎ uncommitted
</Text>
</Box>
<Box flexShrink={0} justifyContent="flex-end">
<Text>
<Text color="success">
+
{added10}
</Text>
{" "}
<Text color="error">
−
{removed10}
</Text>
</Text>
</Box>
<Box flexShrink={0} justifyContent="flex-end">
<Text>
<Text color="success">
+
{added11}
</Text>
{" "}
<Text color="error">
−
{removed11}
</Text>
</Text>
</Box>
<Box flexShrink={0} justifyContent="flex-end">
<Text>
<Text color="success">
+
{added12}
</Text>
{" "}
<Text color="error">
−
{removed12}
</Text>
</Text>
</Box>
</Box>
<Box flexDirection="row" marginTop="0">
<Box flexGrow={1} flexShrink={1} minWidth={0} overflow="hidden">
<Text bold>
{"Σ net vs "}
{shortRef}
</Text>
</Box>
<Box flexShrink={0} justifyContent="flex-end">
<Text>
<Text color="success">
+
{added13}
</Text>
{" "}
<Text color="error">
−
{removed13}
</Text>
</Text>
</Box>
<Box flexShrink={0} justifyContent="flex-end">
<Text>
<Text color="success">
+
{added14}
</Text>
{" "}
<Text color="error">
−
{removed14}
</Text>
</Text>
</Box>
<Box flexShrink={0} justifyContent="flex-end">
<Text>
<Text color="success">
+
{added15}
</Text>
{" "}
<Text color="error">
−
{removed15}
</Text>
</Text>
</Box>
</Box>
<Text dimColor>
partial: git output was cut
</Text>
</Box>
<Box flexDirection="row" justifyContent="space-between">
<Box flexShrink={0} marginLeft={0}>
<Button plain label={`${toggleLabel}`} />
<Text color="warning">
{" ✎"}
</Text>
</Box>
<Box flexShrink={1} marginLeft={2}>
<Text wrap="truncate">
<Text dimColor>
{" · "}
</Text>
<Text dimColor>
{LABELS}
{" "}
</Text>
<Text color="success">
+
{added16}
</Text>
{" "}
<Text color="error">
−
{removed16}
</Text>
<Text dimColor>
{" · "}
</Text>
<Text dimColor>
{LABELS2}
{" "}
</Text>
<Text color="success">
+
{added17}
</Text>
{" "}
<Text color="error">
−
{removed17}
</Text>
<Text dimColor>
{" · "}
</Text>
<Text dimColor>
{LABELS3}
{" "}
</Text>
<Text color="success">
+
{added18}
</Text>
{" "}
<Text color="error">
−
{removed18}
</Text>
</Text>
</Box>
</Box>
{await next(e)}
</Box>
)
})
}
Mod 自身のコード
Mod のライセンス(MIT)に従って載せています。全文は下にあります。写すときは著作権表示を残してください。
loc-split/hooks/register.ts 207〜225 行 · バンド
on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
if (e.props.hasSurvey) return next(e)
if (e.surface !== 'terminal' && e.surface !== 'desktop') return next(e)
const r = (await $.state.get(REPORT)).value ?? null
if (r === null) return next(e)
const isOpen = (await $.state.get(IS_EXPANDED)).value ?? false
const offset = (await $.state.get(SCROLL)).value ?? 0
const { Box, Button, Text } = $.ui.resolve(e)
return drawBand(
{ Box, Button, Text },
r,
{ isOpen, offset, surface: e.surface, bodyColumns: e.props.bodyColumns, maxRows: e.props.maxRows },
{
toggle: () => void toggleExpanded($),
scrollBy: (by, lastOffset) => void scrollBy($, by, lastOffset),
},
)
})loc-split/hooks/band.tsx 131〜280 行 · バンド
export function drawBand(ui: BandUi, r: LocReport, view: BandView, actions: BandActions) {
const { Box, Button, Text } = ui
const { isOpen } = view
const counts = (count: LocCount) =>
isZero(count)
? [<Text dimColor>·</Text>]
: [
count.added > 0 && <Text color="success">+{count.added}</Text>,
count.added > 0 && count.removed > 0 && ' ',
count.removed > 0 && <Text color="error">−{count.removed}</Text>,
]
const shown = changed(r.net)
const isDirty = !isEmptySplit(r.uncommitted)
// The terminal draws the band's collapse mark at its edge; the desktop does not.
const chrome = view.surface === 'terminal' ? BAND_CHROME : 0
const fit = fitFor(r, view.bodyColumns - chrome - 2 * PADDING)
const summary = (
<Box flexDirection="row" justifyContent="space-between">
<Box flexShrink={0} marginLeft={view.surface === 'desktop' ? -BUTTON_INSET : 0}>
<Button key="toggle" plain label={toggleLabel(r, fit, isOpen)} onPress={actions.toggle} />
{isDirty && <Text color="warning"> ✎</Text>}
</Box>
<Box flexShrink={1} marginLeft={2}>
<Text wrap="truncate">
{shown.length === 0 ? (
<Text dimColor>no changes</Text>
) : (
shown.map((category, i) => [
i > 0 && <Text dimColor> · </Text>,
<Text dimColor>{LABELS[category][fit.isShort ? 'short' : 'full']} </Text>,
counts(countFor(r.net[category], fit)),
])
)}
</Text>
</Box>
</Box>
)
if (!isOpen) {
return (
<Box key="loc-split" flexDirection="column" paddingLeft={PADDING} paddingRight={PADDING + chrome}>
{summary}
</Box>
)
}
const { columns, names, widths, label } = layout(r, view.bodyColumns - chrome - 2 * PADDING - SCROLLBAR_CELLS)
// Each cell is a box of fixed width, so the columns line up in a
// proportional font (the desktop) as well as in a terminal's grid.
const cells = (split: LocSplit) =>
columns.map((column, i) => (
<Box width={(widths[i] ?? 0) + GAP} flexShrink={0} justifyContent="flex-end">
<Text>{counts(split[column])}</Text>
</Box>
))
const tableRow = (head: RenderChildren, split: LocSplit, marginTop = 0, bar?: RenderChildren) => (
<Box flexDirection="row" marginTop={marginTop}>
<Box width={label} flexGrow={1} flexShrink={1} minWidth={0} overflow="hidden">
{head}
</Box>
{cells(split)}
{bar}
</Box>
)
const older = r.commitCount - r.commits.length
const fixed = FIXED_ROWS + (isDirty ? 1 : 0) + (older > 0 ? 1 : 0)
const room = view.maxRows - fixed
const listRows = Math.max(2, Math.min(LIST_ROWS, room))
const canScroll = r.commits.length > listRows
const lastOffset = Math.max(0, r.commits.length - listRows)
const offset = Math.min(view.offset, lastOffset)
const visible = r.commits.slice(offset, offset + listRows)
const page = Math.max(1, listRows - 1)
// A scroll bar beside the list: an arrow above and below a track of dots
// whose bright run is as long, and sits as far down, as the window over
// the commits. Dots, centered, read the same in a terminal's grid and in
// the desktop's proportional font, where line glyphs never join up.
const thumb = Math.max(1, Math.round((listRows * listRows) / Math.max(1, r.commits.length)))
const thumbAt = lastOffset === 0 ? 0 : Math.round((offset / lastOffset) * (listRows - thumb))
const barCell = (child: RenderChildren) => (
<Box width={SCROLLBAR_CELLS} flexShrink={0} justifyContent="center">
{child}
</Box>
)
const track = (row: number) =>
canScroll &&
barCell(row >= thumbAt && row < thumbAt + thumb ? <Text>•</Text> : <Text dimColor>·</Text>)
return (
<Box key="loc-split" flexDirection="column" paddingLeft={PADDING} paddingRight={PADDING + chrome}>
<Box flexDirection="column" marginBottom={1}>
<Box flexDirection="row" justifyContent="space-between">
<Text bold wrap="truncate">
{titleOf(r)}
</Text>
{canScroll && (
<Box flexShrink={0} marginLeft={2}>
<Text dimColor>
{offset + 1}–{offset + visible.length} of {r.commits.length}
</Text>
</Box>
)}
</Box>
<Box flexDirection="row">
<Box width={label} flexGrow={1} flexShrink={1} />
{names.map((name, i) => (
<Box width={(widths[i] ?? 0) + GAP} flexShrink={0} justifyContent="flex-end">
<Text dimColor>{name}</Text>
</Box>
))}
{canScroll &&
barCell(<Button key="up" plain dimColor={offset === 0} label="↑" onPress={() => actions.scrollBy(-page, lastOffset)} />)}
</Box>
{visible.map((one, row) =>
tableRow(
<Box flexDirection="row" minWidth={0} overflow="hidden">
<Box width={SHA_CELLS} flexShrink={0}>
<Text dimColor>{one.sha}</Text>
</Box>
<Box flexShrink={1} minWidth={0} overflow="hidden" marginRight={1}>
<Text wrap="truncate-end">{one.subject}</Text>
</Box>
</Box>,
one.split,
0,
track(row),
),
)}
{canScroll && (
<Box flexDirection="row">
<Box flexGrow={1} />
{barCell(<Button key="down" plain dimColor={offset === lastOffset} label="↓" onPress={() => actions.scrollBy(page, lastOffset)} />)}
</Box>
)}
{older > 0 && (
<Text dimColor>
… {older} older commit{older === 1 ? '' : 's'} not listed
</Text>
)}
{isDirty && tableRow(<Text color="warning">✎ uncommitted</Text>, r.uncommitted)}
{tableRow(<Text bold>Σ net vs {shortRef(r.base)}</Text>, r.net, canScroll ? 0 : 1)}
{r.isPartial && <Text dimColor>partial: git output was cut</Text>}
</Box>
{summary}
</Box>
)
}ライセンスの全文(MIT)
MIT License Copyright (c) 2026 Roman Hotsiy 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 に読んだコミット 204a8da7c0ed のソースから。最初のまとまりが載せる条件で、残りは自分で判断するための材料です。後のコミットは、次に読むまで見ていません。
| 載せる条件: 確かめやすいコード | |
|---|---|
| 入口を読んだ | hooks/hooks.json が名指すモジュールをすべて読んだ。loc-split/hooks/register.ts |
| 解析できる | すべてのファイルが TypeScript か JavaScript として解析できる。4 ファイルを解析 |
| コードが 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 のホスト)がコードに書いてあるか。通信なし |
| プログラム | 起動するプログラムの名前がコードに書いてあり、シェル・インタプリタ・通信用の道具でないか。loc-split/hooks/register.ts:99 実行時に決まるプログラム; loc-split/hooks/register.ts:104 実行時に決まるプログラム; loc-split/hooks/register.ts:105 実行時に決まるプログラム; loc-split/hooks/register.ts:106 実行時に決まるプログラム; loc-split/hooks/register.ts:107 実行時に決まるプログラム |
| 読んで送る | ファイルや環境変数を読み、かつ通信するか。読んだうえで通信する |
| ソースの鍵 | ソースに API キーや秘密鍵らしきものがあるか。ソースに鍵なし |
| ライセンス | オープンなライセンス(MIT・Apache-2.0・BSD・ISC・Unlicense・0BSD・CC0)で全文があれば、modscode にコードを載せる。違えばリンクだけ。MIT |
コードの文面を読んだだけで、安全の審査ではありません。動かしてはおらず、起動するプログラムの中で何が起きるかも見えません。入れる前の確認はあなたの役目です。 載せる条件
入れる
入れる前に、必ず自分で確かめてください。Mod はサンドボックスなしで、あなたの権限で動きます。modscode はこのコードの安全を保証しません。下のコードを読み(またはフォルダーで claude plugin validate .)、触るものを見て、読んだコミットを入れてください。
リポジトリがそのままマーケットプレイスです。このマーケットプレイスを足し(ターミナルでは次のコマンド、デスクトップアプリではプラグインの設定)、そこから Mod を入れます。
/plugin marketplace add RomanHotsiy/claude-mods/plugin install loc-split@claude-mods入るのはマーケットプレイスの最新のコミットで、ここで読んだもの(204a8da7c0ed)と違うことがあります。入れる前に見比べてください。
Claude に聞く
modscode のコネクタを入れると、Claude がこのデザイン・コードが触るもの・コードを読んで、それをもとに作れます。たとえば:
modscode のデザイン「romanhotsiy-loc-split」をコードごと読んで、同じようなペインを作って似たデザイン
-
Claude に頼む…Blast RadiusBlast Radius: npm testWould Cancel. Proceed Proceed ProceedProceed 1Cancel 2
-
Claude に頼む…Replay TheaterReplay Theater 31 31 31src/app.ts (step 01 of 3)● Write● Write● WritePrev pNext nClose q
-
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
-
何をするか
- プロンプトの上の帯を描く
- /seo-spend・/seo-doctor・/seo-cockpit を足す
- Agent の呼び出しを見張る(止めることがある)
- agent.spawn・classic.SessionStart・prompt.submit・session.compact ほか 3 個にフックする
-
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 に頼む…