AI / GitHub Copilot CLI Fundamentals Interview Questions
What are Copilot CLI hooks and what can they be used for?
Hooks are user-defined scripts that Copilot CLI invokes automatically at specific points during a session - for example, before or after Copilot modifies files. They let you inject custom logic (validation, notifications, formatting) into the Copilot workflow without modifying the agent's core behaviour.
| Aspect | Detail |
|---|---|
| Configuration | Defined in the Copilot CLI config or a hooks configuration file |
| Hook events | Pre-task, post-task, pre-file-write, post-file-write, and others depending on the version |
| Input payload | Hooks receive a JSON payload describing the current action |
| Decision control | Hooks can allow, block, or modify Copilot's planned actions |
| Use cases | Auto-format code after edits, run linters, send Slack notifications, enforce security policies |
# Example hook: run prettier after every file write # hooks config (format may vary - check docs for current schema) hooks: post-file-write: - command: "npx prettier --write {file}" description: "Auto-format after Copilot edits" # Example hook: block writes to sensitive paths # A hook can inspect the planned file path and return # a decision to allow or deny the write
For detailed information about hooks - including configuration formats, supported events, input payloads, and decision control - see the GitHub Copilot hooks reference in the official documentation.
More Related questions...