Turbocharge Claude Code, Cursor, Codex, Gemini & every coding agent: faster, cheaper, with contextual understanding specific to your codebase.
TypeScript ai-agentsanthropicclaude-codeclicode-graphcodexcontext-engineeringcursordeveloper-toolsgeminiknowledge-graphllmmcpmcp-serveropen-sourceopenaitree-sitter
feat(claude): statusline reader + shim + settings
Shrish Dwivedi29db13cae9f0
diff --git a/.claude/helpers/graft-statusline.cjs b/.claude/helpers/graft-statusline.cjsnew file mode 100644index 00000000..63a42899--- /dev/null+++ b/.claude/helpers/graft-statusline.cjs@@ -0,0 +1,6 @@+#!/usr/bin/env node+const path = require('path');+const dir = process.env.CLAUDE_PROJECT_DIR || process.cwd();+import(path.join(dir, 'dist', 'claude', 'statusline.js'))+ .then((m) => m.main())+ .catch(() => { /* graft not built or unavailable — render nothing */ });diff --git a/.claude/settings.json b/.claude/settings.jsonnew file mode 100644index 00000000..93fae57e--- /dev/null+++ b/.claude/settings.json@@ -0,0 +1,6 @@+{+ "statusLine": {+ "type": "command",+ "command": "node \"${CLAUDE_PROJECT_DIR:-.}/.claude/helpers/graft-statusline.cjs\""+ }+}diff --git a/src/claude/format.ts b/src/claude/format.tsnew file mode 100644index 00000000..3c37463e--- /dev/null+++ b/src/claude/format.ts@@ -0,0 +1,45 @@+import { basename } from 'node:path';+import type { Stats, SessionState } from './state.js';++const C = {+ indigo: (s: string) => `\x1b[38;2;84;111;255m${s}\x1b[0m`,+ amber: (s: string) => `\x1b[38;2;224;165;68m${s}\x1b[0m`,+ muted: (s: string) => `\x1b[38;5;244m${s}\x1b[0m`,+ text: (s: string) => `\x1b[38;5;251m${s}\x1b[0m`,+};+const SEP = C.muted(' · ');++export function enrichedSegment(s: Stats): string | null {+ if (s.readyCount < 1) return null;+ const pct = s.totalCount ? Math.round((s.readyCount / s.totalCount) * 100) : 0;+ return C.indigo(`${pct}% enriched`);+}++export function freshnessSegment(s: Stats): string {+ if (s.syncing) return C.amber('syncing…');+ if (s.dirty && s.staleCount > 0) return C.amber(`⚠ ${s.staleCount} stale`);+ if (s.dirty) return C.amber('⚠ stale');+ return C.indigo('✓ synced');+}++export function renderStatusline(+ stats: Stats | null,+ _session: SessionState | null,+ ctx: { ctxPct: number | null },+): string[] {+ if (!stats || stats.nodeCount === 0) {+ return [C.muted('◤ graft · not built · run ') + C.text('graft build')];+ }+ const top = [C.muted('◤ ') + C.indigo('graft'), C.text(`${stats.nodeCount} nodes / ${stats.edgeCount} edges`)];+ const enr = enrichedSegment(stats);+ if (enr) top.push(enr);+ top.push(freshnessSegment(stats));++ const bottom: string[] = [];+ if (typeof ctx.ctxPct === 'number') bottom.push(C.text(`ctx ${ctx.ctxPct}%`));+ if (stats.lastFile) bottom.push(C.muted('last: ') + C.text(basename(stats.lastFile)));++ const lines = [top.join(SEP)];+ if (bottom.length) lines.push(C.muted('▸ ') + bottom.join(SEP));+ return lines;+}diff --git a/src/claude/statusline.ts b/src/claude/statusline.tsnew file mode 100644index 00000000..06c44b31--- /dev/null+++ b/src/claude/statusline.ts@@ -0,0 +1,14 @@+import { readFileSync } from 'node:fs';+import { renderStatusline } from './format.js';+import { readStats, readSession } from './state.js';++export function main(): void {+ let input: any = {};+ try { input = JSON.parse(readFileSync(0, 'utf8')); } catch { /* no/invalid stdin */ }+ const dir = process.env.CLAUDE_PROJECT_DIR || input.cwd || process.cwd();+ const stats = readStats(dir);+ const session = readSession(dir, input.session_id || 'default');+ const raw = input?.context_window?.used_percentage;+ const ctxPct = typeof raw === 'number' ? Math.round(raw) : null;+ process.stdout.write(renderStatusline(stats, session, { ctxPct }).join('\n'));+}diff --git a/test/claude-format.test.ts b/test/claude-format.test.tsnew file mode 100644index 00000000..be2e74cb--- /dev/null+++ b/test/claude-format.test.ts@@ -0,0 +1,38 @@+import { test } from 'node:test';+import assert from 'node:assert/strict';+import { renderStatusline, enrichedSegment } from '../src/claude/format.js';+import { emptyStats } from '../src/claude/state.js';++const strip = (s: string) => s.replace(/\x1b\[[0-9;]*m/g, '');++test('not-built state', () => {+ const lines = renderStatusline(null, null, { ctxPct: null });+ assert.match(strip(lines[0]), /not built/);+});++test('enriched segment hidden when zero ready', () => {+ assert.equal(enrichedSegment({ ...emptyStats(), totalCount: 10, readyCount: 0 }), null);+});++test('enriched segment shown when >=1 ready', () => {+ const seg = enrichedSegment({ ...emptyStats(), totalCount: 4, readyCount: 2 });+ assert.equal(strip(seg!), '50% enriched');+});++test('two-line bar: size + freshness + ctx + last', () => {+ const stats = { ...emptyStats(), nodeCount: 319, edgeCount: 730, totalCount: 319, readyCount: 0,+ dirty: true, staleCount: 4, lastFile: 'pkce.ts' };+ const lines = renderStatusline(stats, null, { ctxPct: 34 }).map(strip);+ assert.match(lines[0], /graft/);+ assert.match(lines[0], /319 nodes \/ 730 edges/);+ assert.doesNotMatch(lines[0], /enriched/); // hidden at readyCount 0+ assert.match(lines[0], /⚠ 4 stale/);+ assert.match(lines[1], /ctx 34%/);+ assert.match(lines[1], /last: pkce\.ts/);+});++test('syncing overrides stale; synced when clean', () => {+ const base = { ...emptyStats(), nodeCount: 1, edgeCount: 0, totalCount: 1 };+ assert.match(strip(renderStatusline({ ...base, syncing: true, dirty: true }, null, { ctxPct: null })[0]), /syncing/);+ assert.match(strip(renderStatusline(base, null, { ctxPct: null })[0]), /✓ synced/);+});