opensourceagi/qwksearch-research-agent/agent-runtime-hooks
Claude Code and agent skill by opensourceagi/qwksearch-research-agent
- community
- ext:[{"type":"hook","description":"Pre/post lifecycle hooks"}]
Checking that the SKILL.md file is still in the repository.
Agent runtime lifecycle hooks. Use for before/after tool or step hooks, tool mocks, human intervention, sub-agent calls, context compression, evals, callAgent, or lifecycle events.
Install
npx vskill@latest install opensourceagi/qwksearch-research-agent/agent-runtime-hooksSemi-extensibleMentions customization, but needs skill-specific knowledge. Read the extensible skills standard
SKILL.md
Agent Runtime Hooks
Lifecycle hooks for observing and intercepting agent execution. Hooks are registered per-operation via execAgent({ hooks }) and dispatched by HookDispatcher.
Hook Types
16 hook types across 5 categories:
Key Files
| File | Role | |
|---|---|---|
packages/agent-runtime/src/types/hooks.ts | Type definitions (AgentHookType, all event interfaces) | |
apps/server/src/services/agentRuntime/hooks/types.ts | Server-side types (AgentHook, re-exports) | |
apps/server/src/services/agentRuntime/hooks/HookDispatcher.ts | Registration, dispatch, dispatchBeforeToolCall | |
apps/server/src/modules/AgentRuntime/RuntimeExecutors.ts | Tool/Compact/HumanIntervention hook dispatch | |
apps/server/src/services/agentRuntime/AgentRuntimeService.ts | Step hooks + HumanIntervention resume/reject | |
apps/server/src/services/aiAgent/index.ts | CallAgent hook dispatch |
Registration Flow
Hook Reference
Step Level
`beforeStep` — Before each step. event: AgentHookEvent `afterStep` — After each step. event: AgentHookEvent (content, toolsCalling, totalCost, etc.) `onComplete` — Terminal state. event: AgentHookEvent (reason: done/error/interrupted/max\_steps/cost\_limit) `onError` — Error occurred. event: AgentHookEvent (errorMessage, errorDetail)
Tool Call Level
`beforeToolCall` — Before tool executes. Supports mocking via event.mock().
Dispatch method: hookDispatcher.dispatchBeforeToolCall() (returns mock result or null).
`afterToolCall` — After tool completes. Observation only.
`onToolCallError` — Tool threw an exception (catch block, not just success=false).
Human Intervention
`beforeHumanIntervention` — Before agent pauses for approval.
`afterHumanIntervention` — After approve/reject, agent resumes.
`onStopByHumanIntervention` — User rejected, agent halted.
Context Compression
`beforeCompact` — Before compression starts.
`afterCompact` — After compression completes.
`onCompactError` — Compression failed.
Sub-Agent (CallAgent)
`beforeCallAgent` — Before calling sub-agent. Dispatched on parent operation.
`afterCallAgent` — Sub-agent completed. Dispatched on parent operation.
`onCallAgentError` — Sub-agent failed. Dispatched on parent operation.
Note: CallAgent hooks require parentOperationId in ExecSubAgentTaskParams.
Design Notes
- Fire-and-forget: All handlers return
Promise<void>. Errors are non-fatal. - Exception:
beforeToolCallsupports mock viaevent.mock()— usesdispatchBeforeToolCall()which returns the mock result. - Sequential: Same-type hooks run in registration order.
- Local only:
beforeToolCallmock only works in local mode (in-memory hooks). Webhook mode does not support mocking. - Scoped per operation: Auto-cleaned via
hookDispatcher.unregister()on completion. - Sandbox/MCP: No separate hooks — they go through
executeTool, sobeforeToolCall/afterToolCallcover them. Useevent.identifierto filter.
Real-World Example: agent-evals
See devtools/agent-evals/helpers/runner.ts — createEvalHooks() uses afterStep, onComplete, afterToolCall, and beforeToolCall (for mock).
Security
- Security scanPassed, 90 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingapps/qwk-in-lobe/.agents/skills/agent-runtime-hooks/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Extension points
hookPre/post lifecycle hooks
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/opensourceagi/qwksearch-research-agent/agent-runtime-hooks)