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

@ebowwa/claudecodehistory

v1.2.3

Published

TypeScript library for accessing and analyzing Claude Code conversation history

Readme

@ebowwa/claudecodehistory

A TypeScript library for accessing and analyzing Claude Code conversation history with smart filtering and pagination.

Features

This library provides a ClaudeCodeHistoryService class that offers:

  • Conversation History Access - Read Claude Code's .jsonl history files from ~/.claude/projects/
  • Smart Filtering - Filter by date range, project, session, and message types
  • Pagination Support - Efficiently handle large datasets with limit/offset
  • Timezone Intelligence - Automatic timezone detection with manual override support
  • Content Search - Search conversation content across all projects
  • TypeScript Types - Full TypeScript support with exported types

Installation

bun install @ebowwa/claudecodehistory

Quick Start

import { ClaudeCodeHistoryService } from '@ebowwa/claudecodehistory';

const service = new ClaudeCodeHistoryService();

// List all projects
const projects = await service.listProjects();
console.log(projects);
// [
//   {
//     projectPath: '/Users/username/code/my-project',
//     sessionCount: 15,
//     messageCount: 342,
//     lastActivityTime: '2025-01-15T10:30:00.000Z'
//   }
// ]

// Get conversation history with pagination
const history = await service.getConversationHistory({
  limit: 20,
  offset: 0,
  messageTypes: ['user'], // Only user messages (default)
  timezone: 'Asia/Tokyo'
});
console.log(history.entries);
console.log(history.pagination);
// {
//   total_count: 150,
//   limit: 20,
//   offset: 0,
//   has_more: true
// }

// Search conversations
const results = await service.searchConversations('API integration', {
  limit: 30,
  projectPath: '/Users/username/code/my-project',
  startDate: '2025-01-01',
  endDate: '2025-01-31'
});

API

ClaudeCodeHistoryService

Main service class for accessing Claude Code history.

Constructor

const service = new ClaudeCodeHistoryService();

Automatically uses ~/.claude as the data directory.

Methods

getConversationHistory(options)

Get paginated conversation history.

const result = await service.getConversationHistory({
  sessionId?: string,        // Filter by specific session
  startDate?: string,        // Start date (e.g., "2025-01-01")
  endDate?: string,          // End date (e.g., "2025-01-31")
  limit?: number,            // Max entries (default: 20)
  offset?: number,           // Skip entries (default: 0)
  messageTypes?: Array<'user' | 'assistant' | 'system' | 'result'>,
  timezone?: string          // Timezone (e.g., "Asia/Tokyo", "UTC")
});

Returns: PaginatedConversationResponse

searchConversations(query, options)

Search conversation content.

const results = await service.searchConversations('search query', {
  limit?: number,
  projectPath?: string,
  startDate?: string,
  endDate?: string,
  timezone?: string
});

Returns: ConversationEntry[]

listProjects()

List all projects with conversation history.

const projects = await service.listProjects();

Returns: ProjectInfo[]

listSessions(options)

List conversation sessions.

const sessions = await service.listSessions({
  projectPath?: string,
  startDate?: string,
  endDate?: string,
  timezone?: string
});

Returns: SessionInfo[]

getCurrentSession()

Get information about the currently active Claude Code session.

const currentSession = await service.getCurrentSession();

Returns: CurrentSessionInfo | null

Notes:

  • Returns null if no active session is found
  • Uses a best-effort approach to detect the current session by checking running processes and recently modified session files
  • The detected session may not always be the actual active session if multiple Claude Code instances are running
getSessionByPid(pid)

Get session information by process ID.

const sessionInfo = await service.getSessionByPid(12345);

Parameters:

  • pid (number) - Process ID of the Claude Code session

Returns: SessionProcessInfo | null

Notes:

  • Returns null if no session is found for the given PID
  • Cross-references running processes with session history files
  • Useful for correlating active Claude Code processes with their conversation history
listAllSessionUuids()

List all session UUIDs across all projects.

const uuids = await service.listAllSessionUuids();
// Returns: ["uuid-1", "uuid-2", "uuid-3", ...]

Returns: string[]

Notes:

  • Returns a flat array of all session UUIDs
  • Useful for bulk operations or generating session inventories
  • Does not include project path information - use listSessions() for detailed session metadata

Types

interface ConversationEntry {
  sessionId: string;
  timestamp: string;
  type: 'user' | 'assistant' | 'system' | 'result';
  content: string;
  projectPath: string;
  uuid: string;
  formattedTime?: string;
  timeAgo?: string;
  localDate?: string;
  metadata?: {
    usage?: any;
    totalCostUsd?: number;
    numTurns?: number;
    durationMs?: number;
    isError?: boolean;
    errorType?: string;
    model?: string;
    requestId?: string;
  };
}

interface PaginatedConversationResponse {
  entries: ConversationEntry[];
  pagination: {
    total_count: number;
    limit: number;
    offset: number;
    has_more: boolean;
  };
}

interface ProjectInfo {
  projectPath: string;
  sessionCount: number;
  messageCount: number;
  lastActivityTime: string;
}

interface SessionInfo {
  sessionId: string;
  projectPath: string;
  startTime: string;
  endTime: string;
  messageCount: number;
  userMessageCount: number;
  assistantMessageCount: number;
}

interface CurrentSessionInfo {
  uuid: string;
  projectPath: string;
  pid?: number;
  command?: string;
}

interface SessionProcessInfo {
  uuid: string;
  projectPath: string;
  pid: number;
  command: string;
  startTime?: string;
  messageCount?: number;
}

Smart Features

Message Type Filtering

Default behavior only returns user messages to reduce data volume:

// Only user messages (default)
await service.getConversationHistory();

// User and assistant messages
await service.getConversationHistory({
  messageTypes: ['user', 'assistant']
});

// All message types
await service.getConversationHistory({
  messageTypes: ['user', 'assistant', 'system', 'result']
});

Timezone Support

Automatic timezone detection with manual override:

// Auto-detect system timezone
await service.getConversationHistory();

// Explicit timezone
await service.getConversationHistory({
  timezone: 'Asia/Tokyo'
});

Date Filtering

Smart date normalization with timezone awareness:

await service.getConversationHistory({
  startDate: '2025-01-01',  // Automatically normalized to proper timezone bounds
  endDate: '2025-01-31',
  timezone: 'America/New_York'
});

Example MCP Server

This repository includes an example MCP server in the example/ directory that demonstrates how to use this library to build an MCP server.

See example/README.md for details.

Development

# Clone repository
git clone https://github.com/ebowwa/claude-code-history-mcp.git
cd claude-code-history-mcp

# Install dependencies
bun install

# Build
bun run build

# Run tests
bun test

License

MIT