Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 50 additions & 3 deletions website/src/content/docs/learning-hub/automating-with-hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: 'Automating with Hooks'
description: 'Learn how to use hooks to automate lifecycle events like formatting, linting, and governance checks during Copilot agent sessions.'
authors:
- GitHub Copilot Learning Hub Team
lastUpdated: 2026-05-05
lastUpdated: 2026-05-08
estimatedReadingTime: '8 minutes'
tags:
- hooks
Expand Down Expand Up @@ -89,7 +89,7 @@ Hooks can trigger on several lifecycle events:
|-------|---------------|------------------|
| `sessionStart` | Agent session begins or resumes | Initialize environments, log session starts, validate project state |
| `sessionEnd` | Agent session completes or is terminated | Clean up temp files, generate reports, send notifications |
| `userPromptSubmitted` | User submits a prompt | Log requests for auditing and compliance |
| `userPromptSubmitted` | User submits a prompt | Log requests for auditing and compliance; handle requests directly without invoking the LLM (v1.0.44+) |
| `preToolUse` | Before the agent uses any tool (e.g., `bash`, `edit`) | **Approve or deny** tool executions, block dangerous commands, enforce security policies |
| `postToolUse` | After a tool **successfully** completes execution | Log results, track usage, format code after edits |
| `postToolUseFailure` | When a tool call **fails with an error** | Log errors for debugging, send failure alerts, track error patterns |
Expand Down Expand Up @@ -441,6 +441,53 @@ Scan user prompts for potential security threats and log session activity:

This pattern is useful for enterprise environments that need to audit AI interactions for compliance.

### Handling Requests Directly with userPromptSubmitted (v1.0.44+)

Since v1.0.44, `userPromptSubmitted` hooks can do more than log or block — they can **handle a request entirely**, returning a response to the user without making any model call. When your hook script writes a JSON object with a `response` field to stdout, the CLI delivers that text to the user and skips the LLM altogether.

This is useful for:
- **FAQ bots**: Return canned answers for common questions without spending model quota
- **Policy enforcement**: Reject out-of-scope prompts with a clear, consistent message
- **Redirect patterns**: Direct users to a specific resource or runbook

```json
{
"version": 1,
"hooks": {
"userPromptSubmitted": [
{
"type": "command",
"bash": "./scripts/prompt-router.sh",
"timeoutSec": 5
}
]
}
}
```

Example script that handles a `/help` prefix without invoking the model:

```bash
#!/usr/bin/env bash
# scripts/prompt-router.sh
# Return a direct response for known help queries — no LLM call needed.

INPUT=$(cat)
PROMPT=$(echo "$INPUT" | jq -r '.prompt // empty' | tr '[:upper:]' '[:lower:]')

if echo "$PROMPT" | grep -q "^/help\b"; then
echo '{"response": "Available commands: /generate-tests, /review-pr, /explain-architecture. Type /help <command> for details."}'
exit 0
fi

# No match — let the LLM handle it normally (exit 0 without writing a response)
exit 0
```

> **How it works**: When the hook exits with code `0` **and** writes a valid `{"response": "..."}` JSON object to stdout, the CLI delivers that text to the user and stops processing — no model call is made. If the hook exits with code `0` but writes nothing (or writes no `response` key), the CLI proceeds normally and calls the LLM.

> **Multiple hooks**: If several `userPromptSubmitted` hooks are configured, the first one that returns a `response` wins; subsequent hooks for that event are skipped.

### Notification on Session End

Send a Slack or Teams notification when an agent session completes:
Expand Down Expand Up @@ -592,7 +639,7 @@ For team-wide hooks that everyone should use, `.github/hooks/` is the recommende

**Q: Can hooks access the user's prompt text?**

A: Yes, for `userPromptSubmitted` events the prompt content is available via JSON input to the hook script. Other hooks like `preToolUse` and `postToolUse` receive context about the tool being called. See the [GitHub Copilot hooks documentation](https://docs.github.com/en/copilot/concepts/agents/coding-agent/about-hooks) for details.
A: Yes. For `userPromptSubmitted` events the prompt content is available via JSON input to the hook script. Since v1.0.44, these hooks can also **respond directly** by writing `{"response": "..."}` to stdout — the CLI delivers that text to the user and skips the LLM entirely. Other hooks like `preToolUse` and `postToolUse` receive context about the tool being called. See the [GitHub Copilot hooks documentation](https://docs.github.com/en/copilot/concepts/agents/coding-agent/about-hooks) for details.

**Q: What happens if a hook times out?**

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: 'Creating Effective Skills'
description: 'Master the art of writing reusable, shareable skill folders that deliver consistent results across your team.'
authors:
- GitHub Copilot Learning Hub Team
lastUpdated: 2026-02-26
lastUpdated: 2026-05-08
estimatedReadingTime: '9 minutes'
tags:
- skills
Expand Down Expand Up @@ -347,7 +347,10 @@ Use [scripts/parse-test-output.sh](scripts/parse-test-output.sh) to extract stru

**Q: How do I invoke a skill?**

A: Skills can be invoked in two ways. Users can type the skill name as a `/command` in VS Code Chat (e.g., `/generate-tests`). Agents can also discover and invoke skills automatically based on the skill's description and the user's intent.
A: Skills can be invoked in several ways:
- **Slash command**: Type the skill name anywhere in your message (e.g., `/generate-tests fix the failing tests`). Since v1.0.44, slash commands can appear mid-input — you don't have to start with them.
- **Multiple skills in one message**: You can invoke multiple skills in a single message (e.g., `/generate-tests and then /conventional-commit`). Both skills will be executed in sequence.
- **Agent discovery**: Agents can also discover and invoke skills automatically based on the skill's `description` and the user's intent — no slash command required.

**Q: How are skills different from prompts?**

Expand All @@ -361,9 +364,9 @@ A: Yes! Skills are folders, not single files. You can bundle reference documents

A: Store skill folders in your repository's `.github/skills/` directory. They're automatically available to all team members with Copilot access when working in that repository.

**Q: Can agents chain multiple skills?**
**Q: Can I invoke multiple skills in one message?**

A: Agents can discover and invoke multiple skills during a conversation based on user intent. Each skill invocation is independent, but agents maintain conversation context across invocations.
A: Yes, since v1.0.44. You can include multiple slash commands in a single message (e.g., `/generate-tests and then /conventional-commit`), and the CLI will execute each skill in sequence. Agents can also discover and chain multiple skills during a conversation based on user intent. Each skill invocation is independent, but agents maintain conversation context across invocations.

**Q: Should skills include code examples?**

Expand Down