---
id: post/gerardorenteria-blog/14522
type: post
title: "🪝 VS Code Agent Hooks: Give Copilot Context Before the First Message"
summary: 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.
tier: community
language: en
tags:
  - vs code
  - agent hooks
  - copilot context
  - onboarding
  - session management
  - dynamic prompts
system: development
review:
  state: reviewed
  by: opus
  at: "2026-10-08T01:55:25.710Z"
  flags: []
generated:
  at: "2026-10-08T01:26:53.141Z"
  pipeline: 0.2.0
  prompts:
    extract-post: 1
  input_hash: 045b3ed709046668e498c1834fbe45ca459a7cc5ce397d539b57714b30c03401
evidence:
  - kind: blog
    url: https://gerardorenteria.blog/2026/05/03/%f0%9f%aa%9d-vs-code-agent-hooks-give-copilot-context-before-the-first-message/
    title: "🪝 VS Code Agent Hooks: Give Copilot Context Before the First Message"
    date: "2026-05-03"
    commit: null
    t: null
    quote: null
  - kind: blog
    url: https://gerardorenteria.blog/2026/05/03/%f0%9f%aa%9d-vs-code-agent-hooks-give-copilot-context-before-the-first-message/
    title: "🪝 VS Code Agent Hooks: Give Copilot Context Before the First Message"
    date: "2026-05-03"
    commit: null
    t: null
    quote: Agent Hooks allow you to automatically run code at specific points in the agent lifecycle, before the user types anything.
  - kind: blog
    url: https://gerardorenteria.blog/2026/05/03/%f0%9f%aa%9d-vs-code-agent-hooks-give-copilot-context-before-the-first-message/
    title: "🪝 VS Code Agent Hooks: Give Copilot Context Before the First Message"
    date: "2026-05-03"
    commit: null
    t: null
    quote: Hooks don't replace instructions or custom prompts; instead, they provide dynamic runtime context.
links:
  learn: []
  objects: []
  features: []
  topics: []
  localizations: []
  videos: []
  posts: []
  guidelines: []
post_id: "14522"
source_id: gerardorenteria-blog
source_name: Gerardo Renteria
url: https://gerardorenteria.blog/2026/05/03/%f0%9f%aa%9d-vs-code-agent-hooks-give-copilot-context-before-the-first-message/
published_at: "2026-05-03T16:10:32.000Z"
author: Gerardo Renteria
full_text: false
words: 1951
quotes:
  - text: Agent Hooks allow you to automatically run code at specific points in the agent lifecycle, before the user types anything.
    why_it_matters: This is the core capability that enables automation of context setup without manual intervention on every session.
  - text: Hooks don't replace instructions or custom prompts; instead, they provide dynamic runtime context.
    why_it_matters: Clarifies the complementary role of hooks within the broader system of agent customization.
code_objects_mentioned: []
systems:
  - development
  - copilot
versions_mentioned: []
preview:
  embeddable: true
  frame_url: https://gerardorenteria.blog/2026/05/03/%f0%9f%aa%9d-vs-code-agent-hooks-give-copilot-context-before-the-first-message/embed/
  image: https://gerardorenteria.blog/wp-content/uploads/2026/05/designer-2.png
  image_alt: null
  image_w: 1024
  image_h: 1024
  site_name: Gerardo Rentería Blog
  favicon: https://gerardorenteria.blog/wp-content/uploads/2020/11/cropped-wolficon.jpg?w=32
  probed_at: "2026-10-07T11:50:46.463Z"
---

# 🪝 VS Code Agent Hooks: Give Copilot Context Before the First Message

[Read the post](https://gerardorenteria.blog/2026/05/03/%f0%9f%aa%9d-vs-code-agent-hooks-give-copilot-context-before-the-first-message/) · Gerardo Renteria (Gerardo Renteria) · 2026-05-03 · 1951 words · tier community · reviewed (checked by Opus)

> 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.

## 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.
