Skip to content

Commit 02159dd

Browse files
Move hooks example from README into lesson 15 (Programmatic Mode)
Agent-Logs-Url: https://github.com/instil/github-copilot-tutorial/sessions/836790b1-5069-4596-8b3f-94c23e92d1b5 Co-authored-by: calebwilson706 <71669491+calebwilson706@users.noreply.github.com>
1 parent 93ae68f commit 02159dd

2 files changed

Lines changed: 24 additions & 12 deletions

File tree

README.md

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,3 @@ The tutorial is built using three Copilot CLI features:
6262
- **Hooks** (`.github/hooks/`) — State persistence, context injection, and exercise validation
6363

6464
The tutorial itself is built using these three features working together.
65-
66-
### Hooks in Action
67-
68-
The `.github/hooks/` directory shows real hook usage:
69-
70-
| Hook | Script | Purpose |
71-
|------|--------|---------|
72-
| `sessionStart` | `session-start.sh` | Bootstrap `tutorial/state.json` on first run |
73-
| `userPromptSubmitted` | `prompt-context.sh` | Write the current lesson to `tutorial/current-lesson.md` so Copilot always has the right context |
74-
| `preToolUse` | `pre-tool-use.sh` | Auto-approve edits to `tutorial/state.json` so navigation agents don't trigger permission prompts |
75-
76-
The `preToolUse` hook is a practical example of using `permissionDecision: "allow"` (available since Copilot CLI v1.0.18) to suppress approval prompts for trusted, repetitive operations — here, the lesson-progress updates that happen every time you say "next" or "skip".

tutorial/lessons/15-programmatic-mode.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,30 @@ cat error.log | copilot -p "explain this error and suggest a fix" > summary.txt
2828
git diff main | copilot -p "review these changes for bugs"
2929
```
3030

31+
### Hooks for automation
32+
33+
Hooks let you run scripts at key moments in Copilot's lifecycle — before and after tool use, when a session starts, or when a prompt is submitted. This is useful for automating repetitive decisions in CI or unattended workflows.
34+
35+
A practical example lives in this tutorial itself. Navigation agents write to `tutorial/state.json` on every lesson transition. Rather than prompting for permission each time, a `preToolUse` hook auto-approves those writes:
36+
37+
```json
38+
// .github/hooks/hooks.json
39+
{
40+
"preToolUse": [{ "type": "command", "bash": "bash .github/hooks/pre-tool-use.sh" }]
41+
}
42+
```
43+
44+
```bash
45+
# .github/hooks/pre-tool-use.sh
46+
INPUT=$(cat)
47+
FILE_PATH=$(echo "$INPUT" | jq -r '.tool_input.path // .parameters.path // .path // empty')
48+
if [ "$FILE_PATH" = "tutorial/state.json" ]; then
49+
echo '{"permissionDecision": "allow"}'
50+
fi
51+
```
52+
53+
Returning `permissionDecision: "allow"` from a `preToolUse` hook suppresses the approval prompt entirely — key for any automation where you trust the operation and want zero interruptions.
54+
3155
### Scoping permissions
3256

3357
When running in automation, lock down what Copilot can do:

0 commit comments

Comments
 (0)