Scope SessionStart hook to Copilot Studio projects only - #181
Open
hectorfitch-coder wants to merge 1 commit into
Open
Scope SessionStart hook to Copilot Studio projects only#181hectorfitch-coder wants to merge 1 commit into
hectorfitch-coder wants to merge 1 commit into
Conversation
The SessionStart hook has no matcher, so hooks/system-prompt.md (~11KB) is injected into every Claude Code / Copilot CLI session, including ones unrelated to Copilot Studio. This adds constant context overhead and applies the prompt's "bias toward assuming Copilot Studio" and "using skills directly is FORBIDDEN" directives in non-CS sessions. Gate the injection on the plugin's own definition of a CS project: an agent.mcs.yml in the working directory or a subdirectory. A SessionStart hook runs before any user message, so the project marker is the only reliable signal of intent. When no marker is found, print-prompt.js exits without output. hooks.json's inline `command` variant is repointed at the (now gated) print-prompt.js so the gate is the single source of truth across all variants. setup.js is unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Author
|
@microsoft-github-policy-service agree |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The
SessionStarthook inhooks/hooks.jsonhas no matcher/condition, sohooks/system-prompt.md(~11KB of "act as manager, delegate to the Advisor/Author/Manage/Test sub-agents" routing rules) is injected into every session — including ones with nothing to do with Copilot Studio. I hit this when the prompt showed up in an unrelated session in a non-CS repository.Why it matters
Beyond the constant context overhead, the prompt instructs a strong "bias toward assuming the request is about Copilot Studio" and that "using skills directly is FORBIDDEN". In a non-CS session those directives apply unless the model explicitly disregards them.
Fix
Gate the injection on the plugin's own definition of a Copilot Studio project — an
agent.mcs.ymlin the working directory or a subdirectory (exactly whatsystem-prompt.mdalready uses to detect "already inside a Copilot Studio project"). When no marker is found,print-prompt.jsexits without output.A
SessionStarthook runs before any user message, so it cannot read user intent; the project marker is the only reliable signal available at that point.Changes
hooks/print-prompt.js— adds a boundedhasCopilotStudioProject(cwd, depth 4, ≤2000 dirs)check (skipsnode_modules/.git/build dirs) andprocess.exit(0)s when no marker is present. The existing Copilot-CLI-JSON vs Claude-Code-raw output branch is unchanged.hooks/hooks.json— repoints the inlinecommandvariant (previously readsystem-prompt.mddirectly) at the now-gatedprint-prompt.js, so the gate is the single source of truth across thecommand/bash/powershellvariants.setup.jsis untouched.Verification
print-prompt.jsproduces 0 bytes (nothing injected).agent.mcs.ymlpresent (incl. nested subdirectory) → full prompt injected as before.hooks.jsonparses as valid JSON;print-prompt.jspassesnode --check.Notes / trade-offs
agent.mcs.yml(e.g. cloning a brand-new agent from scratch).system-prompt.mdalready documents the clone-first flow, and users can also mention "Copilot Studio" explicitly; happy to add an env-var/opt-in escape hatch (e.g.COPILOT_STUDIO_ALWAYS_ON=1) if you'd prefer one.🤖 Generated with Claude Code