Skip to content

Commit 4555fee

Browse files
authored
Merge pull request #685 from github/hooks
Hooks
2 parents 738bafc + e80e20b commit 4555fee

23 files changed

+1230
-64
lines changed

AGENTS.md

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ The Awesome GitHub Copilot repository is a community-driven collection of custom
88
- **Prompts** - Task-specific prompts for code generation and problem-solving
99
- **Instructions** - Coding standards and best practices applied to specific file patterns
1010
- **Skills** - Self-contained folders with instructions and bundled resources for specialized tasks
11+
- **Hooks** - Automated workflows triggered by specific events during development
1112
- **Collections** - Curated collections organized around specific themes and workflows
1213

1314
## Repository Structure
@@ -18,6 +19,7 @@ The Awesome GitHub Copilot repository is a community-driven collection of custom
1819
├── prompts/ # Task-specific prompts (.prompt.md files)
1920
├── instructions/ # Coding standards and guidelines (.instructions.md files)
2021
├── skills/ # Agent Skills folders (each with SKILL.md and optional bundled assets)
22+
├── hooks/ # Automated workflow hooks (folders with README.md + hooks.json)
2123
├── collections/ # Curated collections of resources (.md files)
2224
├── docs/ # Documentation for different resource types
2325
├── eng/ # Build and automation scripts
@@ -48,9 +50,9 @@ npm run skill:create -- --name <skill-name>
4850

4951
## Development Workflow
5052

51-
### Working with Agents, Prompts, Instructions, and Skills
53+
### Working with Agents, Prompts, Instructions, Skills, and Hooks
5254

53-
All agent files (`*.agent.md`), prompt files (`*.prompt.md`), and instruction files (`*.instructions.md`) must include proper markdown front matter. Agent Skills are folders containing a `SKILL.md` file with frontmatter and optional bundled assets:
55+
All agent files (`*.agent.md`), prompt files (`*.prompt.md`), and instruction files (`*.instructions.md`) must include proper markdown front matter. Agent Skills are folders containing a `SKILL.md` file with frontmatter and optional bundled assets. Hooks are folders containing a `README.md` with frontmatter and a `hooks.json` configuration file:
5456

