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

@promethean-os/opencode-client

v1.0.2

Published

CLI client for OpenCode plugins and tools

Readme

OpenCode Client

TypeScript client for OpenCode with comprehensive session management, event processing, and context indexing capabilities.

Installation

pnpm add @promethean-os/opencode-client

Quick Start

import { spawnSession, listSessions, sendPrompt, listEvents } from '@promethean-os/opencode-client';

// Create a new session
const session = await spawnSession.execute({
  title: 'Development Session',
  message: 'Start working on TypeScript project',
});

const { session: sessionData } = JSON.parse(session);
console.log('Session created:', sessionData.id);

// Send a message to the session
const message = await sendPrompt.execute({
  sessionId: sessionData.id,
  content: 'Analyze the codebase for performance issues',
  type: 'instruction',
});

console.log('Message sent:', JSON.parse(message));

// List all active sessions
const sessions = await listSessions.execute({ limit: 10 });
console.log('Active sessions:', JSON.parse(sessions));

Key Features

🚀 Session Management

  • Create, list, and manage OpenCode sessions
  • Real-time session status tracking
  • Interactive messaging within sessions
  • Session lifecycle management

📊 Event Processing

  • Comprehensive event tracking and querying
  • Real-time event streaming
  • Event filtering and aggregation
  • Historical event analysis

🔍 Context Indexing

  • Full-text search across sessions, events, and messages
  • Semantic search capabilities
  • Context compilation for analysis
  • Intelligent result ranking

🔧 TypeScript-First Design

  • Full type safety with comprehensive type definitions
  • Proper error handling and validation
  • Modern ES6+ patterns and practices

📋 Plugin System

  • Extensible architecture for custom functionality
  • Built-in plugins for common operations
  • Tool registration and execution
  • Cross-plugin communication

Core Tools

| Tool | Purpose | Example | | ---------------- | ----------------------------- | -------------------------------------------------------- | | spawnSession | Create new session | spawnSession.execute({title, message}) | | listSessions | List sessions | listSessions.execute({limit: 20}) | | sendPrompt | Send message to session | sendPrompt.execute({sessionId, content}) | | listMessages | Get session messages | listMessages.execute({sessionId, limit: 50}) | | closeSession | Close session | closeSession.execute({sessionId}) | | listEvents | List system events | listEvents.execute({limit: 100}) | | searchContext | Search across content | searchContext.execute({query, limit: 20}) | | compileContext | Compile comprehensive context | compileContext.execute({query, includeSessions: true}) |

Documentation

Core Documentation

Additional Documentation

Setup & Configuration

Prerequisites

  • Node.js 18+ and TypeScript 5+
  • OpenCode server running locally or accessible via network
  • pnpm package manager

Basic Configuration

// Configure OpenCode server URL (optional, defaults to localhost:4096)
process.env.OPENCODE_SERVER_URL = 'http://localhost:4096';

// Enable debug logging (optional)
process.env.DEBUG = 'opencode-client:*';

// Set authentication token (if required)
process.env.OPENCODE_AUTH_TOKEN = 'your-auth-token';

Common Usage Patterns

Session Management

async function manageSessions() {
  // Create multiple sessions
  const sessions = await Promise.all([
    spawnSession.execute({
      title: 'Code Review',
      message: 'Review authentication module',
    }),
    spawnSession.execute({
      title: 'Documentation',
      message: 'Update API documentation',
    }),
  ]);

  // List all active sessions
  const activeSessions = await listSessions.execute({ limit: 20 });
  console.log('Active sessions:', JSON.parse(activeSessions));
}

Event Processing

async function processEvents() {
  // Get recent events
  const events = await listEvents.execute({
    limit: 100,
    eventType: 'session.created',
  });

  const eventData = JSON.parse(events);
  eventData.events.forEach((event) => {
    console.log(`Event: ${event.type} at ${new Date(event.timestamp)}`);
  });
}

Context Search

async function searchAndAnalyze() {
  // Search for specific content
  const searchResults = await searchContext.execute({
    query: 'TypeScript compilation errors',
    limit: 20,
    includeMessages: true,
    includeSessions: true,
  });

  // Compile comprehensive context
  const context = await compileContext.execute({
    query: 'security vulnerabilities',
    includeSessions: true,
    includeEvents: true,
    includeMessages: true,
    limit: 500,
  });

  return {
    search: JSON.parse(searchResults),
    context: JSON.parse(context),
  };
}

Development

Building from Source

# Clone repository
git clone https://github.com/riatzukiza/promethean.git
cd promethean/packages/opencode-client

# Install dependencies
pnpm install

# Build the package
pnpm build

# Run in development mode
pnpm dev

Running Tests

# Run all tests
pnpm test

# Run with coverage
pnpm test --coverage

# Watch mode
pnpm test --watch

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Ensure build passes
  6. Submit a pull request

For detailed development guidelines, see the Development Guide.

Support and Troubleshooting

Common Issues

  1. TypeScript Compilation Errors: See TypeScript Compilation Fixes
  2. Connection Issues: Ensure OpenCode server is running on port 4096
  3. Session Not Found: Verify session ID is correct and session hasn't expired
  4. Search Returns No Results: Check query syntax and available content

Getting Help

  • Check the Troubleshooting Guide for common issues
  • Review the API Reference for detailed usage
  • Enable debug logging: process.env.DEBUG = 'opencode-client:*'
  • Create an issue with detailed error information

Health Check

import { listSessions, listEvents } from '@promethean-os/opencode-client';

async function healthCheck() {
  try {
    // Check session connectivity
    const sessions = await listSessions.execute({ limit: 1 });
    console.log('Sessions API healthy:', JSON.parse(sessions));

    // Check event connectivity
    const events = await listEvents.execute({ limit: 1 });
    console.log('Events API healthy:', JSON.parse(events));

    console.log('✅ All systems operational');
  } catch (error) {
    console.error('❌ Health check failed:', error.message);
  }
}

healthCheck();

Architecture Overview

┌─────────────────┐    ┌──────────────────┐    ┌─────────────────┐
│   CLI Client    │───▶│  OpenCode API    │───▶│  Session Store  │
│                 │    │                  │    │                 │
│ • sessions      │    │ • Sessions       │    │ • Session Data  │
│ • events        │    │ • Events         │    │ • Event History │
│ • messages      │    │ • Messages       │    │ • Message Log   │
│ • indexer       │    │ • Indexer        │    │ • Search Index  │
└─────────────────┘    └──────────────────┘    └─────────────────┘
         │                       │                       │
         │              ┌──────────────────┐            │
         └──────────────▶│  Plugin System   │◀───────────┘
                        │                  │
                        │ • Agent Mgmt     │
                        │ • Cache          │
                        │ • Events         │
                        │ • Custom         │
                        └──────────────────┘

License

This project is licensed under GPL-3.0 License. See LICENSE file for details.

Related Packages

  • @promethean-os/persistence: Data persistence layer
  • @opencode-ai/plugin: OpenCode plugin framework
  • @opencode-ai/sdk: OpenCode SDK
  • @promethean-os/kanban: Task management and workflow integration