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

shgpt

v1.0.2

Published

A simple ChatGPT gateway module for Node.js with streaming support

Readme

ShellGPT

A simple ChatGPT gateway module for Node.js with streaming support. ShellGPT provides an easy-to-use CLI interface for interacting with OpenAI's ChatGPT API, featuring automatic API key management and conversation history.

Features

  • 🤖 Interactive Chat Sessions - Start a conversation and chat naturally
  • 📡 Real-time Streaming - See responses as they're generated
  • 🔑 Automatic API Key Management - Secure storage and validation
  • 📚 Conversation History - View and manage chat history
  • ⚙️ Configurable Options - Customize model, temperature, and tokens
  • 🛠️ Modular Architecture - Well-structured, maintainable code

Installation

npm install

Usage

As a CLI Tool

Interactive Chat Session

# Start an interactive chat session
npm start

# Or with custom options
npm start -- --model gpt-4 --temperature 0.5

Send a Single Message

# Send a single message
npm start send "What is the capital of France?"

# With custom options
npm start send "Explain quantum physics" --model gpt-4 --temperature 0.3

Manage Configuration

# Show current configuration
npm start config --show

# Clear saved configuration
npm start config --clear

View History

# Show conversation history
npm start history

# Clear conversation history
npm start history --clear

As a Node.js Module

const ShellGPT = require('./index.js');

async function example() {
    const shellGPT = new ShellGPT();
    
    // Send a single message
    const response = await shellGPT.chat("Hello, how are you?");
    console.log(response);
    
    // Start interactive session
    await shellGPT.startChat();
}

CLI Commands

Global Options

  • -m, --model <model> - Specify the model to use (default: gpt-3.5-turbo)
  • -t, --temperature <temperature> - Set temperature (0-2, default: 0.7)
  • --max-tokens <tokens> - Set maximum tokens (default: 1000)

Commands

chat

Start an interactive chat session.

shgpt chat
shgpt chat --model gpt-4 --temperature 0.5

send <message>

Send a single message to ChatGPT.

shgpt send "What is the weather like?"
shgpt send "Explain machine learning" --model gpt-4

config

Manage configuration.

shgpt config --show    # Show current configuration
shgpt config --clear   # Clear saved configuration

history

Manage conversation history.

shgpt history          # Show conversation history
shgpt history --clear  # Clear conversation history

Interactive Session Commands

When in an interactive chat session, you can use these commands:

  • clear - Clear conversation history
  • history - Show conversation history
  • help - Show available commands
  • quit or exit - Exit the chat session

Configuration

ShellGPT automatically manages your OpenAI API key:

  1. First Run: You'll be prompted to enter your OpenAI API key
  2. Validation: The key is validated before being saved
  3. Storage: The key is securely stored in ~/.shgpt/config.json
  4. Subsequent Runs: The saved key is automatically loaded

API Key Setup

  1. Get your API key from OpenAI Platform
  2. Run ShellGPT for the first time
  3. Enter your API key when prompted
  4. The key will be validated and saved for future use

Project Structure

shellgpt/
├── src/
│   ├── auth/
│   │   └── AuthManager.js      # API key management and validation
│   ├── chat/
│   │   └── ChatManager.js      # Chat functionality and streaming
│   ├── cli/
│   │   └── InteractiveSession.js # Interactive CLI session
│   ├── config/
│   │   └── ConfigManager.js    # Configuration file management
│   └── core/
│       └── ShellGPT.js         # Main orchestrator class
├── cli.js                      # CLI entry point with Commander.js
├── index.js                    # Module entry point
├── package.json                # Dependencies and metadata
└── README.md                   # This file

Dependencies

  • openai - OpenAI API client
  • commander - CLI argument parsing
  • readline - Interactive input handling
  • fs, path, os - File system and OS utilities

Error Handling

ShellGPT includes comprehensive error handling:

  • Invalid API Key: Automatic validation and retry
  • Network Errors: Graceful error messages
  • Configuration Issues: Clear guidance for setup
  • Graceful Shutdown: Proper cleanup on exit

Security

  • API keys are stored locally in user's home directory
  • Keys are validated before storage
  • No keys are logged or displayed
  • Configuration files use proper permissions

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

License

ISC License - see LICENSE file for details.