Skip to main content
When Claude Code or OpenCode spawn subagents, the proxy needs to distinguish subagent requests from top-level user requests and keep them associated with the correct root session. Without a marker, the proxy treats every request as a fresh top-level interaction, which can consume unnecessary premium quota and breaks session affinity. The plugins fix this by injecting a session marker and propagating a session ID header. The proxy reads these values to preserve the parent session identity and correctly classify the traffic as subagent-originated.

Claude Code plugin

The Claude Code plugin is distributed through a marketplace hosted in the Copilot API repository.
1

Add the marketplace

Inside Claude Code, run:
/plugin marketplace add https://github.com/nick3/copilot-api.git#all
This registers the Copilot API marketplace catalog with Claude Code.
2

Install the plugin

/plugin install claude-plugin@copilot-api-marketplace

What the plugin does

  • Injects a subagent marker at the SubagentStart lifecycle event so the proxy can identify subagent traffic.
  • Registers a UserPromptSubmit hook that returns {"continue": true}.

Plugin environment variables

You can control the plugin’s behavior with these environment variables, set in your .claude/settings.json env block or in your shell:
VariableEffect
CLAUDE_PLUGIN_ENABLE_QUESTION_RULES=1Automatically injects question-tool reminders at session start. This is equivalent to adding the reminders manually in CLAUDE.md — see CLAUDE.md / AGENTS.md recommended content below.
CLAUDE_PLUGIN_ENABLE_NO_BACKGROUND_AGENTS_RULE=1Adds a reminder discouraging agent hooks that set run_in_background: true.

OpenCode plugin

The OpenCode plugin is a JavaScript file included in the Copilot API repository at .opencode/plugins/subagent-marker.js.
1

Copy the plugin file

Clone or download the Copilot API repository, then copy the plugin to your OpenCode plugins directory:
cp .opencode/plugins/subagent-marker.js ~/.config/opencode/plugins/
If you prefer not to clone the repository, create the file manually at ~/.config/opencode/plugins/subagent-marker.js with the plugin content from the repository.

What the plugin does

  • Tracks sub-sessions created by subagents.
  • Prepends a subagent marker as a system reminder to subagent chat messages.
  • Sets a session ID header for session tracking.
The plugin hooks into the following OpenCode events: session.created, session.deleted, chat.message, and chat.headers. Adding question-tool reminders to your project’s CLAUDE.md (for Claude Code) or AGENTS.md (for OpenCode and Codex) helps the agent check in with you before closing a task instead of finishing silently.
CLAUDE.md or AGENTS.md
- Prohibited from directly asking questions to users, MUST use question tool.
- Once you can confirm that the task is complete, MUST use question tool to make user confirm.
If you set CLAUDE_PLUGIN_ENABLE_QUESTION_RULES=1 in your Claude Code environment, the plugin injects these reminders automatically at session start. You do not need to add them to CLAUDE.md in that case — but it does not hurt to have both.