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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@simonwjackson/opencode-direnv

v2025.1211.9

Published

OpenCode plugin that automatically loads direnv environment variables at session start

Readme

opencode-direnv

Seamless direnv integration for OpenCode

npm version npm downloads License: MIT Bun TypeScript direnv OpenCode Plugin


Automatically load direnv environment variables when OpenCode sessions start.

InstallationUsageConfigurationAPIContributing

Demo


Overview

opencode-direnv automatically detects and loads .envrc files, ensuring your OpenCode sessions have access to the same environment variables you use in your terminal.

Key Features

  • Automatic Detection — Searches for .envrc from the project directory up to the git root
  • Seamless Integration — Applies environment variables to process.env for all subsequent commands
  • Smart Notifications — Toast alerts for blocked .envrc files and successful environment loads
  • Zero Configuration — Works out of the box with sensible defaults
  • Graceful Degradation — Silently skips if direnv is not installed or no .envrc exists

Requirements

| Dependency | Version | Required | Notes | |------------|---------|----------|-------| | OpenCode | >=1.0.0 | Yes | Plugin host environment | | direnv | >=2.0.0 | Yes | Must be available in PATH | | TypeScript | >=5.0.0 | Dev only | For building from source |


Installation

Via OpenCode Config

Just add the plugin to your configuration — OpenCode handles installation automatically.

Configuration

Add the plugin to your OpenCode configuration:

Project-level (./opencode.json):

{
  "plugin": ["@simonwjackson/opencode-direnv"]
}

Global (~/.config/opencode/opencode.json):

{
  "plugin": ["@simonwjackson/opencode-direnv"]
}

Usage

Basic Setup

  1. Ensure direnv is installed on your system
  2. Create or configure your .envrc file in your project
  3. Allow the .envrc file:
    direnv allow
  4. Start an OpenCode session — environment variables are loaded automatically

Use Cases

| Scenario | Description | |----------|-------------| | Nix Flakes | Automatically load use flake environments for reproducible development | | Project Secrets | Securely load API keys and credentials from .envrc | | Tool Versioning | Leverage direnv's layout functions for project-specific tooling | | Database Connections | Load connection strings and credentials per-project | | Cloud Configurations | Set AWS, GCP, or Azure credentials per-project |

Example .envrc

# Nix flake environment
use flake

# Project-specific variables
export DATABASE_URL="postgresql://localhost/myapp"
export API_KEY="your-api-key-here"

# Tool versions via asdf/mise
use asdf

How It Works

┌─────────────────────────────────────────────────────────────────┐
│                     Session Creation                            │
└─────────────────────────────────────────────────────────────────┘
                              │
                              ▼
┌─────────────────────────────────────────────────────────────────┐
│  1. Search for .envrc (project dir → git root → filesystem root)│
└─────────────────────────────────────────────────────────────────┘
                              │
                              ▼
┌─────────────────────────────────────────────────────────────────┐
│  2. Execute `direnv export json`                                │
└─────────────────────────────────────────────────────────────────┘
                              │
                              ▼
┌─────────────────────────────────────────────────────────────────┐
│  3. Parse JSON and apply to process.env                         │
└─────────────────────────────────────────────────────────────────┘
                              │
                              ▼
┌─────────────────────────────────────────────────────────────────┐
│  4. All bash commands inherit environment variables             │
└─────────────────────────────────────────────────────────────────┘

Behavior Details

  1. Session Start — Plugin hooks into OpenCode session creation
  2. Directory Traversal — Searches upward from project directory, stopping at git root
  3. Environment Export — Executes direnv export json for structured output
  4. Variable Application — Merges exported variables into process.env

Notifications

| Type | Condition | Message | |------|-----------|---------| | Warning | .envrc is blocked | Prompts user to run direnv allow | | Info | Environment loaded | Confirms successful environment application | | Silent | No direnv or .envrc | No notification displayed |


Limitations

| Limitation | Description | Workaround | |------------|-------------|------------| | Single Load | Environment loaded once per session | Start new session for .envrc changes | | Manual Allow | .envrc must be explicitly allowed | Run direnv allow (security feature) | | No Unload | Variables persist until session ends | Sessions are isolated by design |


Troubleshooting

Common Issues

Environment not loading

# Verify direnv is installed
which direnv

# Check if .envrc exists and is allowed
direnv status

Variables not available in commands

# Ensure .envrc is allowed
direnv allow

# Verify export works
direnv export json

Plugin not activating

  • Confirm plugin is listed in opencode.json
  • Check OpenCode logs for plugin initialization errors

Contributing

Contributions are welcome. Please read our contributing guidelines before submitting a pull request.

# Clone the repository
git clone https://github.com/simonwjackson/opencode-direnv.git
cd opencode-direnv

# Install dependencies
bun install

# Build
bun run build

License

This project is licensed under the MIT License.


Built with

TypeScript Bun


Made with care by @simonwjackson