GitHub Copilot supports hooks that can automate tasks during an agent session. A practical use case is auto-formatting C# code after every file edit using the postToolUse hook event. The post walks through writing a PowerShell script that detects .cs file edits and runs dotnet format with .editorconfig rules, then configuring the hook JSON file in .github/hooks. It also explains why postToolUse is preferable to sessionEnd: the agent sees clean, formatted code before its next step, leading to better decisions and cleaner diffs.
Table of contents
What event should we use?Writing our scriptCreating the hookTesting the hookMore informationSort: