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-nostr-dm

v0.1.2

Published

OpenCode plugin for Nostr DM integration (NIP-04)

Downloads

261

Readme

OpenCode Nostr DM Plugin

Chat with OpenCode AI via Nostr encrypted DMs (NIP-04).

Quick Install (Ubuntu/Debian Server)

curl -fsSL https://raw.githubusercontent.com/happylemonprogramming/opencode-nostr-dm/main/install.sh | bash

This one command will:

  1. Install Node.js (for nostr-tools dependency)
  2. Install OpenCode
  3. Install nak (key generator)
  4. Prompt for your private key (or press Enter to generate a new one)
  5. Configure the plugin
  6. Set up systemd service (runs 24/7, survives reboots)
  7. Start the server automatically
  8. Print your npub

That's it! Send a DM to the npub shown at the end from any Nostr client (Primal, Damus, Amethyst, etc.) and get AI responses!

Useful commands:

systemctl status opencode    # Check status
journalctl -u opencode -f    # View logs
systemctl restart opencode   # Restart service

Manual Installation

1. Install OpenCode

curl -fsSL https://opencode.ai/install | bash
source ~/.bashrc

2. Install Node.js & nostr-tools

curl -fsSL https://deb.nodesource.com/setup_22.x | bash -
apt-get install -y nodejs
cd ~/.config/opencode
npm init -y
npm install nostr-tools

3. Install nak & Generate Keypair

curl -sSL https://raw.githubusercontent.com/fiatjaf/nak/master/install.sh | sh
export PATH="$HOME/.local/bin:$PATH"

NSEC=$(nak key generate)
HEX_PUB=$(nak key public $NSEC)
NPUB=$(echo $HEX_PUB | nak encode npub)
echo "Your npub: $NPUB"

4. Create Config Files

mkdir -p ~/.config/opencode/plugins

cat > ~/.config/opencode/opencode.json << 'EOF'
{
  "$schema": "https://opencode.ai/config.json",
  "model": "opencode/big-pickle"
}
EOF

cat > ~/.config/opencode/.env << EOF
NOSTR_PRIVATE_KEY=$NSEC
NOSTR_RELAYS=wss://relay.primal.net,wss://nos.lol,wss://relay.damus.io
NOSTR_DEBUG=true
EOF

5. Download Plugin

curl -fsSL https://raw.githubusercontent.com/happylemonprogramming/opencode-nostr-dm/main/plugin.ts \
  -o ~/.config/opencode/plugins/nostr-dm.ts

6. Start & Test

opencode serve --print-logs
# In another terminal:
curl http://127.0.0.1:4096/event

Configuration

| Variable | Required | Default | Description | |----------|----------|---------|-------------| | NOSTR_PRIVATE_KEY | Yes | - | Private key (nsec1... or hex) | | NOSTR_RELAYS | No | 3 default relays | Comma-separated relay URLs | | NOSTR_DEFAULT_MODEL | No | opencode/big-pickle | Default AI model (free) | | NOSTR_DEBUG | No | false | Enable debug logging |

Edit config: nano ~/.config/opencode/.env

Systemd Service (24/7 Operation)

The quick install automatically sets up a systemd service. If you used manual installation, run:

cat > /etc/systemd/system/opencode.service << 'EOF'
[Unit]
Description=OpenCode Nostr DM Server
After=network.target

[Service]
Type=simple
User=root
Environment="PATH=/root/.local/bin:/usr/local/bin:/usr/bin:/bin"
WorkingDirectory=/root
ExecStart=/root/.local/bin/opencode serve
ExecStartPost=/bin/bash -c 'sleep 3 && curl -s http://127.0.0.1:4096/event > /dev/null'
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target
EOF

systemctl daemon-reload
systemctl enable opencode
systemctl start opencode

Service commands:

systemctl status opencode     # Check status
journalctl -u opencode -f     # View logs (follow mode)
systemctl restart opencode    # Restart after config changes
systemctl stop opencode       # Stop the service

How It Works

  1. Plugin subscribes to NIP-04 DMs tagged to your server's pubkey
  2. When a DM arrives, it decrypts the message and sends it to OpenCode AI
  3. OpenCode AI generates a response
  4. Plugin encrypts and sends the response back via Nostr DM

Each sender gets their own persistent session (until server restart).

Features

  • NIP-04 encrypted direct messages
  • Automatic session management (one session per sender)
  • /new command support - send /new to clear context and start fresh
  • Automatic session recovery if session becomes invalid
  • Multi-relay support
  • Free AI models (no API keys needed)
  • Debug logging

Commands

| Command | Description | |---------|-------------| | /new | Clear current session and start a fresh conversation | | /models | Change AI model - prompts for model name, reverts if invalid |

Note: The default model (opencode/big-pickle) is free. To use paid models (e.g., anthropic/claude-sonnet-4-20250514), add the appropriate API key to your .env file (see .env.example).

Troubleshooting

Plugin doesn't load:

  • Restart OpenCode and trigger with curl http://127.0.0.1:4096/event
  • Check logs for [NostrDM] messages

No DMs received:

  • Verify NOSTR_PRIVATE_KEY is set: cat ~/.config/opencode/.env
  • Enable debug: NOSTR_DEBUG=true
  • Check you're DMing the correct npub

License

MIT

Links