A tool the model calls to report the session's cost, for remote control where /cost isn't available

install.sh is a good guide to how things work because it sets up all the symlinks.
Note: .helix and deno.jsonc are not dotfiles; they are config files for this repo.
hooks/register.ts 23 lines1import type { Register } from 'claude-code'
2
3// The mobile app over remote control has no /cost, so this gives the model a
4// tool to report it when asked.
5
6const usd = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' })
7
8export const register: Register = on => {
9 on('session.start', async ($, e, next) => {
10 await $.tool.register({
11 name: 'cost',
12 description:
13 "What the session has cost so far in US dollars, as /cost totals it. Call it when the user asks about cost.",
14 })
15 return next(e)
16 })
17
18 on('tool.call', { tool: 'mcp__session-cost__cost' }, async $ => {
19 const { cost } = await $.session.usage()
20 return { result: cost ? usd.format(cost.usd) : 'No cost ledger in this session.' }
21 })
22}
23