Skip to main content

Module session_start

Module session_start 

Source
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:

  1. Exports TRACEVAULT_SESSION_ID into Claude Code’s session env file (when present) so agent-invoked tracevault repo … commands can find the session without an explicit --session-id flag.
  2. Resolves the effective repo binding (workspace-mode precedence chain) and, if one exists, injects that repo’s policies as SessionStart additionalContext — 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 real CLAUDE_ENV_FILE env var. Creates the file if it doesn’t exist.