Skip to content

Scope SessionStart hook to Copilot Studio projects only - #181

Open
hectorfitch-coder wants to merge 1 commit into
microsoft:mainfrom
hectorfitch-coder:scope-sessionstart-hook-to-cs-projects
Open

Scope SessionStart hook to Copilot Studio projects only#181
hectorfitch-coder wants to merge 1 commit into
microsoft:mainfrom
hectorfitch-coder:scope-sessionstart-hook-to-cs-projects

Conversation

@hectorfitch-coder

Copy link
Copy Markdown

Problem

The SessionStart hook in hooks/hooks.json has no matcher/condition, so hooks/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.yml in the working directory or a subdirectory (exactly what system-prompt.md already uses to detect "already inside a Copilot Studio project"). When no marker is found, print-prompt.js exits without output.

A SessionStart hook 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 bounded hasCopilotStudioProject(cwd, depth 4, ≤2000 dirs) check (skips node_modules/.git/build dirs) and process.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 inline command variant (previously read system-prompt.md directly) at the now-gated print-prompt.js, so the gate is the single source of truth across the command/bash/powershell variants. setup.js is untouched.

Verification

  • No marker in cwd → print-prompt.js produces 0 bytes (nothing injected).
  • agent.mcs.yml present (incl. nested subdirectory) → full prompt injected as before.
  • hooks.json parses as valid JSON; print-prompt.js passes node --check.

Notes / trade-offs

  • This changes behaviour for CS work started in a directory that does not yet contain an agent.mcs.yml (e.g. cloning a brand-new agent from scratch). system-prompt.md already 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.
  • Scan depth (4) and dir cap (2000) are conservative defaults — easy to tune.

🤖 Generated with Claude Code

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>
@hectorfitch-coder

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant