Skip to content

Commit 197939c

Browse files
Merge pull request #97 from microsoft/copilot/add-support-for-hooks
feat: Support Hooks as an Agent Primitive
2 parents e06ade0 + 3b64d2e commit 197939c

16 files changed

Lines changed: 2187 additions & 38 deletions

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ Skill registries install skills. APM manages **every primitive** your AI agents
5757
| **Skills** | AI capabilities, workflows | Form builder, code reviewer |
5858
| **Prompts** | Reusable slash commands | `/security-audit`, `/design-review` |
5959
| **Agents** | Specialized personas | Accessibility auditor, API designer |
60+
| **Hooks** | Lifecycle event handlers | Pre-tool validation, post-tool linting |
6061
| **MCP Servers** | Tool integrations | Database access, API connectors |
6162

6263
All declared in one manifest. All installed with one command — including transitive dependencies:
@@ -119,7 +120,8 @@ my-standards/
119120
├── instructions/ # Guardrails (.instructions.md)
120121
├── prompts/ # Slash commands (.prompt.md)
121122
├── skills/ # Agent Skills (SKILL.md)
122-
└── agents/ # Personas (.agent.md)
123+
├── agents/ # Personas (.agent.md)
124+
└── hooks/ # Event handlers (.json)
123125
```
124126

125127
Add a guardrail and publish:

docs/cli-reference.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ apm install --exclude codex
168168
- **Claude Skills**: Repositories with `SKILL.md` (auto-generates `apm.yml` upon installation)
169169
- Example: `apm install ComposioHQ/awesome-claude-skills/brand-guidelines`
170170
- Skills are transformed to `.github/agents/*.agent.md` for VSCode target
171+
- **Hook Packages**: Repositories with `hooks/*.json` (no `apm.yml` or `SKILL.md` required)
172+
- Example: `apm install anthropics/claude-plugins-official/plugins/hookify`
171173
- **Virtual Packages**: Single files or collections installed directly from URLs
172174
- Single `.prompt.md` or `.agent.md` files from any GitHub repository
173175
- Collections from curated sources (e.g., `github/awesome-copilot`)
@@ -215,6 +217,7 @@ When you run `apm install`, APM automatically integrates primitives from install
215217
- **Chatmodes**: `.chatmode.md` files → `.github/agents/*-apm.agent.md` (renamed to modern format)
216218
- **Control**: Disable with `apm config set auto-integrate false`
217219
- **Smart updates**: Only updates when package version/commit changes
220+
- **Hooks**: Hook `.json` files → `.github/hooks/*-apm.json` with scripts bundled
218221
- **Naming**: Integrated files use `-apm` suffix (e.g., `accessibility-audit-apm.prompt.md`)
219222
- **GitIgnore**: Pattern `*-apm.prompt.md` automatically added to `.gitignore`
220223

@@ -224,6 +227,7 @@ APM also integrates with Claude Code when `.claude/` directory exists:
224227

225228
- **Agents**: `.agent.md` and `.chatmode.md` files → `.claude/agents/*-apm.md`
226229
- **Commands**: `.prompt.md` files → `.claude/commands/*-apm.md`
230+
- **Hooks**: Hook definitions merged into `.claude/settings.json` hooks key
227231

228232
**Skill Integration:**
229233

@@ -278,6 +282,8 @@ apm uninstall microsoft/apm-sample-package --dry-run
278282
| Integrated chatmodes | `.github/agents/*-apm.agent.md` |
279283
| Claude commands | `.claude/commands/*-apm.md` |
280284
| Skill folders | `.github/skills/{folder-name}/` |
285+
| Integrated hooks | `.github/hooks/*-apm.json` |
286+
| Claude hook settings | `.claude/settings.json` (hooks key cleaned) |
281287
| Lockfile entries | `apm.lock` (removed packages + orphaned transitives) |
282288

283289
**Behavior:**

docs/compilation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ target: vscode # or claude, or all
4141
| `all` | Both `AGENTS.md` and `CLAUDE.md` | Universal compatibility |
4242
| `minimal` | `AGENTS.md` only | Works everywhere, no folder integration |
4343

44-
> **Note**: `AGENTS.md` and `CLAUDE.md` contain **only instructions** (grouped by `applyTo` patterns). Prompts, agents, commands, and skills are integrated by `apm install`, not `apm compile`. See the [Integrations Guide](integrations.md) for details on how `apm install` populates `.github/prompts/`, `.github/agents/`, `.github/skills/`, and `.claude/commands/`.
44+
> **Note**: `AGENTS.md` and `CLAUDE.md` contain **only instructions** (grouped by `applyTo` patterns). Prompts, agents, commands, hooks, and skills are integrated by `apm install`, not `apm compile`. See the [Integrations Guide](integrations.md) for details on how `apm install` populates `.github/prompts/`, `.github/agents/`, `.github/skills/`, and `.claude/commands/`.
4545

4646
### How It Works
4747

docs/concepts.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ Package your prompt engineering into reusable, configurable components:
157157
- **Agents** (.agent.md) - AI assistant personalities
158158
- **Skills** (SKILL.md) - Package meta-guides for AI agents
159159
- **Context** (.context.md) - Project knowledge base
160+
- **Hooks** (.json) - Lifecycle event handlers
160161

161162
### Layer 3: Context Engineering
162163

@@ -234,6 +235,20 @@ Optimized project knowledge for AI consumption:
234235
- Event-driven communication between services
235236
```
236237

238+
### Hooks (.json)
239+
Lifecycle event handlers that run scripts at specific points during AI operations:
240+
241+
```json
242+
{
243+
"hooks": {
244+
"PostToolUse": [{
245+
"matcher": { "tool_name": "write_file" },
246+
"hooks": [{ "type": "command", "command": "./scripts/lint.sh" }]
247+
}]
248+
}
249+
}
250+
```
251+
237252
## Universal Compatibility
238253

239254
APM generates context files for all major coding agents:

docs/dependencies.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ APM supports multiple dependency types:
1818
| Type | Detection | Example |
1919
|------|-----------|---------|
2020
| **APM Package** | Has `apm.yml` | `microsoft/apm-sample-package` |
21-
| **Claude Skill** | Has `SKILL.md` (no `apm.yml`) | `ComposioHQ/awesome-claude-skills/brand-guidelines` |
22-
| **Virtual Subdirectory Package** | Folder path in monorepo | `ComposioHQ/awesome-claude-skills/mcp-builder` |
21+
| **Claude Skill** | Has `SKILL.md` (no `apm.yml`) | `ComposioHQ/awesome-claude-skills/brand-guidelines` || **Hook Package** | Has `hooks/*.json` (no `apm.yml` or `SKILL.md`) | `anthropics/claude-plugins-official/plugins/hookify` || **Virtual Subdirectory Package** | Folder path in monorepo | `ComposioHQ/awesome-claude-skills/mcp-builder` |
2322
| **Virtual Subdirectory Package** | Folder path in repo | `github/awesome-copilot/skills/review-and-refactor` |
2423
| **ADO Package** | Azure DevOps repo | `dev.azure.com/org/project/_git/repo` |
2524

docs/integrations.md

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ apm install microsoft/apm-sample-package
152152

153153
# Agents are automatically integrated to:
154154
# .github/agents/*-apm.agent.md (verbatim copy)
155+
156+
# Hooks are automatically integrated to:
157+
# .github/hooks/*-apm.json (hook definitions with rewritten script paths)
155158
```
156159

157160
**How Auto-Integration Works**:
@@ -163,13 +166,14 @@ apm install microsoft/apm-sample-package
163166

164167
**Integration Flow**:
165168
1. Run `apm install` to fetch APM packages
166-
2. APM automatically creates `.github/prompts/` and `.github/agents/` directories if needed
167-
3. Discovers `.prompt.md` and `.agent.md` files in each package
169+
2. APM automatically creates `.github/prompts/`, `.github/agents/`, and `.github/hooks/` directories if needed
170+
3. Discovers `.prompt.md`, `.agent.md`, and hook `.json` files in each package
168171
4. Copies prompts to `.github/prompts/` with `-apm` suffix (e.g., `accessibility-audit-apm.prompt.md`)
169172
5. Copies agents to `.github/agents/` with `-apm` suffix (e.g., `security-apm.agent.md`)
170-
6. Updates `.gitignore` to exclude integrated prompts and agents
171-
7. VSCode automatically loads all prompts and agents for your coding agents
172-
8. Run `apm uninstall` to automatically remove integrated prompts and agents
173+
6. Copies hooks to `.github/hooks/` with `-apm` suffix (e.g., `hookify-hooks-apm.json`) and copies referenced scripts
174+
7. Updates `.gitignore` to exclude integrated prompts, agents, and hooks
175+
8. VSCode automatically loads all prompts, agents, and hooks for your coding agents
176+
9. Run `apm uninstall` to automatically remove integrated primitives
173177

174178
**Intent-First Discovery**:
175179
The `-apm` suffix pattern enables natural autocomplete in VSCode:
@@ -222,10 +226,11 @@ When you run `apm compile`, APM generates Claude-native files:
222226
When you run `apm install`, APM integrates package primitives into Claude's native structure:
223227

224228
| Location | Purpose |
225-
|----------|---------||
229+
|----------|---------|
226230
| `.claude/agents/*-apm.md` | Sub-agents from installed packages (from `.agent.md` files) |
227231
| `.claude/commands/*-apm.md` | Slash commands from installed packages (from `.prompt.md` files) |
228232
| `.claude/skills/{folder}/` | Skills from packages with `SKILL.md` or `.apm/` primitives |
233+
| `.claude/settings.json` (hooks key) | Hooks from installed packages (merged into settings) |
229234

230235
### Automatic Agent Integration
231236

@@ -286,6 +291,33 @@ apm install ComposioHQ/awesome-claude-skills/mcp-builder
286291
3. Updates `.gitignore` to exclude integrated skills
287292
4. `apm uninstall` removes the skill folder
288293

294+
### Automatic Hook Integration
295+
296+
APM automatically integrates hooks from installed packages. Hooks define lifecycle event handlers (e.g., `PreToolUse`, `PostToolUse`, `Stop`) supported by both VSCode Copilot and Claude Code.
297+
298+
> **Note:** Hook packages must be authored in the target platform's native format. APM handles path rewriting and file placement but does not translate between hook schema formats (e.g., Claude's `command` key vs GitHub Copilot's `bash`/`powershell` keys, or event name casing differences).
299+
300+
```bash
301+
# Install a package with hooks
302+
apm install anthropics/claude-plugins-official/plugins/hookify
303+
304+
# VSCode result (.github/hooks/):
305+
# .github/hooks/hookify-hooks-apm.json → Hook definitions
306+
# .github/hooks/scripts/hookify/hooks/*.py → Referenced scripts
307+
308+
# Claude result (.claude/settings.json):
309+
# Hooks merged into .claude/settings.json hooks key
310+
# Scripts copied to .claude/hooks/hookify/
311+
```
312+
313+
**How hook integration works:**
314+
1. `apm install` discovers hook JSON files in `.apm/hooks/` or `hooks/` directories
315+
2. For VSCode: copies hook JSON to `.github/hooks/` with `-apm` suffix and rewrites script paths
316+
3. For Claude: merges hook definitions into `.claude/settings.json` under the `hooks` key
317+
4. Copies referenced scripts to the target location
318+
5. Rewrites `${CLAUDE_PLUGIN_ROOT}` and relative script paths for the target platform
319+
6. `apm uninstall` removes hook files and cleans up merged settings
320+
289321
### Target-Specific Compilation
290322

291323
Generate only Claude formats when needed:

docs/primitives.md

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,13 @@ apm run review-copilot --param files="src/auth/"
6969

7070
## Overview
7171

72-
The APM CLI supports four types of primitives:
72+
The APM CLI supports the following types of primitives:
7373

7474
- **Agents** (`.agent.md`) - Define AI assistant personalities and behaviors (legacy: `.chatmode.md`)
7575
- **Instructions** (`.instructions.md`) - Provide coding standards and guidelines for specific file types
7676
- **Skills** (`SKILL.md`) - Package meta-guides that help AI agents understand what a package does
7777
- **Context** (`.context.md`, `.memory.md`) - Supply background information and project context
78+
- **Hooks** (`.json` in `.apm/hooks/` or `hooks/`) - Define lifecycle event handlers with script references
7879

7980
> **Note**: Both `.agent.md` (new format) and `.chatmode.md` (legacy format) are fully supported. VSCode provides Quick Fix actions to help migrate from `.chatmode.md` to `.agent.md`.
8081
@@ -95,8 +96,12 @@ APM discovers primitives in these locations:
9596
│ └── *.instructions.md
9697
├── context/ # Project context files
9798
│ └── *.context.md
98-
└── memory/ # Team info, contacts, etc.
99-
└── *.memory.md
99+
├── memory/ # Team info, contacts, etc.
100+
│ └── *.memory.md
101+
└── hooks/ # Lifecycle event handlers
102+
├── *.json # Hook definitions (JSON)
103+
└── scripts/ # Referenced scripts
104+
└── *.sh, *.py
100105
101106
# VSCode-compatible structure
102107
.github/
@@ -117,7 +122,7 @@ APM discovers primitives in these locations:
117122

118123
## Component Types Overview
119124

120-
Context implements the complete [AI-Native Development framework](https://danielmeppiel.github.io/awesome-ai-native/docs/concepts/) through four core component types:
125+
Context implements the complete [AI-Native Development framework](https://danielmeppiel.github.io/awesome-ai-native/docs/concepts/) through the following core component types:
121126

122127
### Instructions (.instructions.md)
123128
**Context Engineering Layer** - Targeted guidance by file type and domain
@@ -340,6 +345,38 @@ Team information (`.apm/memory/team-contacts.memory.md`):
340345
- Sprint planning: Mondays 2:00 PM PST
341346
```
342347

348+
### Hooks
349+
350+
Hooks define lifecycle event handlers that run scripts at specific points during AI agent operations (e.g., before/after tool use).
351+
352+
**Format:** `.json` files in `hooks/` or `.apm/hooks/`
353+
354+
**Structure:**
355+
```json
356+
{
357+
"hooks": {
358+
"PostToolUse": [
359+
{
360+
"matcher": { "tool_name": "write_file" },
361+
"hooks": [
362+
{
363+
"type": "command",
364+
"command": "./scripts/lint-changed.sh $TOOL_INPUT_path"
365+
}
366+
]
367+
}
368+
]
369+
}
370+
}
371+
```
372+
373+
**Supported Events:** `PreToolUse`, `PostToolUse`, `Stop`, `Notification`, `SubagentStop`
374+
375+
**Integration:**
376+
- VSCode: Hook JSON files are copied to `.github/hooks/*-apm.json` with script paths rewritten
377+
- Claude: Hooks are merged into `.claude/settings.json` under the `hooks` key
378+
- Scripts referenced by hooks are bundled alongside the hook definitions
379+
343380
## Discovery and Parsing
344381

345382
The APM CLI automatically discovers and parses all primitive files in your project.

docs/skills.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ APM automatically detects package types:
276276
|-----|------|-----------|
277277
| `apm.yml` only | APM Package | Standard APM primitives |
278278
| `SKILL.md` only | Claude Skill | Treated as native skill |
279+
| `hooks/*.json` only | Hook Package | Hook handlers only |
279280
| Both files | Hybrid Package | Best of both worlds |
280281

281282
## Target Detection

0 commit comments

Comments
 (0)