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): session-start orientation — inject graft/INDEX.md head
Shrish Dwivedibf2a4e5c7483
diff --git a/.claude/settings.json b/.claude/settings.jsonindex 74be35e7..cdba9c98 100644--- a/.claude/settings.json+++ b/.claude/settings.json@@ -25,6 +25,13 @@{ "type": "command", "command": "node \"${CLAUDE_PROJECT_DIR:-.}/.claude/helpers/graft-hooks.cjs\" prompt", "timeout": 8000 }]}+ ],+ "SessionStart": [+ {+ "hooks": [+ { "type": "command", "command": "node \"${CLAUDE_PROJECT_DIR:-.}/.claude/helpers/graft-hooks.cjs\" session-start", "timeout": 8000 }+ ]+ }]}}diff --git a/src/claude/format.ts b/src/claude/format.tsindex 12f09e0b..9ba2cd22 100644--- a/src/claude/format.ts+++ b/src/claude/format.ts@@ -87,3 +87,7 @@ export function formatRetrieval(ask: AskJson, cap = 5): string | null {});return `[graft] relevant context for this prompt:\n${lines.join('\n')}`;}++export function formatOrientation(indexMd: string, budgetBytes = 1500): string {+ return `[graft] repo map (graft/INDEX.md):\n${indexMd.slice(0, budgetBytes)}`;+}diff --git a/src/claude/hooks.ts b/src/claude/hooks.tsindex 4fd30f2c..3b790375 100644--- a/src/claude/hooks.ts+++ b/src/claude/hooks.ts@@ -2,7 +2,7 @@ import { readFileSync } from 'node:fs';import { execFileSync, spawn } from 'node:child_process';import { join, basename } from 'node:path';import { readWiring } from './stats.js';-import { formatBlastRadius, formatRetrieval } from './format.js';+import { formatBlastRadius, formatRetrieval, formatOrientation } from './format.js';import { patchStats, readStats, acquireLock, readSession, writeSession } from './state.js';function readStdin(): any {@@ -39,6 +39,14 @@ export async function main(event: string): Promise<void> {const input = readStdin();const dir = projectDir(input);+ if (event === 'session-start') {+ try {+ const idx = readFileSync(join(dir, 'graft', 'INDEX.md'), 'utf8');+ emit('SessionStart', formatOrientation(idx));+ } catch { /* no INDEX.md — skip */ }+ return;+ }+if (event === 'post-edit') {const file: string | undefined = input?.tool_input?.file_path;if (!file || underGraft(dir, file)) return;diff --git a/test/claude-format.test.ts b/test/claude-format.test.tsindex 59e70ae6..49c4d185 100644--- a/test/claude-format.test.ts+++ b/test/claude-format.test.ts@@ -1,6 +1,6 @@import { test } from 'node:test';import assert from 'node:assert/strict';-import { renderStatusline, enrichedSegment, incomingEdges, formatBlastRadius, formatRetrieval } from '../src/claude/format.js';+import { renderStatusline, enrichedSegment, incomingEdges, formatBlastRadius, formatRetrieval, formatOrientation } from '../src/claude/format.js';import { emptyStats } from '../src/claude/state.js';const strip = (s: string) => s.replace(/\x1b\[[0-9;]*m/g, '');@@ -76,3 +76,10 @@ test('formatRetrieval renders top hits, trims snippet, first pointer only', () =test('formatRetrieval returns null for no hits', () => {assert.equal(formatRetrieval({ query: 'x', mode: 'empty', hits: [] } as any), null);});++test('formatOrientation labels and truncates to budget', () => {+ const md = 'X'.repeat(3000);+ const out = strip(formatOrientation(md, 1500));+ assert.match(out, /repo map/);+ assert.ok(out.length < 1600, 'trimmed to budget + short header');+});