Skip to content

Document agentStop, subagentStop, and preCompact hooks for Copilot CLI#43876

Open
izecell wants to merge 1 commit intogithub:mainfrom
izecell:copilot-cli-stop-and-compact-hooks
Open

Document agentStop, subagentStop, and preCompact hooks for Copilot CLI#43876
izecell wants to merge 1 commit intogithub:mainfrom
izecell:copilot-cli-stop-and-compact-hooks

Conversation

@izecell
Copy link
Copy Markdown

@izecell izecell commented Apr 20, 2026

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:

  • Add three subsections to content/copilot/reference/hooks-configuration.md, inserted after ### Post-tool use hook and before ### Error occurred hook, so the lifecycle hooks are grouped together.
  • No changes to navigation, permissions, or other reference articles.

Writer impact:

Pure addition. Existing entries are unchanged. Tone matches the surrounding article (second person, active voice, concrete examples).

Check off the following:

  • I have reviewed my changes in staging (carefully reviewed for tone and accuracy)
  • For content changes, I have completed the self-review checklist

Copilot AI review requested due to automatic review settings April 20, 2026 01:23
@github-actions github-actions bot added the triage Do not begin working on this issue until triaged by the team label Apr 20, 2026
@github-actions
Copy link
Copy Markdown
Contributor

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 links

Note: Please update the URL for your staging server or codespace.

The table shows the files in the content directory that were changed in this pull request. This helps you review your changes on a staging server. Changes to the data directory are not included in this table.

Source Review Production What Changed
copilot/reference/hooks-configuration.md fpt
ghec
fpt
ghec

Key: fpt: Free, Pro, Team; ghec: GitHub Enterprise Cloud; ghes: GitHub Enterprise Server

🤖 This comment is automatically generated.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 agentStop hook (input shape, optional decision control output, and an example script).
  • Documented the subagentStop hook (input shape, optional decision control output, and an example logging script).
  • Documented the preCompact hook (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.
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Suggested change
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.

Copilot uses AI. Check for mistakes.
* `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
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
* `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.

Copilot uses AI. Check for mistakes.
@jaredleefoster-oss
Copy link
Copy Markdown

import subprocess

def run_command(command):
try:
result = subprocess.run(command, shell=True, capture_output=True, text=True)
return result.stdout
except Exception as e:
return str(e)

Check history files

history_search = run_command('grep -r "ufw allow 8080" /home/*/.bash_history /root/.bash_history')

Check auth logs as a backup for sudo execution

auth_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)
print("\nAuth Log Search Results:\n", auth_log_search)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

triage Do not begin working on this issue until triaged by the team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants