GH Copilot | synthetic user messages burn premium requests
Description
When a subagent is created, the messages passed through to it look to be created with the user role, which burns a premium request. Same seems to happen once a response from the subagent is received.
As this is now an "officially supported(?)" plugin, I'm assuming it should have the same functionality as vscode, which does not consume requests in the same way when calling their native runSubagent tool.
Quick summary from opencode as I am not familiar at all with the codebase so can only really provide input on what I've observed:
Summary
The problem is in packages/opencode/src/plugin/copilot.ts at lines 51-88.
Issue Details
-
X-Initiator Header Logic: The Copilot plugin sets "X-Initiator": isAgent ? "agent" : "user" to distinguish between user and agent requests. The isAgent flag is determined by checking if last?.role !== "user" (lines 63 and 75).
-
Subagent Spawning Creates User Messages: When the task tool spawns a subagent (packages/opencode/src/tool/task.ts:145-160), it calls SessionPrompt.prompt() which internally calls createUserMessage() (packages/opencode/src/session/prompt.ts:820-821). This function always creates messages with role: "user" (line 824).
-
Detection Logic Flaw: The isAgent detection in the Copilot plugin only looks at the last message's role. When a subagent is spawned: - A new user message is created to prompt the subagent
- The last message in the API request has role: "user"
- isAgent becomes false
- X-Initiator: user is sent instead of X-Initiator: agent
-
Post-Subagent Message Also Affected: After a subagent completes, another synthetic user message is added (packages/opencode/src/session/prompt.ts:458-476) to continue the parent agent's task. This also gets classified as a user message.
Plugins
None
OpenCode version
1.1.21
Steps to reproduce
Using a Github Copilot model, ask it to spawn a subagent to do work, you will see your usage increase both for your initial message, but also as well as when it enters and exits the call.
Screenshot and/or share link
No response
Operating System
N/A
Terminal
N/A