Skip to content

Commit 264649b

Browse files
big-guyclaude
andcommitted
hooks(claude): register SessionStart hook
Add SessionStart to the Claude status plugin's hook set, mirroring Codex. A freshly started/resumed session derives to 'waiting', and its payload carries session_id so the generic discovery in tailLog picks up the session ID before the first prompt. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 8ae0f72 commit 264649b

5 files changed

Lines changed: 19 additions & 0 deletions

File tree

resources/plugins/harness-status/hooks/hooks.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
{
22
"hooks": {
3+
"SessionStart": [
4+
{
5+
"hooks": [
6+
{
7+
"type": "command",
8+
"command": "bash -c 'h=\"$HARNESS_TERMINAL_ID\"; [ -z \"$h\" ] && h=\"$CLAUDE_HARNESS_ID\"; [ -z \"$h\" ] && exit 0; d=/tmp/harness-status; mkdir -p \"$d\"; p=$(cat); [ -z \"$p\" ] && p=null; printf \"{\\\"event\\\":\\\"SessionStart\\\",\\\"ts\\\":%s,\\\"payload\\\":%s}\\n\" \"$(date +%s)\" \"$p\" >> \"$d/$h.ndjson\"'",
9+
"timeout": 5
10+
}
11+
]
12+
}
13+
],
314
"UserPromptSubmit": [
415
{
516
"hooks": [

src/main/agents/claude.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ describe('stripGlobalHooks (legacy migration)', () => {
158158
describe('hookEvents', () => {
159159
it('exports the events the bundled plugin must register', () => {
160160
expect(hookEvents).toEqual([
161+
'SessionStart',
161162
'UserPromptSubmit',
162163
'PreToolUse',
163164
'PostToolUse',

src/main/agents/claude.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export const defaultCommand = 'claude'
1515
export const assignsSessionId = true
1616

1717
export const hookEvents = [
18+
'SessionStart',
1819
'UserPromptSubmit',
1920
'PreToolUse',
2021
'PostToolUse',

src/main/claude-plugin.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { join } from 'path'
1010
import { makeHookCommand } from './hooks'
1111

1212
const HOOK_EVENTS = [
13+
'SessionStart',
1314
'UserPromptSubmit',
1415
'PreToolUse',
1516
'PostToolUse',

src/main/hooks.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ function readPendingTool(p: Record<string, unknown> | null): PendingTool | null
7979

8080
function deriveStatus(terminalId: string, ev: HookEvent): StatusUpdate | null {
8181
switch (ev.event) {
82+
case 'SessionStart':
83+
// Fires when a session starts or resumes. Nothing is running yet, so
84+
// the tab is idle. Its payload also carries session_id, which the
85+
// generic discovery in tailLog picks up before the first prompt.
86+
return { status: 'waiting', pendingTool: null }
8287
case 'PreToolUse': {
8388
const tool = readPendingTool(ev.payload)
8489
if (tool) lastPreTool.set(terminalId, tool)

0 commit comments

Comments
 (0)