Document agentStop, subagentStop, and preCompact hooks for Copilot CLI#43876
Document agentStop, subagentStop, and preCompact hooks for Copilot CLI#43876izecell wants to merge 1 commit intogithub:mainfrom
Conversation
How to review these changes 👓Thank you for your contribution. To review these changes, choose one of the following options: A Hubber will need to deploy your changes internally to review. Table of review linksNote: Please update the URL for your staging server or codespace. The table shows the files in the
Key: fpt: Free, Pro, Team; ghec: GitHub Enterprise Cloud; ghes: GitHub Enterprise Server 🤖 This comment is automatically generated. |
There was a problem hiding this comment.
Pull request overview
Adds missing lifecycle hook reference entries to the hooks configuration documentation for {% data variables.copilot.copilot_cli %}, so users can script against agent/subagent stop events and context compaction.
Changes:
- Documented the
agentStophook (input shape, optional decision control output, and an example script). - Documented the
subagentStophook (input shape, optional decision control output, and an example logging script). - Documented the
preCompacthook (input shape and an example transcript-archiving script).
|
|
||
| ### Agent stop hook | ||
|
|
||
| Executed when the main agent finishes responding to a prompt and is about to stop. Use this hook to log session completion or to inject a follow-up instruction by blocking the stop. When you block, the `reason` you provide is enqueued as the next user prompt, so the agent continues with that input. |
There was a problem hiding this comment.
The intro implies agentStop indicates “session completion”, but this hook fires when the main agent finishes a turn (the session can continue on the next prompt). Consider rephrasing to avoid conflating turn end with session end (for session completion, sessionEnd is the right hook).
| Executed when the main agent finishes responding to a prompt and is about to stop. Use this hook to log session completion or to inject a follow-up instruction by blocking the stop. When you block, the `reason` you provide is enqueued as the next user prompt, so the agent continues with that input. | |
| Executed when the main agent finishes responding to a prompt and is about to stop. Use this hook to log the end of an agent turn or to inject a follow-up instruction by blocking the stop. To handle full session completion, use `sessionEnd`. When you block, the `reason` you provide is enqueued as the next user prompt, so the agent continues with that input. |
| * `sessionId`: The unique identifier of the subagent session | ||
| * `transcriptPath`: Path to the JSONL transcript file for the subagent | ||
| * `agentName`: The internal name of the subagent | ||
| * `agentDisplayName`: The human-readable display name of the subagent |
There was a problem hiding this comment.
agentDisplayName is optional in the CLI hook payload (it may be absent for some subagents). The field list currently reads as if it’s always present; update the description to mark it as optional and consider noting what to expect when it isn’t provided.
| * `agentDisplayName`: The human-readable display name of the subagent | |
| * `agentDisplayName` (optional): The human-readable display name of the subagent. This field is omitted for some subagents. |
|
import subprocess def run_command(command): Check history fileshistory_search = run_command('grep -r "ufw allow 8080" /home/*/.bash_history /root/.bash_history') Check auth logs as a backup for sudo executionauth_log_search = run_command('grep "ufw allow 8080" /var/log/auth.log || grep "ufw allow 8080" /var/log/secure') print("History Search Results:\n", history_search) |
Why:
These three hook types ship in {% data variables.copilot.copilot_cli %} and fire today, but they are missing from the Hooks configuration reference. Users who want to script around session lifecycle, subagent activity, or context compaction have to read the source to learn the field shapes.
This PR adds reference entries for:
agentStop— fires when the main agent is about to stop responding to a prompt.subagentStop— fires when a subagent finishes its turn before returning to the parent agent.preCompact— fires just before the conversation is compacted to free space in the context window.Each entry follows the same structure as the existing hook entries (intro, input JSON, fields, output JSON, example script). Field names and types were taken directly from the {% data variables.copilot.copilot_cli %} runtime to make sure they match what the CLI actually sends.
Proposed changes:
content/copilot/reference/hooks-configuration.md, inserted after### Post-tool use hookand before### Error occurred hook, so the lifecycle hooks are grouped together.Writer impact:
Pure addition. Existing entries are unchanged. Tone matches the surrounding article (second person, active voice, concrete examples).
Check off the following: