feat(agent): add pre-execute hook event for context injection at bootstrap#123
Conversation
71 sessions distilled (glm-5.1); 2→68 guides, citations verbatim-anchored. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…strap Add `PreExecute` to `HookEvent`, `fire_pre_execute` to `ProjectHooksRunner`, and a call site at the end of agent bootstrap. Hooks subscribed to `pre-execute` fire once before the first LLM call; their stdout is appended to the system prompt. Non-zero exit is logged and ignored. The stdin payload matches the Claude Code UserPromptSubmit schema (`session_id`, `cwd`, `transcript_path: null`, `prompt`) so tools like `proactive-context inject` work without adaptation. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Code ReviewOverviewThis PR adds a Core Code Changes
The integration is minimal and correct. Cloning // This comment explains a non-obvious borrow constraint — appropriate per CLAUDE.md
let hooks_for_bootstrap = project_hooks.clone();One nit:
The new Issues1. Multi-line doc comments violate CLAUDE.mdCLAUDE.md is explicit: "Never write multi-paragraph docstrings or multi-line comment blocks — one short line max." The PR adds three violations: /// Fires once at agent bootstrap, before the first LLM call. Stdout is
/// injected into the system prompt. Non-zero exit is logged and ignored
/// (the agent still runs).
PreExecute,/// Fire every `pre-execute` hook once at agent bootstrap. Non-zero exit is
/// logged and ignored — the agent still runs. Stdout on exit 0 is collected
/// and returned for injection into the system prompt.
pub async fn fire_pre_execute(&self) -> Vec<String> {/// Build the `pre-execute` stdin payload. Matches the Claude Code
/// `UserPromptSubmit` hook schema so tools like `proactive-context inject`
/// work without adaptation.
fn pre_execute_stdin(&self) -> String {Each of these should be collapsed to a single line. The wiki entry 2. No automated test coverageThe PR description notes "Verified live against DDD project" but there are no automated tests for the new path. The
There is no 3. Wiki dump bundled with functional change69 auto-generated wiki files (2200+ of 2275 additions) are mixed into this PR alongside the functional change. The Design / Correctness
SummaryThe functional change is correct and minimal. Two things need fixing before merge:
The wiki dump should be a separate commit or PR. 🤖 Generated with Claude Code |
Resolved conflict over where pre-execute hook injections land: master's approach (turn_reminders → user message as a system-reminder block) is correct because the system prompt must remain byte-stable for prompt-cache hits. System-prompt mutation (the PR's original approach) is discarded. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Code ReviewPR: feat(agent): add pre-execute hook event for context injection at bootstrap OverviewThis PR has two distinct components:
The PR description claims it adds Code Quality (
|
| Area | Verdict |
|---|---|
project_hooks.rs code changes |
✅ Clean |
pre-execute hook design |
✅ Sound (with kill_on_drop caveat) |
| Wiki: off-topic content | ❌ iOS/podcast entries don't belong here |
| Wiki: date inconsistency | e2e-probe-validation.md created > updated |
| Wiki: contradictory MCP entries | |
| Gap between PR description and diff | fire_pre_execute + agent_bootstrap changes are on master |
🤖 Generated with Claude Code
Summary
Adds
pre-executeas a third hook event alongsidepre-toolandpost-tool. A hook subscribed topre-executefires once at agent bootstrap, before the first LLM call; its stdout is appended to the system prompt.This wires up the
proactive-context injectpath — hooks configured in.tenex-hooks.jsonwithevents: ["pre-execute"]now inject wiki-sourced project context directly into the agent's system prompt on every invocation.The stdin payload matches the Claude Code
UserPromptSubmithook schema (session_id,cwd,transcript_path: null,prompt) soproactive-context injectand any other Claude Code-compatible inject hook works without adaptation.Non-zero exit from a
pre-executehook is logged and the agent continues — a failing inject hook must never block the agent.Changes
project_hooks.rs:HookEvent::PreExecutevariant,fire_pre_executemethod,pre_execute_stdinbuilder,"pre-execute"in config parseragent_bootstrap/mod.rs: clone hooks runner before move, callfire_pre_executeand append results tosystem_promptafter all other remindersTest
Verified live against DDD project with
.tenex-hooks.jsonwired toproactive-context inject:writing-styleguide selected and compiled →<system-reminder>with cited line references injected into system prompt🤖 Generated with Claude Code