cmdHookSessionStart emits a Claude Code SessionStart hook response. Wired via ~/.claude/settings.json with a matcher of "startup|resume" so it fires for both fresh spawns and `claude --resume`. Two modes, branching on whether this session is bound to a flow task. The binding is discovered via rever
(args []string)
| 52 | } |
| 53 | } |
| 54 | |
| 55 | // cmdHookSessionStart emits a Claude Code SessionStart hook response. |
| 56 | // Wired via ~/.claude/settings.json with a matcher of "startup|resume" |
| 57 | // so it fires for both fresh spawns and `claude --resume`. |
| 58 | // |
| 59 | // Two modes, branching on whether this session is bound to a flow |
| 60 | // task. The binding is discovered via reverse-lookup on the |
| 61 | // $CLAUDE_CODE_SESSION_ID env var (Claude Code injects this into |
| 62 | // every session) against tasks.session_id: |
| 63 | // - Bound (a task carries this session_id): emit the full |
| 64 | // task-context reload instructions. On a fresh spawn this is |
| 65 | // redundant with the bootstrap prompt but harmless; on a resume |
| 66 | // it's the only way to force the agent to re-read potentially- |
| 67 | // updated briefs and updates. |
| 68 | // - Unbound (no task carries it, or env var missing): emit the |
| 69 | // ambient skill hint so Claude knows the flow skill is available. |
| 70 | func cmdHookSessionStart(args []string) int { |
| 71 | fs := flagSet("hook session-start") |
| 72 | if err := fs.Parse(args); err != nil { |
| 73 | return 2 |
| 74 | } |
| 75 | |
| 76 | slug := lookupBoundTaskSlug() |
| 77 | if slug == "" { |
| 78 | // Unbound sessions are where the human usually sits — surface |
| 79 | // their pending-mail count here too (inform-only). |
| 80 | return emitAmbientSkillHint() |
| 81 | } |
| 82 | pageCtx := busSessionStartContext() |
| 83 | |
| 84 | instructions := fmt.Sprintf( |
| 85 | "You are running inside a flow execution session for task %q. "+ |
| 86 | "Before doing anything else in this turn, re-load your task context — "+ |
| 87 | "the brief and update files may have been edited since your previous "+ |
| 88 | "session. Do these in order: "+ |
| 89 | "(1) invoke the `flow` skill via the Skill tool. That skill is your "+ |
| 90 | "operating manual for this session: it defines the bootstrap contract, "+ |
| 91 | "the workflows for starting/saving/logging/archiving work, KB scoop "+ |
| 92 | "discipline, and the scope-creep detection that keeps unrelated work "+ |
| 93 | "from landing in the wrong task. "+ |
| 94 | "(2) run `flow show task` and use your Read tool on the file at the "+ |
| 95 | "`brief:` path AND every file listed under `updates:`; "+ |
| 96 | "(3) if a project is listed on the task, run `flow show project <that-slug>` "+ |
| 97 | "and Read its brief and updates too; "+ |
| 98 | "(4) Read `CLAUDE.md` in your work_dir and any nested CLAUDE.md under "+ |