Copilot CLI hooks: hooks.json in .github/hooks/, preToolUse and permissionRequest
- copilot
- coding-agents
- guardrails
GitHub Copilot CLI hooks are shell commands the CLI runs at fixed points of a session. They live in JSON files under .github/hooks/ in a repository or ~/.copilot/hooks/ for your user. The file needs "version": 1 and a hooks object. The hook that can stop a tool is preToolUse. A second one, permissionRequest, answers the approval prompt before the CLI shows it.
{
"version": 1,
"hooks": {
"preToolUse": [
{
"type": "command",
"matcher": "bash|powershell",
"bash": "./scripts/check-command.sh",
"powershell": "./scripts/check-command.ps1",
"timeoutSec": 10
}
]
}
}
- Where. Any
*.jsonin.github/hooks/for the repo. Any*.jsonin~/.copilot/hooks/for you. Inline under ahookskey insettings.json. - Events. Fourteen in the reference.
preToolUseandpermissionRequestcan say no. - Deny. Print
permissionDecision: "deny"with a reason, or exit 2. A crash denies too. A timeout does not. - Trust. Repo hooks load only after you trust the folder. In
-pmode they stay off unless you opt in. - How I know. I do not run Copilot CLI. This post reads the GitHub docs and the CLI changelog up to 1.0.105 on 31 October 2026.
The Claude Code version, with my own guardrail script, is in my PreToolUse post. This one is the Copilot CLI side, from the docs only.
Where does Copilot CLI read hooks.json?
Six places, per the hooks reference. Policy files load first, then user files, then the repository, then plugins. For one event, every entry from every source runs. Any file name works.
The repository level is .github/hooks/*.json at the repo root. The user level is ~/.copilot/hooks/*.json, or $COPILOT_HOME/hooks/ when that variable is set. The docs call them user-level hooks, searches say global hooks.
Inline works too. Put a hooks object at the top level of ~/.copilot/settings.json, or of .github/copilot/settings.json in the repo. The CLI also reads .claude/settings.json in the repo for shared keys, hooks among them. The docs say the CLI "no longer reads ~/.copilot/config.json for hooks".
The sixth source is policy hooks in /etc/github-copilot/policy.d/*.json, which disableAllHooks cannot switch off.
What hook events does Copilot CLI have?
Fourteen, in the reference's event table on 31 October 2026. The lifecycle ones are sessionStart, sessionEnd, userPromptSubmitted, userPromptTransformed, agentStop, subagentStart, subagentStop, errorOccurred and preCompact. The tool ones are preToolUse, postToolUse and postToolUseFailure. Then permissionRequest and notification.
errorOccurred, sessionEnd and preCompact are notification only. agentStop can return decision: "block" with a reason and force another turn, up to eight times in a row.
Each entry is type: "command" with a bash key, a powershell key, or a cross-platform command. Optional keys are cwd, env, matcher and timeoutSec. The default timeout is 30 seconds.
Event names come in two spellings. preToolUse gets camelCase input with toolName and toolArgs. PreToolUse, in PascalCase, gets the VS Code shape with tool_name and tool_input.
How does a Copilot CLI preToolUse hook deny a command?
A Copilot CLI preToolUse hook denies a command by printing permissionDecision: "deny" to stdout, or by exiting 2. The other values are allow and ask. A deny needs permissionDecisionReason, which the agent sees. modifiedArgs swaps the tool arguments before the call. Per the reference, exit 2 denies "even if that JSON reports permissionDecision: "allow"".
The input for bash is sessionId, timestamp, cwd, toolName and toolArgs. The tutorial's policy script parses toolArgs with jq and tests the command against a regex list.
Command hooks on preToolUse are fail-closed. A crash or any non-zero exit denies the call with "Denied by preToolUse hook (hook errored)". Timeouts are the exception. A hook that runs past timeoutSec is killed, a warning is shown, and the tool call goes on through the normal permission flow. Per the changelog, errors deny since 1.0.57 in June 2026 and exit 2 denies since 1.0.70 in July.
ask has a catch. In autopilot mode ask becomes a deny. Codex does not support ask yet, see my Codex hooks post.
What is the Copilot CLI permissionRequest hook?
A hook that runs before the permission service, so before rule checks, session approvals and the user prompt. If the hook returns behavior: "allow" or "deny", the normal flow is skipped. Empty output falls through. The docs point it at -p mode and CI, "where no interactive prompt is available". The changelog adds it in 1.0.16.
Output is behavior, a message the model sees on a deny, and interrupt, which stops the agent on a deny. Exit 2 counts as deny here as well. A request to leave the sandbox ignores a hook allow. Only a deny propagates.
So preToolUse says whether a tool runs. permissionRequest says whether a prompt appears.
Why are my Copilot CLI hooks not working?
Copilot CLI hooks usually fail for one of five reasons, four of them from the how-to page's troubleshooting table: the file is outside .github/hooks/, the JSON does not parse, "version": 1 is missing, the script is not executable or has no shebang, or the folder is not trusted. Hook changes load at startup, so restart the CLI.
Repository hooks load "only after folder trust is confirmed", per the changelog since 1.0.8. In -p mode repo hooks stay off unless the folder is trusted, --trust-folder is passed for that run, or GITHUB_COPILOT_PROMPT_MODE_REPO_HOOKS=true is set. COPILOT_ALLOW_ALL=true also trusts the folder, a trap from my Copilot CLI allow all tools post.
A matcher is a regex anchored as ^(?:PATTERN)$, so it must match the whole tool name. The native names are lowercase, so Bash will not match bash under preToolUse. disableAllHooks: true in repository settings.json turns off every hook except policy ones.
How do Copilot CLI hooks differ from VS Code Copilot and Claude Code hooks?
VS Code Copilot and Copilot CLI share one hook format. The VS Code docs, read on 31 October 2026, say the editor, the Copilot app and the CLI "share this harness and its hook format". Claude Code differs. Its event is PreToolUse, its deny sits under hookSpecificOutput, and a crashed hook does not block unless onFailure: "block" is set.
| Copilot CLI 1.0.105 | VS Code Copilot, Copilot harness | Claude Code | |
|---|---|---|---|
| Config | .github/hooks/*.json, ~/.copilot/hooks/*.json, inline hooks in settings | Same files, same harness | hooks in settings files |
| Event | preToolUse or PreToolUse | preToolUse or PreToolUse | PreToolUse |
| Matcher | Regex on toolName, full match | Same; only the older Local harness ignores matcher values | By tool name |
| Deny | Top-level permissionDecision: "deny" or exit 2 | Top-level permissionDecision: "deny" | hookSpecificOutput.permissionDecision or exit 2 |
| Crash | Denies the call | Denies, per the GitHub docs it cites | Non-blocking unless onFailure: "block" |
| Timeout | Fail-open, 30 s default | Fail-open | 600 s default |
The config file and the event name port from Claude Code. Per the changelog, since 1.0.6 one file works "across VS Code, Claude Code, and the CLI without modification". Whether the CLI reads Claude Code's hookSpecificOutput wrapper, I could not confirm. The docs show permissionDecision at the top level. Exit 2 denies in both.
Frequently asked questions
Does Copilot CLI have hooks?
Yes. Hook files go in .github/hooks/ or ~/.copilot/hooks/, with "version": 1.
Is there a Copilot CLI hook for permission requests?
Yes, permissionRequest. It runs before the permission flow and returns behavior: "allow" or "deny".
Do global Copilot CLI hooks exist?
Yes. User-level hooks in ~/.copilot/hooks/*.json, or under hooks in ~/.copilot/settings.json, apply to every session.
Did you test this?
No. Copilot CLI is not installed on my machine. This post reads the GitHub Copilot docs and the CLI changelog up to 1.0.105 on 31 October 2026. The Claude Code column comes from its docs and my earlier posts.
The verdict
A crashed hook blocks. A slow hook does not. Set timeoutSec above what your script needs, then test the deny path with a canary command before you trust it.
Sources, read on 31 October 2026: the GitHub Copilot hooks reference, Using hooks with GitHub Copilot CLI, the Rolling out Copilot CLI hooks tutorial, the configuration directory reference, the command reference and the github/copilot-cli changelog. Claude Code fields come from its hooks reference.