Skip to main content

Module session_hooks

Module session_hooks 

Source
Expand description

Shared helpers for the SessionStart / UserPromptSubmit hook commands (sub-plan C): the Claude Code hook-output JSON shape for injecting context, the pure decision logic for when to inject, and the shared resolve-binding-then-inject flow used by both hook commands.

Structs§

HookOutput
Claude Code hook output. Field names are camelCase to match CC’s contract (the shared protocol HookResponse is snake_case and server-facing; this is the CLI-local shape used only for hook stdout).
HookSpecificOutput

Functions§

cap_context
Cap injected context. Oversize policy text is truncated to its first HEAD_LEN chars with a suffix pointing at tracevault repo status — unlike tracevault agent-policies, repo status works in workspace mode (no .tracevault/config.toml required), so the fallback is reachable in every install mode.
resolve_and_inject
Resolve the session’s effective binding and, if should_inject(event, ...), best-effort fetch + print policies as additionalContext and persist last_injected_repo. Always prints a valid HookOutput; never hard-fails.
should_inject
Whether to inject policies for this hook event.