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

@tianhuil/opencode-dotenv

v0.1.1

Published

An OpenCode plugin that automatically loads .env files into shell environments

Downloads

40

Readme

OpenCode DotEnv Plugin

CI

An OpenCode plugin that automatically loads .env files into shell environments before every bash command execution.

Features

  • Automatic environment injection - Loads .env files before AI-triggered bash commands and interactive terminals
  • Multi-environment support - Follows dotenv-flow convention for .env.development, .env.production, etc.
  • Encrypted secrets - Supports encrypted values using dotenvx
  • Variable expansion - Reference other variables: DATABASE_URL=postgres://${USER}@localhost
  • Safe merging - Doesn't override existing environment variables

Installation

Install from npm (Recommended)

Add to your opencode.json config:

{
  "$schema": "https://opencode.ai/config.json",
  "plugin": ["@tianhuil/opencode-dotenv"]
}

OpenCode automatically installs npm plugins using Bun at startup. Packages are cached in ~/.cache/opencode/node_modules/.


Option 1: Project-level Plugin (Development)

The plugin files are already in place. OpenCode will automatically load it:

# Plugin is located at:
.opencode/plugins/load-dotenv.ts

Restart OpenCode to pick up the plugin.

Option 2: Global Plugin (Development)

To use this plugin across all projects:

# Copy plugin to global plugins directory
mkdir -p ~/.config/opencode/plugins
cp .opencode/plugins/load-dotenv.ts ~/.config/opencode/plugins/

# Copy dependencies package.json
mkdir -p ~/.config/opencode
cp .opencode/package.json ~/.config/opencode/package.json

Usage

Create .env files in your project root:

# Global defaults
echo "APP_NAME=MyApp" > .env
echo "DATABASE_HOST=localhost" >> .env

# Development overrides
echo "DEBUG=true" > .env.development
echo "LOG_LEVEL=debug" >> .env.development

# Production overrides
echo "LOG_LEVEL=warn" > .env.production
echo "API_URL=https://api.example.com" >> .env.production

The plugin automatically loads environment variables based on NODE_ENV:

| NODE_ENV | Files loaded (in priority order) | |-----------|-------------------------------| | development | .env.development.local, .env.development, .env.local, .env | | production | .env.production.local, .env.production, .env.local, .env | | test | .env.test.local, .env.test, .env.local, .env | | not set | Defaults to development |

Encryption

Encrypt secrets in your .env files:

# Install dotenvx CLI
bun install -g @dotenvx/dotenvx

# Generate encryption keys
dotenvx encrypt

# Set encrypted value
dotenvx set API_KEY "my-secret-key"

Create .env.keys with your private keys:

DOTENV_PRIVATE_KEY="your-private-key-here"
DOTENV_PRIVATE_KEY_PRODUCTION="your-production-key"

Important: Add .env.keys to .gitignore - never commit private keys.

Environment Files

File Loading Order

When NODE_ENV=development:

1. .env.development.local  (highest priority - never commit)
2. .env.development        (dev defaults - safe to commit)
3. .env.local            (local overrides - never commit)
4. .env                  (global defaults - safe to commit)

What to Commit

# ✅ Safe to commit (no secrets)
.env
.env.development
.env.production
.env.test

# ❌ Never commit (contains secrets)
.env.keys
.env.local
.env.*.local

Testing

Run Unit Tests

bun test test/load-dotenv.test.ts

Run E2E Tests

# Requires OpenCode CLI to be installed
bun test test/e2e-cli.test.ts

Run All Tests

bun test

Development

Project Structure

opencode-dotenv/
├── src/
│   └── load-dotenv.ts          # Main implementation
├── .opencode/
│   ├── package.json             # Plugin dependencies
│   └── plugins/
│       └── load-dotenv.ts      # Shim (loads plugin)
├── test/
│   ├── load-dotenv.test.ts     # Unit tests
│   ├── e2e-cli.test.ts        # E2E tests
│   └── fixtures/
│       ├── env-loading/         # Unit test fixtures
│       ├── encrypted-env/       # Encryption test fixtures
│       └── e2e/               # E2E test workspace
└── notes/
    └── opencode-dotenv-plugin.md # Implementation docs

Edit Plugin

  1. Edit src/load-dotenv.ts
  2. Run tests: bun test
  3. Restart OpenCode

The shim in .opencode/plugins/load-dotenv.ts automatically reloads changes.

Troubleshooting

Environment variables not loading:

  • Check .env files exist in project root
  • Verify plugin is in .opencode/plugins/
  • Run bun install in .opencode/ to install dependencies

Wrong environment loaded:

  • Check NODE_ENV: echo $NODE_ENV
  • Verify file names: .env.production not .env.prod

Encrypted values not decrypting:

  • Ensure .env.keys exists or DOTENV_PRIVATE_KEY is set
  • Check public/private key pair match

Publishing

Publish to npm with np

# 1. Install dependencies
bun install

# 2. Login to npm
npm login

# 3. Publish using np (automatically prompts for version bump)
bunx np --any-branch

Manual publish

If you prefer manual version control:

# Bump version (patch, minor, or major)
npm version patch

# Publish to npm
npm publish --access public

References