Expand description
tracevault session-start — the Claude Code SessionStart hook.
Installed (sub-plan C) as the SessionStart hook for init --global. Runs
on every session start/resume and does these things, all best-effort:
- Exports
TRACEVAULT_SESSION_IDinto Claude Code’s session env file (when present) so agent-invokedtracevault repo …commands can find the session without an explicit--session-idflag. - Resolves the effective repo binding (workspace-mode precedence chain;
with none, binds the session from its checkout’s origin remote — see
auto_bind) and, if one exists, injects that repo’s policies asSessionStartadditionalContext— the reliable way to hand an agent up-to-date policy text at the start of a session. - Once per CLI upgrade, refreshes the installed hooks and turns telemetry
on (
upgrade, VIS-1109). - After its response is printed, sends the
cost-statereports earlier sessions of the repo left unsent (catch_up, VIS-1108).
This hook must NEVER hard-fail: a failing SessionStart hook blocks
Claude Code from starting the session. Every fallible step below is
handled internally, and the function always prints a valid HookOutput
JSON payload before returning Ok(()).
Functions§
- run
- write_
session_ env - Append
export TRACEVAULT_SESSION_ID='<session_id>'to the Claude Code session env file, unless that exact line is already present. Pure I/O helper factored out so it can be unit-tested without touching the realCLAUDE_ENV_FILEenv var. Creates the file if it doesn’t exist.