5557
#### Agent Files (*.agent.md)
5658
- Must have `description` field (wrapped in single quotes)
@@ -80,16 +82,37 @@ All agent files (`*.agent.md`), prompt files (`*.prompt.md`), and instruction fi
8082
- Asset files should be reasonably sized (under 5MB per file)
8183
- Skills follow the [Agent Skills specification](https://agentskills.io/specification)
8284

85+
#### Hook Folders (hooks/*/README.md)
86+
- Each hook is a folder containing a `README.md` file with frontmatter
87+
- README.md must have `name` field (human-readable name)
88+
- README.md must have `description` field (wrapped in single quotes, not empty)
89+
- Must include a `hooks.json` file with hook configuration (hook events extracted from this file)
90+
- Folder names should be lower case with words separated by hyphens
91+
- Can include bundled assets (scripts, utilities, configuration files)
92+
- Bundled scripts should be referenced in the README.md and hooks.json
93+
- Follow the [GitHub Copilot hooks specification](https://docs.github.com/en/copilot/how-tos/use-copilot-agents/coding-agent/use-hooks)
94+
- Optionally includes `tags` field for categorization
95+
8396
### Adding New Resources
8497

85-
When adding a new agent, prompt, instruction, or skill:
98+
When adding a new agent, prompt, instruction, skill, or hook:
8699

87100
**For Agents, Prompts, and Instructions:**
88101
1. Create the file with proper front matter
89102
2. Add the file to the appropriate directory
90103
3. Update the README.md by running: `npm run build`
91104
4. Verify the resource appears in the generated README
92105

106+
**For Hooks:**
107+
1. Create a new folder in `hooks/` with a descriptive name
108+
2. Create `README.md` with proper frontmatter (name, description, hooks, tags)
109+
3. Create `hooks.json` with hook configuration following GitHub Copilot hooks spec
110+
4. Add any bundled scripts or assets to the folder
111+
5. Make scripts executable: `chmod +x script.sh`
112+
6. Update the README.md by running: `npm run build`
113+
7. Verify the hook appears in the generated README
114+
115+
93116
**For Skills:**
94117
1. Run `npm run skill:create` to scaffold a new skill folder
95118
2. Edit the generated SKILL.md file with your instructions
@@ -186,6 +209,16 @@ For skills (skills/*/):
186209
- [ ] Any bundled assets are referenced in SKILL.md
187210
- [ ] Bundled assets are under 5MB per file
188211

212+
For hook folders (hooks/*/):
213+
- [ ] Folder contains a README.md file with markdown front matter
214+
- [ ] Has `name` field with human-readable name
215+
- [ ] Has non-empty `description` field wrapped in single quotes
216+
- [ ] Has `hooks.json` file with valid hook configuration (hook events extracted from this file)
217+
- [ ] Folder name is lower case with hyphens
218+
- [ ] Any bundled scripts are executable and referenced in README.md
219+
- [ ] Follows [GitHub Copilot hooks specification](https://docs.github.com/en/copilot/how-tos/use-copilot-agents/coding-agent/use-hooks)
220+
- [ ] Optionally includes `tags` array field for categorization
221+
189222
## Contributing
190223

191224
This is a community-driven project. Contributions are welcome! Please see:

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ This repository provides a comprehensive toolkit for enhancing GitHub Copilot wi
1111
- **👉 [Awesome Agents](docs/README.agents.md)** - Specialized GitHub Copilot agents that integrate with MCP servers to provide enhanced capabilities for specific workflows and tools
1212
- **👉 [Awesome Prompts](docs/README.prompts.md)** - Focused, task-specific prompts for generating code, documentation, and solving specific problems
1313
- **👉 [Awesome Instructions](docs/README.instructions.md)** - Comprehensive coding standards and best practices that apply to specific file patterns or entire projects
14+
- **👉 [Awesome Hooks](docs/README.hooks.md)** - Automated workflows triggered by specific events during development, testing, and deployment
1415
- **👉 [Awesome Skills](docs/README.skills.md)** - Self-contained folders with instructions and bundled resources that enhance AI capabilities for specialized tasks
1516
- **👉 [Awesome Collections](docs/README.collections.md)** - Curated collections of related prompts, instructions, agents, and skills organized around specific themes and workflows
1617
- **👉 [Awesome Cookbook Recipes](cookbook/README.md)** - Practical, copy-paste-ready code snippets and real-world examples for working with GitHub Copilot tools and features
@@ -96,6 +97,10 @@ Use the `/` command in GitHub Copilot Chat to access prompts:
9697

9798
Instructions automatically apply to files based on their patterns and provide contextual guidance for coding standards, frameworks, and best practices.
9899

100+
### 🪝 Hooks
101+
102+
Hooks enable automated workflows triggered by specific events during GitHub Copilot coding agent sessions (like sessionStart, sessionEnd, userPromptSubmitted). They can automate tasks like logging, auto-committing changes, or integrating with external services.
103+
99104
## 🎯 Why Use Awesome GitHub Copilot?
100105

101106
- **Productivity**: Pre-built agents, prompts and instructions save time and provide consistent results.
@@ -107,7 +112,7 @@ Instructions automatically apply to files based on their patterns and provide co
107112

108113
We welcome contributions! Please see our [Contributing Guidelines](CONTRIBUTING.md) for details on how to:
109114

110-
- Add new prompts, instructions, agents, or skills
115+
- Add new prompts, instructions, hooks, agents, or skills
111116
- Improve existing content
112117
- Report issues or suggest enhancements
113118

@@ -148,7 +153,7 @@ The customizations in this repository are sourced from and created by third-part
148153

149154
---
150155

151-
**Ready to supercharge your coding experience?** Start exploring our [prompts](docs/README.prompts.md), [instructions](docs/README.instructions.md), and [custom agents](docs/README.agents.md)!
156+
**Ready to supercharge your coding experience?** Start exploring our [prompts](docs/README.prompts.md), [instructions](docs/README.instructions.md), [hooks](docs/README.hooks.md), and [custom agents](docs/README.agents.md)!
152157

153158
## Contributors ✨
154159

docs/README.hooks.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# 🪝 Hooks
2+
3+
Hooks enable automated workflows triggered by specific events during GitHub Copilot coding agent sessions, such as session start, session end, user prompts, and tool usage.
4+
### How to Use Hooks
5+
6+
**What's Included:**
7+
- Each hook is a folder containing a `README.md` file and a `hooks.json` configuration
8+
- Hooks may include helper scripts, utilities, or other bundled assets
9+
- Hooks follow the [GitHub Copilot hooks specification](https://docs.github.com/en/copilot/how-tos/use-copilot-agents/coding-agent/use-hooks)
10+
11+
**To Install:**
12+
- Copy the hook folder to your repository's `.github/hooks/` directory
13+
- Ensure any bundled scripts are executable (`chmod +x script.sh`)
14+
- Commit the hook to your repository's default branch
15+
16+
**To Activate/Use:**
17+
- Hooks automatically execute during Copilot coding agent sessions
18+
- Configure hook events in the `hooks.json` file
19+
- Available events: `sessionStart`, `sessionEnd`, `userPromptSubmitted`, `preToolUse`, `postToolUse`, `errorOccurred`
20+
21+
**When to Use:**
22+
- Automate session logging and audit trails
23+
- Auto-commit changes at session end
24+
- Track usage analytics
25+
- Integrate with external tools and services
26+
- Custom session workflows
27+
28+
| Name | Description | Events | Bundled Assets |
29+
| ---- | ----------- | ------ | -------------- |
30+
| [Session Auto-Commit](../hooks/session-auto-commit/README.md) | Automatically commits and pushes changes when a Copilot coding agent session ends | sessionEnd | `auto-commit.sh`<br />`hooks.json` |
31+
| [Session Logger](../hooks/session-logger/README.md) | Logs all Copilot coding agent session activity for audit and analysis | sessionStart, sessionEnd, userPromptSubmitted | `hooks.json`<br />`log-prompt.sh`<br />`log-session-end.sh`<br />`log-session-start.sh` |

eng/collection-to-plugin.mjs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ import fs from "fs";
44
import path from "path";
55
import readline from "readline";
66
import { COLLECTIONS_DIR, ROOT_FOLDER } from "./constants.mjs";
7-
import { parseCollectionYaml, parseFrontmatter } from "./yaml-parser.mjs";
7+
import {
8+
parseCollectionYaml,
9+
parseFrontmatter,
10+
parseHookMetadata,
11+
} from "./yaml-parser.mjs";
812

913
const PLUGINS_DIR = path.join(ROOT_FOLDER, "plugins");
1014

@@ -158,6 +162,12 @@ function getDisplayName(filePath, kind) {
158162
return basename.replace(".agent.md", "");
159163
} else if (kind === "instruction") {
160164
return basename.replace(".instructions.md", "");
165+
} else if (kind === "hook") {
166+
// For folder-based hooks like hooks/<hook>/README.md, use the folder name.
167+
if (basename.toLowerCase() === "readme.md") {
168+
return path.basename(path.dirname(filePath));
169+
}
170+
return basename.replace(".hook.md", "");
161171
} else if (kind === "skill") {
162172
return path.basename(filePath);
163173
}
@@ -221,6 +231,27 @@ function generateReadme(collection, items) {
221231
lines.push("");
222232
}
223233

234+
// Hooks
235+
const hooks = items.filter((item) => item.kind === "hook");
236+
if (hooks.length > 0) {
237+
lines.push("### Hooks");
238+
lines.push("");
239+
lines.push("| Hook | Description | Event |");
240+
lines.push("|------|-------------|-------|");
241+
for (const item of hooks) {
242+
const name = getDisplayName(item.path, "hook");
243+
const description =
244+
item.frontmatter?.description || item.frontmatter?.name || name;
245+
// Extract events from hooks.json rather than frontmatter
246+
const hookFolderPath = path.join(ROOT_FOLDER, path.dirname(item.path));
247+
const hookMeta = parseHookMetadata(hookFolderPath);
248+
const event =
249+
hookMeta?.hooks?.length > 0 ? hookMeta.hooks.join(", ") : "N/A";
250+
lines.push(`| \`${name}\` | ${description} | ${event} |`);
251+
}
252+
lines.push("");
253+
}
254+
224255
// Skills
225256
const skills = items.filter((item) => item.kind === "skill");
226257
if (skills.length > 0) {

eng/constants.mjs

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import path from "path";
1+
import path, { dirname } from "path";
22
import { fileURLToPath } from "url";
3-
import { dirname } from "path";
43

54
const __filename = fileURLToPath(import.meta.url);
65
const __dirname = dirname(__filename);
@@ -100,6 +99,34 @@ Skills differ from other primitives by supporting bundled assets (scripts, code
10099
- Browse the skills table below to find relevant capabilities
101100
- Copy the skill folder to your local skills directory
102101
- Reference skills in your prompts or let the agent discover them automatically`,
102+
103+
hooksSection: `## 🪝 Hooks
104+
105+
Hooks enable automated workflows triggered by specific events during GitHub Copilot coding agent sessions, such as session start, session end, user prompts, and tool usage.`,
106+
107+
hooksUsage: `### How to Use Hooks
108+
109+
**What's Included:**
110+
- Each hook is a folder containing a \`README.md\` file and a \`hooks.json\` configuration
111+
- Hooks may include helper scripts, utilities, or other bundled assets
112+
- Hooks follow the [GitHub Copilot hooks specification](https://docs.github.com/en/copilot/how-tos/use-copilot-agents/coding-agent/use-hooks)
113+
114+
**To Install:**
115+
- Copy the hook folder to your repository's \`.github/hooks/\` directory
116+
- Ensure any bundled scripts are executable (\`chmod +x script.sh\`)
117+
- Commit the hook to your repository's default branch
118+
119+
**To Activate/Use:**
120+
- Hooks automatically execute during Copilot coding agent sessions
121+
- Configure hook events in the \`hooks.json\` file
122+
- Available events: \`sessionStart\`, \`sessionEnd\`, \`userPromptSubmitted\`, \`preToolUse\`, \`postToolUse\`, \`errorOccurred\`
123+
124+
**When to Use:**
125+
- Automate session logging and audit trails
126+
- Auto-commit changes at session end
127+
- Track usage analytics
128+
- Integrate with external tools and services
129+
- Custom session workflows`,
103130
};
104131

105132
const vscodeInstallImage =
@@ -115,13 +142,15 @@ const AKA_INSTALL_URLS = {
115142
instructions: "https://aka.ms/awesome-copilot/install/instructions",
116143
prompt: "https://aka.ms/awesome-copilot/install/prompt",
117144
agent: "https://aka.ms/awesome-copilot/install/agent",
145+
hook: "https://aka.ms/awesome-copilot/install/hook",
118146
};
119147

120148
const ROOT_FOLDER = path.join(__dirname, "..");
121149
const INSTRUCTIONS_DIR = path.join(ROOT_FOLDER, "instructions");
122150
const PROMPTS_DIR = path.join(ROOT_FOLDER, "prompts");
123151
const AGENTS_DIR = path.join(ROOT_FOLDER, "agents");
124152
const SKILLS_DIR = path.join(ROOT_FOLDER, "skills");
153+
const HOOKS_DIR = path.join(ROOT_FOLDER, "hooks");
125154
const COLLECTIONS_DIR = path.join(ROOT_FOLDER, "collections");
126155
const COOKBOOK_DIR = path.join(ROOT_FOLDER, "cookbook");
127156
const MAX_COLLECTION_ITEMS = 50;
@@ -135,23 +164,24 @@ const SKILL_DESCRIPTION_MAX_LENGTH = 1024;
135164
const DOCS_DIR = path.join(ROOT_FOLDER, "docs");
136165

137166
export {
138-
TEMPLATES,
139-
vscodeInstallImage,
140-
vscodeInsidersInstallImage,
141-
repoBaseUrl,
142-
AKA_INSTALL_URLS,
143-
ROOT_FOLDER,
144-
INSTRUCTIONS_DIR,
145-
PROMPTS_DIR,
146167
AGENTS_DIR,
147-
SKILLS_DIR,
168+
AKA_INSTALL_URLS,
148169
COLLECTIONS_DIR,
149170
COOKBOOK_DIR,
171+
DOCS_DIR,
172+
HOOKS_DIR,
173+
INSTRUCTIONS_DIR,
150174
MAX_COLLECTION_ITEMS,
151-
SKILL_NAME_MIN_LENGTH,
152-
SKILL_NAME_MAX_LENGTH,
153-
SKILL_DESCRIPTION_MIN_LENGTH,
175+
PROMPTS_DIR,
176+
repoBaseUrl,
177+
ROOT_FOLDER,
154178
SKILL_DESCRIPTION_MAX_LENGTH,
155-
DOCS_DIR,
179+
SKILL_DESCRIPTION_MIN_LENGTH,
180+
SKILL_NAME_MAX_LENGTH,
181+
SKILL_NAME_MIN_LENGTH,
182+
SKILLS_DIR,
183+
TEMPLATES,
184+
vscodeInsidersInstallImage,
185+
vscodeInstallImage
156186
};
157187

0 commit comments

Comments
 (0)