npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

opencode-agent-cpa-env-switcher-plugin

v0.2.0

Published

OpenCode plugin that switches CPA provider prefixes for primary agents, subagents, commands, and default models from CPA_PROVIDER.

Readme

opencode-agent-cpa-env-switcher-plugin

OpenCode server plugin that selects the active CPA provider from CPA_PROVIDER and rewrites configured model provider prefixes in memory at startup.

Supported provider IDs:

  • cpa-jp-edge
  • cpa-van-base

The plugin rewrites known CPA provider prefixes and the literal {env:CPA_PROVIDER} placeholder. Model IDs, variants, prompts, permissions, and unrelated providers remain unchanged.

Environment-neutral agent files

OpenCode expands {env:VAR} references in opencode.json before parsing, but it does not expand them inside agent Markdown frontmatter. To keep agent files environment-neutral, write the literal placeholder as the model prefix:

---
mode: subagent
model: "{env:CPA_PROVIDER}/gpt-5.6-sol"
---

The unexpanded {env:CPA_PROVIDER} prefix reaches this plugin at startup and is rewritten to the selected provider, exactly like a concrete cpa-jp-edge or cpa-van-base prefix. Agent files therefore never name a specific endpoint and switching environments creates no Git diff.

Install

Add the unpinned package to ~/.config/opencode/opencode.json:

{
  "$schema": "https://opencode.ai/config.json",
  "plugin": [
    "opencode-agent-cpa-env-switcher-plugin"
  ]
}

OpenCode installs the current package release when it resolves the plugin.

Environment

Set the selected provider before starting OpenCode:

export CPA_PROVIDER="cpa-van-base"

The plugin does not load .env files. Source your environment file before launching OpenCode.

Example shell function:

opencode() {
  source "$HOME/.config/opencode/.env"
  command opencode --auto "$@"
}

Provider configuration

The selected provider must exist in the resolved OpenCode configuration. Raw environment substitution happens before JSON parsing, so the provider ID and display name can both be environment-driven:

{
  "model": "{env:CPA_PROVIDER}/gpt-5.6-sol",
  "small_model": "{env:CPA_PROVIDER}/gpt-5.6-luna",
  "provider": {
    "{env:CPA_PROVIDER}": {
      "name": "{env:CPA_PROVIDER_NAME}",
      "npm": "@ai-sdk/openai-compatible",
      "options": {
        "baseURL": "{env:CPA_BASE_URL}/v1",
        "apiKey": "{env:CPA_API_KEY}"
      },
      "models": {
        "gpt-5.6-sol": {
          "name": "GPT-5.6 Sol"
        },
        "gpt-5.6-luna": {
          "name": "GPT-5.6 Luna"
        }
      }
    }
  }
}

What is rewritten

At startup the plugin updates the provider prefix for:

  • the top-level model
  • small_model
  • every primary agent and subagent model
  • deprecated mode agent entries
  • command-specific models

A prefix is rewritten when it is cpa-jp-edge, cpa-van-base, or the literal {env:CPA_PROVIDER} placeholder. For example, with CPA_PROVIDER=cpa-van-base:

cpa-jp-edge/claude-fable-5
{env:CPA_PROVIDER}/claude-fable-5

both resolve in memory as:

cpa-van-base/claude-fable-5

Tracked agent files are not modified, so switching environments does not create a Git diff.

Models belonging to providers other than cpa-jp-edge and cpa-van-base are left unchanged.

Failure behavior

OpenCode startup fails clearly when:

  • CPA_PROVIDER is missing
  • CPA_PROVIDER is not one of the supported IDs
  • the selected provider is absent from the resolved provider configuration

Credentials are never read or logged by this plugin.

Development

npm install
npm run check
npm pack --dry-run

Publishing

CI runs on pushes and pull requests using supported Node.js versions.

Publishing runs automatically when a matching version tag is pushed:

npm version patch
git push origin main --follow-tags

The package version must match the tag (0.1.1 requires v0.1.1). The publish workflow uses npm trusted publishing with GitHub Actions OIDC and provenance.

After the initial npm publication, configure the package's npm trusted publisher:

  • Provider: GitHub Actions
  • GitHub owner: caoool
  • Repository: opencode-agent-cpa-env-switcher-plugin
  • Workflow filename: publish.yml
  • Allowed action: npm publish