Repository navigation
Scope telemetry hooks with tool matchers - #22084
Conversation
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
🔵 Needs a closer look
The Claude Read gate is tested only as serialized text, so client-level validation is still needed to confirm rule evaluation triggers plugin, user, and project skill reads, including Windows paths.
No open issues 🎉
What changed in this PR
This PR narrows Aspire’s agent telemetry hooks to reduce unnecessary CLI launches, addressing the noisy per-tool invocation reported in #20480. It builds on #22078’s per-client hook registration while keeping the classifier as the final filter.
Changes:
- Adds tool-name matchers for Copilot and Claude Code, with a path-filtered Claude
Readhook for Aspire skills. - Extracts shared settings merge and hook-identification logic into
TelemetryHookSettings. - Updates matcher tests, registration expectations, and the telemetry specification.
| File | Description |
|---|---|
| tests/Aspire.Cli.Tests/Agents/TelemetryHookConfiguratorTests.cs | Verifies matcher registration, migration, and preservation of existing hooks. |
| tests/Aspire.Cli.Tests/Agents/AgentTelemetryHookTests.cs | Tests tool matching and canonical MCP tool coverage. |
| tests/Aspire.Cli.EndToEnd.Tests/AgentCommandTests.cs | Updates expected Claude hook configuration. |
| src/Aspire.Cli/Agents/Hooks/TelemetryHookSettings.cs | Centralizes settings merging and Aspire hook identification. |
| src/Aspire.Cli/Agents/Hooks/AgentTelemetryHook.cs | Defines client matchers and the Claude skill-path condition. |
| src/Aspire.Cli/Agents/Copilot/CopilotAgentClient.cs | Registers the Copilot tool matcher. |
| src/Aspire.Cli/Agents/ClaudeCode/ClaudeCodeAgentClient.cs | Registers separate tool and filtered-read hook groups. |
| docs/specs/aspire-product-telemetry.md | Documents matcher scope and fallback behavior. |
Review effort: Balanced
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 22084Or
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 22084" |
This comment has been minimized.
This comment has been minimized.
84a23d3 to
a46114c
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
🔵 Needs a closer look
Tests inspect configuration and emulate matching but do not verify that supported Copilot/Claude versions suppress unrelated hook launches while preserving tracked skill, MCP, and Claude reference-read events.
No open issues 🎉
Review effort: Balanced
|
Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt. |
This comment has been minimized.
This comment has been minimized.
|
Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt. |
|
Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt. |
|
Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt. |
|
Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt. |
|
Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt. |
This comment has been minimized.
This comment has been minimized.
David Pine (IEvangelist)
left a comment
There was a problem hiding this comment.
No actionable findings.
|
Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt. |
|
Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt. |
Register the Copilot user hook with a tool-name matcher for skill and Aspire MCP tools, and register Claude PostToolUse hooks for the Skill and Aspire MCP tools plus Read calls limited to Aspire skill paths through an if rule. Share settings merge helpers through TelemetryHookSettings. Co-authored-by: Copilot App <[email protected]>
Add a test that every canonical skill and reference path matches ClaudeReadIf, and split the merged matcher paragraph in the telemetry spec. Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
Move the Copilot and Claude matcher constants into their agent clients, drop the shared settings helper, and restore the clients to their base shape plus the matcher behavior. Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
Claude Code does not evaluate hook if rules against Skill input (anthropics/claude-code#95819), so Skill(aspire*) blocked every Skill hook. Match every skill and let the classifier drop non-Aspire skills. Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
7159cf2 to
27a91a9
Compare
Tests selector2 / 101 PR test projects · 4 PR jobs, from 6 changed files. Selected PR test projects (2 / 101)
Selected PR jobs (4)
How these were chosen — grouped by what changed📦 affected project 🧪 🧪 🧪 Job reasons
Selection computed for commit |
## Description Stack 3/3, on #22084. `aspire agent init --scope project` now installs telemetry hooks too. The hooks are written at user scope (`~/.copilot/hooks` and `~/.claude/settings.json`) no matter which scope was requested. Skills and MCP configuration still follow the requested scope, and #22078's per-client gating still decides which clients get hooks. Because the hooks live in user-level configuration, they apply in every repository where that client runs, not only the one where `aspire agent init` was run. The PostToolUse matcher from #22084 makes the client launch `aspire` only for matching tool calls, and only Aspire skill, MCP tool, and reference-file usage is reported. Users can opt out with `ASPIRE_CLI_TELEMETRY_OPTOUT=true`. The install message now says the hooks were written to user-level configuration. ### Why we can't install project-level hooks today Every hook launches a separate `aspire` process, so it must fire exactly once per event. Today a project-level hook would make it fire more than once (see #20480): - **Copilot runs hooks from every source and doesn't dedupe them.** It loads the repo's `.github/hooks/*.json`, `~/.copilot/hooks`, `.github/copilot/settings(.local).json`, `~/.copilot/settings.json`, and plugins, then runs all of them. A project hook in `.github/hooks` plus the user hook that global init installs would launch `aspire` twice for each event. Claude Code dedupes identical handlers across its settings files, so this is a Copilot problem. - **Copilot also runs Claude's project hooks.** Copilot reads the repo's `.claude/settings(.local).json` and runs those hooks too, ignoring Claude-only fields such as `if`. A Claude project hook would fire in Copilot sessions on top of Copilot's own hook, even if the user set up only Claude for the project. - **Install time can't avoid the duplicates.** Project hook files are committed and shared, but user hooks belong to each machine. We can't delete a user hook to make room for a project hook, because it also serves the user's other repos. Skipping the project hook when a user hook exists only helps the developer who ran init, not teammates who clone the repo with their own user hooks. - **Runtime dedupe is heavy.** Each invocation is an independent process with no shared event ID. Deduping would mean hook processes coordinating through shared state on every tool call, which is the hot path. Installing hooks only at user scope gives exactly one hook per client on each machine. We can revisit project hooks if Copilot starts deduping identical hook commands or applying precedence across hook sources. Validation: `dotnet test --project tests\Aspire.Cli.Tests\Aspire.Cli.Tests.csproj --no-launch-profile -- --filter-class "*.AgentInit*" --filter-class "*.TelemetryHook*" --filter-class "*.AgentTelemetry*" --filter-not-trait "quarantined=true" --filter-not-trait "outerloop=true"` passed (464/464). The E2E tests were not run. ## Checklist - Is this feature complete? - [x] Yes. Ready to ship. - [ ] No. Follow-up changes expected. - Are you including unit tests for the changes and scenario tests if relevant? - [x] Yes - [ ] No - Did you add public API? - [ ] Yes - If yes, did you have an API Review for it? - [ ] Yes - [ ] No - Did you add `<remarks />` and `<code />` elements on your triple slash comments? - [ ] Yes - [ ] No - [x] No - Does the change make any security assumptions or guarantees? - [ ] Yes - If yes, have you done a threat model and had a security review? - [ ] Yes - [ ] No - [x] No --------- Co-authored-by: Copilot App <[email protected]> Copilot-Session: b39716fb-e8ff-45f3-a048-a710d4f3052e
## Description Backports of the PRs from https://github.com/microsoft/aspire/stack/22118: - #22078 - #22084 - #22093 ## Checklist - Is this feature complete? - [ ] Yes. Ready to ship. - [ ] No. Follow-up changes expected. - Are you including unit tests for the changes and scenario tests if relevant? - [ ] Yes - [ ] No - Did you add public API? - [ ] Yes - If yes, did you have an API Review for it? - [ ] Yes - [ ] No - Did you add `<remarks />` and `<code />` elements on your triple slash comments? - [ ] Yes - [ ] No - [ ] No - Does the change make any security assumptions or guarantees? - [ ] Yes - If yes, have you done a threat model and had a security review? - [ ] Yes - [ ] No - [ ] No --------- Co-authored-by: Copilot App <[email protected]> Copilot-Session: b39716fb-e8ff-45f3-a048-a710d4f3052e
Description
Telemetry hooks now use tool-name matchers, so agent clients start the aspire CLI only for tools the classifier tracks.
CopilotAgentClient.TelemetryHookMatcheradds amatcherforskilland the Aspire MCP tools. Copilot matchers see only the tool name, so there is noReadmatcher; one would start the CLI for every file read in every repository.ClaudeCodeAgentClientregisters threePostToolUsegroups:Skill(every skill, since Claude hookifrules don't match Skill input yet, [BUG] PreToolUse hook "if" field (permission-rule syntax) never matches Skill tool invocations (v2.1.278) anthropics/claude-code#95819, so the CLI classifier drops non-Aspire skills), the Aspire MCP tools, andReadlimited to Aspire skill directories by anifrule.AgentTelemetryHook.McpMatcheris built from the classifier's MCP tool prefixes, so the matchers cannot drift from the classifier.IMPORTANT: Copilot limitation
This doesn't fully solve the invocation problem for Copilot. Copilot hook matchers only see the tool name, and Copilot has no equivalent of Claude Code's
ifrules for filtering on tool input. So for Copilot:skillcall starts the aspire CLI, including non-Aspire skills. The classifier drops those events, but the process still launches.viewat all. Clients that honor the matcher don't reportreference_file_readevents.matcherand still start the CLI for every tool.Fully scoping Copilot needs input-based filtering in Copilot hooks.
Validation:
dotnet test --project tests\Aspire.Cli.Tests\Aspire.Cli.Tests.csproj --no-launch-profile -- --filter-class "*.AgentInit*" --filter-class "*TelemetryHook*" --filter-class "*AgentTelemetry*" --filter-not-trait "quarantined=true" --filter-not-trait "outerloop=true"passed (449/449). TheAspire.Cli.EndToEnd.Testsbuild succeeds, but the E2E tests were not run.Fixes #20480
Checklist
<remarks />and<code />elements on your triple slash comments?