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

@raylin01/gemini-client

v0.2.2

Published

Node.js client for controlling Gemini CLI with stream-json session support.

Readme

@raylin01/gemini-client

Node.js client for Gemini CLI with both the raw stream-json event API and a higher-level structured session/turn API.

Install

npm install @raylin01/gemini-client

Requirements

  • Node.js 18+
  • Gemini CLI installed and authenticated

Quickstart

import { GeminiClient } from '@raylin01/gemini-client';

const client = await GeminiClient.init({
  cwd: process.cwd(),
  outputFormat: 'stream-json'
});

const turn = client.send('Summarize this repository.');

for await (const update of turn.updates()) {
  if (update.kind === 'output' && update.snapshot.currentOutputKind === 'text') {
    process.stdout.write(update.snapshot.text);
  }
}

const completed = await turn.done;
console.log('\nSession:', completed.sessionId);

const next = client.send('Now propose 3 refactors.');
console.log('Status:', (await next.done).status);

await client.close();

Structured API

  • GeminiClient.init(options) starts the CLI and returns a StructuredGeminiClient
  • client.send(input, options?) returns a turn handle immediately
  • turn.current(), turn.history(), turn.updates(), and turn.done expose normalized state
  • client.getCurrentTurn() and client.getHistory() expose session-level state

Raw Event API

If you need direct access to the Gemini stream-json protocol, the original new GeminiClient(...) API is unchanged.

Event Model

  • ready: session established with sessionId
  • event: raw stream-json event
  • message_delta: assistant token deltas
  • tool_use, tool_result: tool lifecycle
  • result: run completion
  • error_event: structured Gemini warning/error event
  • stderr, stdout, exit

API

new GeminiClient(options)

  • cwd, geminiPath, env, args
  • model, outputFormat, approvalMode, yolo
  • sandbox/tool include options

await GeminiClient.init(options)

  • returns a StructuredGeminiClient
  • keeps the original raw client available at client.raw

Core methods

  • startSession(prompt, runOptions?)
  • continueSession(prompt, runOptions?)
  • sendMessage(prompt, runOptions?)
  • interrupt(signal?)
  • shutdown()

Session helpers

  • listSessions()
  • resolveSession(identifier)
  • deleteSession(identifier)

And utility subpath export:

  • @raylin01/gemini-client/sessions

Session Browser Examples

Gemini sessions can be browsed with the read-only helpers exported from the sessions subpath.

import {
  listGeminiSessionSummaries,
  readGeminiSessionRecord
} from '@raylin01/gemini-client/sessions';

const summaries = await listGeminiSessionSummaries({
  projectPath: process.cwd()
});

const latest = summaries[0];
if (latest) {
  const record = await readGeminiSessionRecord(latest.id, {
    projectPath: process.cwd()
  });

  console.log('Title:', record.summary.summary);
  console.log('Normalized messages:', record.transcript.length);
  console.log('Raw event count:', record.rawMessages.length);
}

Use record.transcript when you want provider-neutral history, and record.rawSession or record.rawMessages when you need Gemini-native details.

Examples

See /examples:

  • basic.ts
  • events.ts
  • error-handling.ts

Troubleshooting

  • Use stream-json output for robust structured integration.
  • If no sessions are found, verify ~/.gemini/tmp/<project-hash>/chats exists.

Versioning

This package uses independent semver releases.

Used by DisCode

DisCode uses this package as a real-world integration example:

License

ISC