@ebowwa/claudecodehistory 1.2.1 → 1.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/LICENSE +21 -0
  2. package/README +266 -0
  3. package/package.json +2 -1
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 ebowwa
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README ADDED
@@ -0,0 +1,266 @@
1
+ # @ebowwa/claudecodehistory
2
+
3
+ A TypeScript library for accessing and analyzing Claude Code conversation history with smart filtering and pagination.
4
+
5
+ ## Features
6
+
7
+ This library provides a `ClaudeCodeHistoryService` class that offers:
8
+
9
+ - **Conversation History Access** - Read Claude Code's `.jsonl` history files from `~/.claude/projects/`
10
+ - **Smart Filtering** - Filter by date range, project, session, and message types
11
+ - **Pagination Support** - Efficiently handle large datasets with limit/offset
12
+ - **Timezone Intelligence** - Automatic timezone detection with manual override support
13
+ - **Content Search** - Search conversation content across all projects
14
+ - **TypeScript Types** - Full TypeScript support with exported types
15
+
16
+ ## Installation
17
+
18
+ ```bash
19
+ bun install @ebowwa/claudecodehistory
20
+ ```
21
+
22
+ ## Quick Start
23
+
24
+ ```typescript
25
+ import { ClaudeCodeHistoryService } from '@ebowwa/claudecodehistory';
26
+
27
+ const service = new ClaudeCodeHistoryService();
28
+
29
+ // List all projects
30
+ const projects = await service.listProjects();
31
+ console.log(projects);
32
+ // [
33
+ // {
34
+ // projectPath: '/Users/username/code/my-project',
35
+ // sessionCount: 15,
36
+ // messageCount: 342,
37
+ // lastActivityTime: '2025-01-15T10:30:00.000Z'
38
+ // }
39
+ // ]
40
+
41
+ // Get conversation history with pagination
42
+ const history = await service.getConversationHistory({
43
+ limit: 20,
44
+ offset: 0,
45
+ messageTypes: ['user'], // Only user messages (default)
46
+ timezone: 'Asia/Tokyo'
47
+ });
48
+ console.log(history.entries);
49
+ console.log(history.pagination);
50
+ // {
51
+ // total_count: 150,
52
+ // limit: 20,
53
+ // offset: 0,
54
+ // has_more: true
55
+ // }
56
+
57
+ // Search conversations
58
+ const results = await service.searchConversations('API integration', {
59
+ limit: 30,
60
+ projectPath: '/Users/username/code/my-project',
61
+ startDate: '2025-01-01',
62
+ endDate: '2025-01-31'
63
+ });
64
+ ```
65
+
66
+ ## API
67
+
68
+ ### `ClaudeCodeHistoryService`
69
+
70
+ Main service class for accessing Claude Code history.
71
+
72
+ #### Constructor
73
+
74
+ ```typescript
75
+ const service = new ClaudeCodeHistoryService();
76
+ ```
77
+
78
+ Automatically uses `~/.claude` as the data directory.
79
+
80
+ #### Methods
81
+
82
+ ##### `getConversationHistory(options)`
83
+
84
+ Get paginated conversation history.
85
+
86
+ ```typescript
87
+ const result = await service.getConversationHistory({
88
+ sessionId?: string, // Filter by specific session
89
+ startDate?: string, // Start date (e.g., "2025-01-01")
90
+ endDate?: string, // End date (e.g., "2025-01-31")
91
+ limit?: number, // Max entries (default: 20)
92
+ offset?: number, // Skip entries (default: 0)
93
+ messageTypes?: Array<'user' | 'assistant' | 'system' | 'result'>,
94
+ timezone?: string // Timezone (e.g., "Asia/Tokyo", "UTC")
95
+ });
96
+ ```
97
+
98
+ Returns: `PaginatedConversationResponse`
99
+
100
+ ##### `searchConversations(query, options)`
101
+
102
+ Search conversation content.
103
+
104
+ ```typescript
105
+ const results = await service.searchConversations('search query', {
106
+ limit?: number,
107
+ projectPath?: string,
108
+ startDate?: string,
109
+ endDate?: string,
110
+ timezone?: string
111
+ });
112
+ ```
113
+
114
+ Returns: `ConversationEntry[]`
115
+
116
+ ##### `listProjects()`
117
+
118
+ List all projects with conversation history.
119
+
120
+ ```typescript
121
+ const projects = await service.listProjects();
122
+ ```
123
+
124
+ Returns: `ProjectInfo[]`
125
+
126
+ ##### `listSessions(options)`
127
+
128
+ List conversation sessions.
129
+
130
+ ```typescript
131
+ const sessions = await service.listSessions({
132
+ projectPath?: string,
133
+ startDate?: string,
134
+ endDate?: string,
135
+ timezone?: string
136
+ });
137
+ ```
138
+
139
+ Returns: `SessionInfo[]`
140
+
141
+ ## Types
142
+
143
+ ```typescript
144
+ interface ConversationEntry {
145
+ sessionId: string;
146
+ timestamp: string;
147
+ type: 'user' | 'assistant' | 'system' | 'result';
148
+ content: string;
149
+ projectPath: string;
150
+ uuid: string;
151
+ formattedTime?: string;
152
+ timeAgo?: string;
153
+ localDate?: string;
154
+ metadata?: {
155
+ usage?: any;
156
+ totalCostUsd?: number;
157
+ numTurns?: number;
158
+ durationMs?: number;
159
+ isError?: boolean;
160
+ errorType?: string;
161
+ model?: string;
162
+ requestId?: string;
163
+ };
164
+ }
165
+
166
+ interface PaginatedConversationResponse {
167
+ entries: ConversationEntry[];
168
+ pagination: {
169
+ total_count: number;
170
+ limit: number;
171
+ offset: number;
172
+ has_more: boolean;
173
+ };
174
+ }
175
+
176
+ interface ProjectInfo {
177
+ projectPath: string;
178
+ sessionCount: number;
179
+ messageCount: number;
180
+ lastActivityTime: string;
181
+ }
182
+
183
+ interface SessionInfo {
184
+ sessionId: string;
185
+ projectPath: string;
186
+ startTime: string;
187
+ endTime: string;
188
+ messageCount: number;
189
+ userMessageCount: number;
190
+ assistantMessageCount: number;
191
+ }
192
+ ```
193
+
194
+ ## Smart Features
195
+
196
+ ### Message Type Filtering
197
+
198
+ Default behavior only returns user messages to reduce data volume:
199
+
200
+ ```typescript
201
+ // Only user messages (default)
202
+ await service.getConversationHistory();
203
+
204
+ // User and assistant messages
205
+ await service.getConversationHistory({
206
+ messageTypes: ['user', 'assistant']
207
+ });
208
+
209
+ // All message types
210
+ await service.getConversationHistory({
211
+ messageTypes: ['user', 'assistant', 'system', 'result']
212
+ });
213
+ ```
214
+
215
+ ### Timezone Support
216
+
217
+ Automatic timezone detection with manual override:
218
+
219
+ ```typescript
220
+ // Auto-detect system timezone
221
+ await service.getConversationHistory();
222
+
223
+ // Explicit timezone
224
+ await service.getConversationHistory({
225
+ timezone: 'Asia/Tokyo'
226
+ });
227
+ ```
228
+
229
+ ### Date Filtering
230
+
231
+ Smart date normalization with timezone awareness:
232
+
233
+ ```typescript
234
+ await service.getConversationHistory({
235
+ startDate: '2025-01-01', // Automatically normalized to proper timezone bounds
236
+ endDate: '2025-01-31',
237
+ timezone: 'America/New_York'
238
+ });
239
+ ```
240
+
241
+ ## Example MCP Server
242
+
243
+ This repository includes an example MCP server in the `example/` directory that demonstrates how to use this library to build an MCP server.
244
+
245
+ See [example/README.md](./example/README.md) for details.
246
+
247
+ ## Development
248
+
249
+ ```bash
250
+ # Clone repository
251
+ git clone https://github.com/ebowwa/claude-code-history-mcp.git
252
+ cd claude-code-history-mcp
253
+
254
+ # Install dependencies
255
+ bun install
256
+
257
+ # Build
258
+ bun run build
259
+
260
+ # Run tests
261
+ bun test
262
+ ```
263
+
264
+ ## License
265
+
266
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ebowwa/claudecodehistory",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "description": "TypeScript library for accessing and analyzing Claude Code conversation history",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -14,6 +14,7 @@
14
14
  "files": [
15
15
  "dist/",
16
16
  "example/",
17
+ "README",
17
18
  "README.md",
18
19
  "LICENSE"
19
20
  ],