Replace per-skill AI disclosure with a PreToolUse hook#125889
Replace per-skill AI disclosure with a PreToolUse hook#125889lewing wants to merge 12 commits intodotnet:mainfrom
Conversation
Move the AI-generated content disclosure from duplicated text in copilot-instructions.md and 6 SKILL.md files into a single .github/hooks/hooks.json PreToolUse hook that fires when gh CLI commands post to GitHub (pr/issue create/comment/edit/review). This eliminates token waste from repeated instructions and ensures the disclosure applies uniformly to all GitHub-posting actions, including any future skills that use gh. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR centralizes the repository’s “AI-generated content disclosure” reminder by removing duplicated disclosure paragraphs from Copilot instructions and multiple skill prompts, and introducing a single lifecycle hook intended to trigger only when gh is used to post to GitHub.
Changes:
- Added a
.github/hooks/hooks.jsonPreToolUsehook to detectgh pr/issue {create,comment,edit,review,merge}and emit a disclosure reminder. - Removed the duplicated disclosure text from
.github/copilot-instructions.mdand several.github/skills/*/SKILL.mdfiles. - Kept skill workflows otherwise unchanged, relying on the hook as the new single source of truth.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| .github/hooks/hooks.json | Adds a PreToolUse hook for Bash that detects certain gh commands and prints a disclosure reminder. |
| .github/copilot-instructions.md | Removes the “AI-Generated Content Disclosure” section from the main Copilot instructions. |
| .github/skills/api-proposal/SKILL.md | Removes the per-skill disclosure paragraph from the publish phase guidance. |
| .github/skills/ci-analysis/SKILL.md | Removes the per-skill disclosure paragraph near the top-level workflow guidance. |
| .github/skills/code-review/SKILL.md | Removes the per-skill disclosure paragraph from the review output format guidance. |
| .github/skills/issue-triage/SKILL.md | Removes the per-skill disclosure paragraph from the anti-patterns section. |
| .github/skills/performance-benchmark/SKILL.md | Removes the per-skill disclosure paragraph near EgorBot posting instructions. |
| .github/skills/vmr-codeflow-status/SKILL.md | Removes the per-skill disclosure paragraph near the top-level workflow guidance. |
- Replace node -e with grep+shell (no external runtime dependency) - Broaden matcher to Bash|PowerShell for cross-platform coverage - Add one-line disclosure pointer back to copilot-instructions.md for discoverability in environments without hook support Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
lewing
left a comment
There was a problem hiding this comment.
Addressed all three review comments in 691492f:
- Node dependency → Replaced
node -ewith pure shell (grep -qE ... && echo >&2; :). No external runtime needed, always exits 0. - Matcher scope → Broadened to
"Bash|PowerShell"for cross-platform coverage. - Discoverability → Added a one-line pointer back in
copilot-instructions.mdlinking to.github/hooks/hooks.jsonso the rule is visible even in environments without hook support.
Note
This comment was generated with the help of Copilot.
Use the version 1 hooks schema with separate bash and powershell keys for cross-platform support. Pure shell builtins on both platforms — no dependency on grep, node, or other external tools. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Shell hook: match any command mentioning 'github' or 'gh' (covers gh CLI, curl to api.github.com, etc.) - GitHub MCP tools hook: unconditional reminder for any tool with 'github' in the name - copilot-instructions.md: remove gh-specific wording; the rule applies to all GitHub posting methods Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The copilot-instructions.md rule is the source of truth. The shell hook is a best-effort nudge when gh/github commands run, not a gate. Remove the overly broad GitHub MCP tool matcher that would spam on every read-only query. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Two hooks: 1. Shell (Bash|PowerShell): fires when command mentions github/gh 2. MCP tools: matcher catches write verbs (create|comment|update| edit|review|push|merge), then body checks for 'github' in the tool args to avoid false positives from non-GitHub tools No metadata on MCP tools to distinguish read vs write, so we match on tool name patterns containing write-like verbs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Shell hook now only fires on gh pr/issue create/comment/review/edit/ merge/close — not on reads like 'gh pr view' or 'gh issue list'. Message shortened to ~15 tokens referencing copilot-instructions.md for the full rule, avoiding context bloat in long sessions. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The hook message is a short pointer ('per copilot-instructions.md'),
so the full rule needs to live here. Restores the original section
from dotnet#125842. The per-skill duplicates remain removed — the hook
provides the point-of-action reminder, this section is the source
of truth.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
danmoseley
left a comment
There was a problem hiding this comment.
Lgtm if this works with all agents?
|
Note This comment was generated by Copilot CLI during local hook testing. Testing hooks locally — please ignore this comment. |
|
random commits in this PR? |
Merge the two separate preToolUse hooks (one for Bash/PowerShell gh CLI commands, one for GitHub MCP tools) into a single hook that covers both surfaces. This halves the number of hook executions per tool call, reducing context overhead. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
24bc9a0 to
1e2ccaf
Compare
fixed |
Switch to Claude nested format (PascalCase events, matcher→hooks structure) — the only format that works across all tools: - bash key: pure shell builtins (Copilot CLI, VS Code on Linux/macOS) - powershell key: native PS (Copilot CLI, VS Code on Windows) - command key: node -e fallback (Claude Code, Gemini CLI) Add .claude/settings.json with command-only hooks since Claude Code doesn't read .github/hooks/. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Two entries double the context cost since both matchers fire on Bash tool calls. One combined entry with merged matcher and stdin checks covers both gh CLI and GitHub MCP tools. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace per-skill AI disclosure with a single PreToolUse hook
Replaces the per-skill duplication from #125842 with a single
PreToolUsehook that reminds about AI-generated content disclosure at the point of action.What changed
.github/hooks/hooks.json— a singlePreToolUsehook (Copilot CLI format) withcommand(Node.js),bash, andpowershellvariants that fires on write-verb tool calls (Bash|PowerShell|create|comment|update|edit|review|push|merge) and checks forgh pr/issuecommands or GitHub MCP tool usage.claude/settings.json— equivalent Claude Code hook configurationcopilot-instructions.md(unchanged from Require AI-generated content disclosure in copilot instructions and skills #125842) — this is the source of truthapi-proposal/SKILL.mdci-analysis/SKILL.mdcode-review/SKILL.mdissue-triage/SKILL.mdperformance-benchmark/SKILL.mdvmr-codeflow-status/SKILL.mdDesign
ghCLI commands and GitHub MCP tools, avoiding doubled context overhead from running two hooks on every tool callcopilot-instructions.mdNote
This PR was drafted with the help of an AI agent.
cc @stephentoub