Describe the feature or problem you'd like to solve
There is currently no way to deterministically guard the agent's work before it returns control to the user, while still being able to act on the result of the hook.
Proposed solution
Introduce a preAgentStop hook that fires when the agent is about to stop responding:
- Exit code 0: the agent stops as normal.
- Non-zero exit code: the agent receives the hook's stdout/stderr as context and continues working to address the issues. The hook re-triggers when the agent tries to stop again.
- A configurable
maxRetries field (e.g., 3) prevents infinite loops.
This benefits Copilot CLI users by enabling deterministic, enforceable guardrails and quality gates without relying on the model to remember instructions (which is not deterministic), while also being able to make changes on the outcome of those checks
Example prompts or workflows
- Linting and formatting enforcement
- Type-checks and build checks
- Running unit tests
...
Additional context
- Example
hooks.json configuration:
{
"version": 1,
"hooks": {
"preAgentStop": [
{
"type": "command",
"bash": "npx eslint",
"powershell": "npx eslint",
"cwd": ".",
"timeoutSec": 120,
"maxRetries": 3
}
]
}
}
- Also add
preSubAgentStop
Analogous to agentStop and subAgentStop
Describe the feature or problem you'd like to solve
There is currently no way to deterministically guard the agent's work before it returns control to the user, while still being able to act on the result of the hook.
Proposed solution
Introduce a
preAgentStophook that fires when the agent is about to stop responding:maxRetriesfield (e.g.,3) prevents infinite loops.This benefits Copilot CLI users by enabling deterministic, enforceable guardrails and quality gates without relying on the model to remember instructions (which is not deterministic), while also being able to make changes on the outcome of those checks
Example prompts or workflows
...
Additional context
hooks.jsonconfiguration:{ "version": 1, "hooks": { "preAgentStop": [ { "type": "command", "bash": "npx eslint", "powershell": "npx eslint", "cwd": ".", "timeoutSec": 120, "maxRetries": 3 } ] } }preSubAgentStopAnalogous to
agentStop and subAgentStop