🪝 VS Code Agent Hooks: Give Copilot Context Before the First Message
VS Code Agent Hooks allow developers to automatically run scripts at specific lifecycle events to provide dynamic context to AI agents before and during sessions. The post demonstrates how to use SessionStart and PreCompact hooks to ask onboarding questions, store answers, and reinject context when conversations are compacted, enabling agents to adapt their behavior based on project type, technology stack, and experience level.

post Gerardo Rentería Blog
"Agent Hooks allow you to automatically run code at specific points in the agent lifecycle, before the user types anything."
Key points
- Agent hooks are commands or scripts that VS Code runs at eight lifecycle events, receiving event data as JSON and replying with JSON to steer the agent.
- Hook definitions are JSON files placed in .github/hooks and load automatically with no extra configuration.
- A SessionStart hook runs once per new session and has the agent ask about stack, experience level and project type, then save the answers to a JSONL file.
- Markdown profiles for junior, mid and senior developers adjust agent behavior based on the onboarding answers.
- A PreCompact hook reads the saved answers and active profile before conversation compaction and reinjects them so context is not lost.
Quotes
- “Agent Hooks allow you to automatically run code at specific points in the agent lifecycle, before the user types anything.” (This is the core capability that enables automation of context setup without manual intervention on every session.)
- “Hooks don’t replace instructions or custom prompts; instead, they provide dynamic runtime context.” (Clarifies the complementary role of hooks within the broader system of agent customization.)
Context
- Features: SessionStart hook, PreCompact hook, agent lifecycle events, dynamic context injection, profile-based behavior, JSONL logging, PowerShell script execution
Source: Gerardo Renteria, community blog. Summary, key points and quotes are derived (CONTENT-NOTICE.md); read the original for the full text.