#6017: feat(hooks): add systemPrompt and tools to before_agent_start event
agents
Exposes the full assembled system prompt and available tools array in the `before_agent_start` plugin hook event. This enables monitoring and capture plugins to see the complete context sent to LLMs.
## Changes
- Add optional `systemPrompt` field (full prompt with injected files)
- Add optional `tools` field (sanitized tools array)
- No breaking changes (fields are optional)
## Use case
LLM monitoring plugins need to see the full context being sent to providers for observability, debugging, and capture purposes.
## Testing
- ✅ `pnpm tsgo` - TypeScript passes
- ✅ `pnpm format` - Formatting passes
- ✅ `pnpm lint` - No new errors
- ✅ `pnpm build` - Build passes
- ✅ `pnpm test` - 4922 tests passed
## AI Disclosure
- [x] AI-assisted contribution (Claude)
- [x] Fully tested locally (all checks pass)
- [x] We understand the changes: passing two existing variables (`appendPrompt` and `tools`) to the hook that already exists ~50 lines earlier in the same function
---
AI-assisted contribution 🤖
---
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR extends the `before_agent_start` plugin hook payload to include the fully assembled `systemPrompt` (with injected files) and a sanitized `tools` array (name/description/parameters) from the embedded runner. This enables monitoring/capture plugins to observe the full LLM invocation context without changing existing plugins, since the new fields are optional.
The change is localized to the embedded attempt runner where hooks are invoked and to the plugin type definitions that describe the event payload.
<h3>Confidence Score: 4/5</h3>
- This PR is generally safe to merge; it adds optional observability fields with minimal behavioral impact.
- Changes are additive and type-safe, but the current hook payload can include a messages snapshot that is later mutated (orphan user-message repair), which can mislead monitoring/capture plugins about the exact context actually sent to the provider.
- src/agents/pi-embedded-runner/run/attempt.ts (hook call ordering vs message repair)
<!-- greptile_other_comments_section -->
<sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub>
**Context used:**
- Context from `dashboard` - CLAUDE.md ([source](https://app.greptile.com/review/custom-context?memory=fd949e91-5c3a-4ab5-90a1-cbe184fd6ce8))
- Context from `dashboard` - AGENTS.md ([source](https://app.greptile.com/review/custom-context?memory=0d0c8278-ef8e-4d6c-ab21-f5527e322f13))
<!-- /greptile_comment -->
Most Similar PRs
#11921: feat(hooks): support systemPrompt injection in before_agent_start hook
by jungdaesuh · 2026-02-08
85.1%
#8178: feat: allow before_agent_start to override the prompt
by richardfogaca · 2026-02-03
84.5%
#14602: fix(plugins): hook systemPrompt gets collected then thrown away (#1...
by yinghaosang · 2026-02-12
83.7%
#14873: [Feature]: Extend before_agent_start hook context with Model, Tools...
by akv2011 · 2026-02-12
82.0%
#22705: fix(agents): merge before_agent_start hook systemPrompt into sessio...
by mushuiyu422 · 2026-02-21
80.7%
#11732: feat(plugins): add injectMessages to before_agent_start hook
by antra-tess · 2026-02-08
80.2%
#8022: feat: implement before_model_select plugin hook
by dead-pool-aka-wilson · 2026-02-03
78.7%
#9677: feat: expose incomingMessage in bootstrap hook context
by speedbal · 2026-02-05
78.7%
#7771: Hooks: wire lifecycle events and tests
by rabsef-bicrym · 2026-02-03
78.3%
#11124: feat(plugins): add before_llm_request hook for custom LLM headers
by johnlanni · 2026-02-07
78.1%