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 two things, both 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)
and, if one exists, injects that repo’s policies as
SessionStartadditionalContext— the reliable way to hand an agent up-to-date policy text at the start of a session.
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.