Context window fill plus where session time goes: API requests (main and subagents) and per-tool totals

This repository contains my dotfiles and configurations, managed with GNU Stow for symlink management and Homebrew for cross-platform dependency installation.
Nvim setup is based on kickstart.nvim
Linux/macOS:
git clone https://github.com/a19simma/configs ~/repos/configs && source ~/repos/configs/shell/.bashrc && bootstrap-configs
Windows (PowerShell):
git clone https://github.com//a19simma/configs $env:USERPROFILE\repos\configs; . $env:USERPROFILE\repos\configs\PowerShell\Microsoft.PowerShell_profile.ps1; Bootstrap-Configs
The repository is organized into Stow packages:
shell/ - Shell configuration (.zshrc, .bashrc)nushell/ - Nushell configuration (config.nu, env.nu)neovim/ - Neovim configuration alacritty/ - Alacritty terminal configvscode/ - VS Code settings and profilestmux/ - Tmux configuration (.tmux.conf)Fresh Linux/macOS system:
# 1. Clone repository
git clone <your-repo-url> ~/repos/configs
# 2. Source the shell config to get bootstrap function
source ~/repos/configs/shell/.bashrc # or .zshrc
# 3. Run bootstrap (installs mise + all dependencies + deploys configs)
bootstrap-configs
Fresh Windows system:
# 1. Clone repository
git clone <your-repo-url> $env:USERPROFILE\repos\configs
# 2. Import PowerShell profile to get bootstrap function
. $env:USERPROFILE\repos\configs\PowerShell\Microsoft.PowerShell_profile.ps1
# 3. Run bootstrap (installs scoop + mise + all dependencies + deploys configs)
Bootstrap-Configs
Install Dependencies:
# Linux/macOS: Install via Homebrew Bundle
mise run install-deps
# Windows: Install via Scoop
mise run install-deps-windows
# Linux only: Install system-level dependencies
mise run install-system-deps
Linux/macOS (GNU Stow):
# Deploy all dotfiles using GNU Stow
mise run stow-deploy
# Remove dotfiles
mise run stow-remove
Windows (PowerShell):
# Deploy Windows configurations
mise run deploy-windows
# Remove Windows configs
mise run remove-windows
# Backup existing configs
mise run backup-configs
# Sync configs from system to repo
mise run sync-from-local
# Update from kickstart.nvim
mise run sync-kickstarthooks/register.tsx 177 lines1import { atom, read, update } from 'claude-code'
2import type { EngineInterface, Register } from 'claude-code'
3
4import type { Reading, Timing } from '../types'
5
6const EMPTY: Timing = { ms: 0, samples: [] }
7
8const tools = atom({ plugin: 'io-meter', key: 'toolTimes' } as const, {})
9const api = atom({ plugin: 'io-meter', key: 'apiTimes' } as const, { main: EMPTY, sub: EMPTY })
10const readings = atom({ plugin: 'io-meter', key: 'readings' } as const, [])
11const usd = atom({ plugin: 'io-meter', key: 'usd' } as const, null)
12
13const SKIP = new Set(['Agent'])
14const TOP = 5
15const HISTORY = 12
16const SAMPLES = 200
17const BARS = '▁▂▃▄▅▆▇█'
18
19const FORECAST = [
20 { upTo: 25, icon: '☀', word: 'Clear', color: 'yellow' },
21 { upTo: 50, icon: '☁', word: 'Cloudy', color: 'cyan' },
22 { upTo: 75, icon: '☂', word: 'Showers', color: 'blue' },
23 { upTo: 90, icon: '☇', word: 'Storm', color: 'magenta' },
24 { upTo: Infinity, icon: '↯', word: 'Compact soon', color: 'red' },
25]
26
27function fmt(ms: number): string {
28 if (ms < 10_000) return (ms / 1000).toFixed(1) + 's'
29 if (ms < 60_000) return Math.round(ms / 1000) + 's'
30 const m = Math.floor(ms / 60_000)
31 return m + 'm' + String(Math.round((ms % 60_000) / 1000)).padStart(2, '0')
32}
33
34function short(n: number): string {
35 if (n >= 1_000_000) return (n / 1_000_000).toFixed(1) + 'M'
36 if (n >= 1_000) return (n / 1_000).toFixed(1) + 'k'
37 return String(n)
38}
39
40function bucket(tool: string): string {
41 const m = /^mcp__(.+?)__/.exec(tool)
42 return m ? m[1] : tool
43}
44
45function add(t: Timing, ms: number): Timing {
46 return { ms: t.ms + ms, samples: [...t.samples, ms].slice(-SAMPLES) }
47}
48
49function p90(t: Timing): number {
50 const sorted = [...t.samples].sort((x, y) => x - y)
51 return sorted[Math.ceil(sorted.length * 0.9) - 1] ?? 0
52}
53
54function forecastFor(percent: number) {
55 return FORECAST.find(f => percent < f.upTo) ?? FORECAST[FORECAST.length - 1]
56}
57
58function chart(rs: Reading[]): string {
59 const top = Math.max(...rs.map(r => r.tokens), 1)
60 return rs.map(r => BARS[Math.min(BARS.length - 1, Math.floor((r.tokens / top) * (BARS.length - 1)))]).join('')
61}
62
63function trend(rs: Reading[]): string {
64 const [prev, last] = rs.slice(-2)
65 if (!prev || !last) return ''
66 const delta = last.tokens - prev.tokens
67 if (delta > 0) return '▲ +' + short(delta)
68 if (delta < 0) return '▼ ' + short(-delta)
69 return 'steady'
70}
71
72async function measure($: EngineInterface) {
73 const { context: c, cost } = await $.session.usage({ breakdown: 'summary' })
74 await update($, usd, () => cost?.usd ?? null)
75 const window = Math.min(c.window, c.breakdown?.rawMaxTokens ?? c.window)
76 if (!window) return
77 const tokens = c.tokens ?? 0
78 const reading: Reading = { tokens, window, percent: Math.round((tokens / window) * 100) }
79 await update($, readings, rs => {
80 const last = rs[rs.length - 1]
81 if (last && last.tokens === reading.tokens && last.window === reading.window) return rs
82 return [...rs.filter(r => r.tokens > 0), reading].slice(-HISTORY)
83 })
84}
85
86export const register: Register = on => {
87 on('session.start', async ($, e, next) => {
88 const result = await next(e)
89 await measure($)
90 return result
91 })
92
93 on('session.measure', async ($, e, next) => {
94 await measure($)
95 return next(e)
96 })
97
98 on('tool.call', async ($, e, next) => {
99 const t0 = await $.clock.now()
100 const result = await next(e)
101 if (!SKIP.has(e.tool)) {
102 const ms = (await $.clock.now()) - t0
103 const key = bucket(e.tool)
104 await update($, tools, all => ({ ...all, [key]: add(all[key] ?? EMPTY, ms) }))
105 }
106 return result
107 })
108
109 on('turn.step', async function* ($, e, next) {
110 const t0 = await $.clock.now()
111 const result = yield* next(e)
112 const ms = (await $.clock.now()) - t0
113 await update($, api, a => (e.agentId ? { ...a, sub: add(a.sub, ms) } : { ...a, main: add(a.main, ms) }))
114 return result
115 })
116
117 on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
118 if (e.props.hasSurvey) return next(e)
119
120 const rs = await read($, readings)
121 const cost = await read($, usd)
122 const a = await read($, api)
123 const t = await read($, tools)
124 const wide = (e.viewport?.columns ?? 80) >= 60
125 const { Box, Text } = $.ui.resolve(e)
126
127 const top = Object.entries(t)
128 .sort((x, y) => y[1].ms - x[1].ms)
129 .slice(0, TOP)
130 const toolMs = Object.values(t).reduce((s, v) => s + v.ms, 0)
131
132 const now = rs[rs.length - 1]
133 const f = now && forecastFor(now.percent)
134 const tr = trend(rs)
135
136 const ctxRow = now && f && (
137 <Box flexDirection="row">
138 <Text color={f.color} bold>
139 {f.icon} {f.word}
140 </Text>
141 <Text> {now.percent}% of context</Text>
142 <Text dimColor> {short(now.tokens)} / {short(now.window)}</Text>
143 {wide && <Text dimColor> last turns </Text>}
144 {wide && <Text color={f.color}>{chart(rs)}</Text>}
145 {wide && tr !== '' && <Text dimColor> {tr}</Text>}
146 {cost !== null && <Text dimColor> · ${cost.toFixed(2)}</Text>}
147 </Box>
148 )
149
150 const ioRow = (
151 <Box flexDirection="row">
152 <Text dimColor>total (p90) │ api </Text>
153 <Text>{fmt(a.main.ms)}</Text>
154 <Text dimColor> ({fmt(p90(a.main))})</Text>
155 {a.sub.samples.length > 0 && <Text dimColor> + sub </Text>}
156 {a.sub.samples.length > 0 && <Text>{fmt(a.sub.ms)}</Text>}
157 {a.sub.samples.length > 0 && <Text dimColor> ({fmt(p90(a.sub))})</Text>}
158 <Text dimColor> │ tools </Text>
159 <Text>{fmt(toolMs)}</Text>
160 {wide &&
161 top.map(([name, s]) => (
162 <Text key={name} dimColor>
163 {' │ '}{name} {fmt(s.ms)} ({fmt(p90(s))})
164 </Text>
165 ))}
166 </Box>
167 )
168
169 return (
170 <Box flexDirection="column" paddingX={1}>
171 {ctxRow}
172 {ioRow}
173 </Box>
174 )
175 })
176}
177types/index.d.ts 15 lines1export type Timing = { ms: number; samples: number[] }
2export type ApiTiming = { main: Timing; sub: Timing }
3export type Reading = { tokens: number; window: number; percent: number }
4
5declare module 'claude-code' {
6 interface PluginState {
7 'io-meter': {
8 toolTimes: Record<string, Timing>
9 apiTimes: ApiTiming
10 readings: Reading[]
11 usd: number | null
12 }
13 }
14}
15