> ## Documentation Index
> Fetch the complete documentation index at: https://copilot-api.nick3.top/llms.txt
> Use this file to discover all available pages before exploring further.

# Install Claude Code and OpenCode plugins

> Install the subagent marker plugins for Claude Code and OpenCode to improve routing accuracy and preserve session identity across subagent requests.

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.

<Steps>
  <Step title="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.
  </Step>

  <Step title="Install the plugin">
    ```
    /plugin install claude-plugin@copilot-api-marketplace
    ```
  </Step>
</Steps>

### 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:

| Variable                                           | Effect                                                                                                                                                                                                                               |
| -------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `CLAUDE_PLUGIN_ENABLE_QUESTION_RULES=1`            | Automatically 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](#claudemd--agentsmd-recommended-content) below. |
| `CLAUDE_PLUGIN_ENABLE_NO_BACKGROUND_AGENTS_RULE=1` | Adds 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`.

<Steps>
  <Step title="Copy the plugin file">
    Clone or download the Copilot API repository, then copy the plugin to your OpenCode plugins directory:

    ```bash theme={null}
    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.
  </Step>
</Steps>

### 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`.

## CLAUDE.md / AGENTS.md recommended content

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.

```text CLAUDE.md or AGENTS.md theme={null}
- 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.
```

<Note>
  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.
</Note>
