New to Claude Skills? Learn how to install them →

Cmicrosoft on GitHub

Create Hook

OfficialFree

Automate agent lifecycle events with custom hooks.

Get this skill

Free · Opens the source repo

What Create Hook does

The Create Hook skill allows developers to define custom hooks in JSON format to enforce specific policies or automate lifecycle events for AI agents. This skill is particularly useful for those looking to customize the behavior of their agents based on specific triggers, such as starting a session or using a particular tool. By creating hooks, users can block certain actions, inject context, or automate responses based on predefined conditions, enhancing the overall functionality and control of the agent.

To utilize this skill, users should begin by reviewing the conversation history to identify any concerns or requirements related to agent behavior. This involves generalizing user needs into actionable hooks, such as determining which actions should be blocked or what context should be injected at specific points in the workflow. The skill guides users through the process of drafting the necessary JSON configuration and companion scripts, ensuring that the hooks are tailored to their specific use cases.

The skill emphasizes the importance of following path conventions when creating hooks. Commands and scripts will run with the current working directory set to the workspace root or user home directory, depending on the context. This ensures that paths are resolved correctly, avoiding potential errors that could arise from improper path handling. Users are encouraged to iterate on their hook designs, refining them based on feedback and testing to ensure they meet the intended objectives.

Overall, the Create Hook skill is designed for developers and designers who want to exert greater control over their AI agents, allowing for tailored interactions and automated processes that align with their specific needs and policies.

When to use it

Use this skill when you need to implement specific policies or automate lifecycle events for your AI agents, especially when user concerns about agent behavior arise.

When not to use it

This skill may not be suitable for users who do not require customization of agent behavior or who are looking for out-of-the-box solutions without the need for configuration.

What you can build with it

Enforce Command Restrictions

Create a hook that blocks specific commands based on user input, preventing unintended actions.

Inject Context Automatically

Set up a hook to inject necessary context at the start of a session, enhancing the agent's responsiveness.

Automate Cleanup Tasks

Define a hook that runs cleanup scripts at the end of a session to maintain a tidy workspace.

How to install Create Hook

View source

1. Install with the skills CLI

npx skills add microsoft/vscode/create-hook --agent claude-code

2. Or install it manually

Download the skill folder and drop it into ~/.claude/skills/ for all projects, or .claude/skills/ to scope it to one repo. Restart Claude Code so it picks up the new skill.

Anthropic's agentic coding CLI, and the reference implementation of Agent Skills. Drop a skill folder into ~/.claude/skills and Claude Code loads it automatically whenever a task matches the skill's description. Claude Code docs

Inside SKILL.md

Written by microsoft

Related skill: agent-customization. Load and follow hooks.md for template and principles.

Guide the user to create a hook in .github/hooks/.

Extract from Conversation

First, review the conversation history. If the user has been expressing concerns about agent behavior (e.g., "don't run this command", "always check before doing X", "inject this context"), generalize that into a hook. Extract:

  • Actions that should be blocked or gated
  • Context that should be injected at certain points
  • Automation needs at session start/end or tool use

Clarify if Needed

If no clear policy need emerges from the conversation, clarify:

  • What event should trigger this hook? (e.g. PreToolUse, SessionStart, Stop)
  • Should it block, warn, or inject context?
  • Does it need a companion script?

Path Conventions

  • Hook commands and companion scripts run with cwd defaulting to the workspace root (when a workspace folder is available); otherwise cwd falls back to the user home directory. Relative paths resolve from cwd. Absolute paths are fine when intentional — just be deliberate about which you use.
  • Do not use environment variables for pathing. The only exception is plugin-provided environment variables in hooks shipped as part of an agent plugin; never use environment variables for pathing outside of a plugin context.

Iterate

  1. Draft the hook JSON (and any scripts) and save them.
  2. Identify the most ambiguous or weak parts and ask about those.
  3. Once finalized, summarize what the hook enforces, suggest ways to test it, and propose related customizations to create next.

Remember to follow the agent-customization guidelines to create highly effective hooks.

Frequently asked questions about Create Hook

Similar skills