claude-code-types 0.1.0
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.
- package/LICENSE +21 -0
- package/README.md +79 -0
- package/index.d.ts +535 -0
- package/package.json +30 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Pedro Carvalho
|
|
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.md
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# claude-code-types
|
|
2
|
+
|
|
3
|
+
TypeScript type definitions for [Claude Code](https://docs.anthropic.com/en/docs/claude-code) chat history JSONL files.
|
|
4
|
+
|
|
5
|
+
Claude Code stores conversation history at `~/.claude/projects/<project-slug>/<session-id>.jsonl`. Each line is a JSON object. This package provides full type coverage for all entry types.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install claude-code-types
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import type { TranscriptEntry } from 'claude-code-types';
|
|
17
|
+
import { readFileSync } from 'fs';
|
|
18
|
+
|
|
19
|
+
const entries: TranscriptEntry[] = readFileSync(path, 'utf-8')
|
|
20
|
+
.split('\n')
|
|
21
|
+
.filter(Boolean)
|
|
22
|
+
.map(line => JSON.parse(line) as TranscriptEntry);
|
|
23
|
+
|
|
24
|
+
for (const entry of entries) {
|
|
25
|
+
switch (entry.type) {
|
|
26
|
+
case 'user':
|
|
27
|
+
console.log(entry.message.content);
|
|
28
|
+
break;
|
|
29
|
+
case 'assistant':
|
|
30
|
+
console.log(entry.message.model);
|
|
31
|
+
break;
|
|
32
|
+
case 'system':
|
|
33
|
+
console.log(entry.subtype);
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Entry types
|
|
40
|
+
|
|
41
|
+
| `type` | Interface | Description |
|
|
42
|
+
|--------|-----------|-------------|
|
|
43
|
+
| `user` | `UserEntry` | Human messages, tool results |
|
|
44
|
+
| `assistant` | `AssistantEntry` | Model responses, tool calls |
|
|
45
|
+
| `system` | `SystemEntry` | API errors, compaction, durations |
|
|
46
|
+
| `file-history-snapshot` | `FileHistorySnapshotEntry` | Undo/restore tracking |
|
|
47
|
+
| `pr-link` | `PrLinkEntry` | Linked pull requests |
|
|
48
|
+
| `progress` | `ProgressEntry` | Streaming subagent updates |
|
|
49
|
+
| `queue-operation` | `QueueOperationEntry` | Queued user messages |
|
|
50
|
+
| `saved_hook_context` | `SavedHookContextEntry` | Hook execution context |
|
|
51
|
+
| `summary` | `SummaryEntry` | Conversation summaries |
|
|
52
|
+
|
|
53
|
+
## Publishing
|
|
54
|
+
|
|
55
|
+
This package is published to npm automatically via GitHub Actions when a version tag is pushed.
|
|
56
|
+
|
|
57
|
+
### Releasing a new version
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
npm version patch # or minor / major
|
|
61
|
+
git push --follow-tags
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
The `publish.yml` workflow triggers on `v*` tags, runs typecheck, and publishes with provenance.
|
|
65
|
+
|
|
66
|
+
### npm authentication
|
|
67
|
+
|
|
68
|
+
The GitHub Actions workflow uses OIDC-based trusted publishing. To set this up:
|
|
69
|
+
|
|
70
|
+
1. Go to [npmjs.com](https://www.npmjs.com) > **Access Tokens** > **Granular Access Token**
|
|
71
|
+
2. Create a token with publish access to `claude-code-types`
|
|
72
|
+
3. In your GitHub repo, go to **Settings** > **Environments** > create an environment called `npm`
|
|
73
|
+
4. Add a secret `NPM_TOKEN` with the token value
|
|
74
|
+
|
|
75
|
+
Alternatively, configure [npm trusted publishing](https://docs.npmjs.com/generating-provenance-statements#publishing-packages-with-provenance-via-github-actions) for keyless OIDC auth.
|
|
76
|
+
|
|
77
|
+
## License
|
|
78
|
+
|
|
79
|
+
MIT
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,535 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for Claude Code chat history JSONL files.
|
|
3
|
+
*
|
|
4
|
+
* Claude Code stores conversation history at:
|
|
5
|
+
* ~/.claude/projects/<project-slug>/<session-id>.jsonl
|
|
6
|
+
*
|
|
7
|
+
* Each line is a JSON object conforming to the `TranscriptEntry` union type.
|
|
8
|
+
*
|
|
9
|
+
* Usage:
|
|
10
|
+
* import type { TranscriptEntry } from 'claude-code-types';
|
|
11
|
+
* const entry: TranscriptEntry = JSON.parse(line);
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
// ---------------------------------------------------------------------------
|
|
15
|
+
// Top-level entry union
|
|
16
|
+
// ---------------------------------------------------------------------------
|
|
17
|
+
|
|
18
|
+
export type TranscriptEntry =
|
|
19
|
+
| UserEntry
|
|
20
|
+
| AssistantEntry
|
|
21
|
+
| SystemEntry
|
|
22
|
+
| FileHistorySnapshotEntry
|
|
23
|
+
| PrLinkEntry
|
|
24
|
+
| ProgressEntry
|
|
25
|
+
| QueueOperationEntry
|
|
26
|
+
| SavedHookContextEntry
|
|
27
|
+
| SummaryEntry;
|
|
28
|
+
|
|
29
|
+
// ---------------------------------------------------------------------------
|
|
30
|
+
// Shared base fields (present on most entries that represent conversation turns)
|
|
31
|
+
// ---------------------------------------------------------------------------
|
|
32
|
+
|
|
33
|
+
interface EntryBase {
|
|
34
|
+
uuid: string;
|
|
35
|
+
parentUuid: string | null;
|
|
36
|
+
isSidechain: boolean;
|
|
37
|
+
sessionId: string;
|
|
38
|
+
timestamp: string;
|
|
39
|
+
cwd: string;
|
|
40
|
+
version: string;
|
|
41
|
+
gitBranch?: string;
|
|
42
|
+
slug?: string;
|
|
43
|
+
teamName?: string;
|
|
44
|
+
userType: 'external';
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// ---------------------------------------------------------------------------
|
|
48
|
+
// User entry
|
|
49
|
+
// ---------------------------------------------------------------------------
|
|
50
|
+
|
|
51
|
+
export interface UserEntry extends EntryBase {
|
|
52
|
+
type: 'user';
|
|
53
|
+
message: UserMessage;
|
|
54
|
+
isMeta?: boolean;
|
|
55
|
+
isCompactSummary?: boolean;
|
|
56
|
+
isVisibleInTranscriptOnly?: boolean;
|
|
57
|
+
imagePasteIds?: string[];
|
|
58
|
+
permissionMode?: PermissionMode;
|
|
59
|
+
planContent?: string;
|
|
60
|
+
thinkingMetadata?: ThinkingMetadata;
|
|
61
|
+
todos?: Todo[];
|
|
62
|
+
/** Present when this user message is a tool result being delivered back */
|
|
63
|
+
toolUseResult?: unknown;
|
|
64
|
+
/** UUID of the assistant message whose tool_use triggered this result */
|
|
65
|
+
sourceToolAssistantUUID?: string;
|
|
66
|
+
/** ID of the tool_use content block this result corresponds to */
|
|
67
|
+
sourceToolUseID?: string;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface UserMessage {
|
|
71
|
+
role: 'user';
|
|
72
|
+
content: string | UserContentBlock[];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export type UserContentBlock =
|
|
76
|
+
| TextBlock
|
|
77
|
+
| ImageBlock
|
|
78
|
+
| DocumentBlock
|
|
79
|
+
| ToolResultBlock;
|
|
80
|
+
|
|
81
|
+
// ---------------------------------------------------------------------------
|
|
82
|
+
// Assistant entry
|
|
83
|
+
// ---------------------------------------------------------------------------
|
|
84
|
+
|
|
85
|
+
export interface AssistantEntry extends EntryBase {
|
|
86
|
+
type: 'assistant';
|
|
87
|
+
message: AssistantMessage;
|
|
88
|
+
requestId?: string;
|
|
89
|
+
/** Present when the API returned an error instead of a response */
|
|
90
|
+
apiError?: unknown;
|
|
91
|
+
error?: string;
|
|
92
|
+
isApiErrorMessage?: boolean;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export interface AssistantMessage {
|
|
96
|
+
role: 'assistant';
|
|
97
|
+
id?: string;
|
|
98
|
+
type?: 'message';
|
|
99
|
+
model?: Model;
|
|
100
|
+
content: AssistantContentBlock[];
|
|
101
|
+
stop_reason: StopReason | null;
|
|
102
|
+
stop_sequence?: string | null;
|
|
103
|
+
usage?: Usage;
|
|
104
|
+
container?: unknown;
|
|
105
|
+
context_management?: unknown;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export type AssistantContentBlock =
|
|
109
|
+
| TextBlock
|
|
110
|
+
| ThinkingBlock
|
|
111
|
+
| RedactedThinkingBlock
|
|
112
|
+
| ToolUseBlock
|
|
113
|
+
| ServerToolUseBlock
|
|
114
|
+
| WebSearchToolResultBlock;
|
|
115
|
+
|
|
116
|
+
// ---------------------------------------------------------------------------
|
|
117
|
+
// System entry (multiple subtypes)
|
|
118
|
+
// ---------------------------------------------------------------------------
|
|
119
|
+
|
|
120
|
+
export interface SystemEntry extends Partial<EntryBase> {
|
|
121
|
+
type: 'system';
|
|
122
|
+
subtype: SystemSubtype;
|
|
123
|
+
isMeta?: boolean;
|
|
124
|
+
content?: string;
|
|
125
|
+
level?: string;
|
|
126
|
+
/** turn_duration */
|
|
127
|
+
durationMs?: number;
|
|
128
|
+
/** api_error */
|
|
129
|
+
error?: string;
|
|
130
|
+
cause?: string;
|
|
131
|
+
retryAttempt?: number;
|
|
132
|
+
retryInMs?: number;
|
|
133
|
+
maxRetries?: number;
|
|
134
|
+
/** compact_boundary */
|
|
135
|
+
compactMetadata?: CompactMetadata;
|
|
136
|
+
/** microcompact_boundary */
|
|
137
|
+
microcompactMetadata?: MicrocompactMetadata;
|
|
138
|
+
/** stop_hook_summary */
|
|
139
|
+
hookCount?: number;
|
|
140
|
+
hookErrors?: unknown[];
|
|
141
|
+
hookInfos?: unknown[];
|
|
142
|
+
hasOutput?: boolean;
|
|
143
|
+
stopReason?: string;
|
|
144
|
+
preventedContinuation?: boolean;
|
|
145
|
+
toolUseID?: string;
|
|
146
|
+
logicalParentUuid?: string;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export type SystemSubtype =
|
|
150
|
+
| 'api_error'
|
|
151
|
+
| 'compact_boundary'
|
|
152
|
+
| 'informational'
|
|
153
|
+
| 'local_command'
|
|
154
|
+
| 'microcompact_boundary'
|
|
155
|
+
| 'stop_hook_summary'
|
|
156
|
+
| 'turn_duration';
|
|
157
|
+
|
|
158
|
+
// ---------------------------------------------------------------------------
|
|
159
|
+
// File history snapshot (undo/restore tracking)
|
|
160
|
+
// ---------------------------------------------------------------------------
|
|
161
|
+
|
|
162
|
+
export interface FileHistorySnapshotEntry {
|
|
163
|
+
type: 'file-history-snapshot';
|
|
164
|
+
messageId: string;
|
|
165
|
+
isSnapshotUpdate: boolean;
|
|
166
|
+
snapshot: FileHistorySnapshot;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export interface FileHistorySnapshot {
|
|
170
|
+
messageId: string;
|
|
171
|
+
timestamp: string;
|
|
172
|
+
trackedFileBackups: Record<string, FileBackup>;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export interface FileBackup {
|
|
176
|
+
backupFileName: string;
|
|
177
|
+
version: number;
|
|
178
|
+
backupTime: string;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// ---------------------------------------------------------------------------
|
|
182
|
+
// PR link
|
|
183
|
+
// ---------------------------------------------------------------------------
|
|
184
|
+
|
|
185
|
+
export interface PrLinkEntry {
|
|
186
|
+
type: 'pr-link';
|
|
187
|
+
sessionId: string;
|
|
188
|
+
timestamp: string;
|
|
189
|
+
prNumber: number;
|
|
190
|
+
prUrl: string;
|
|
191
|
+
prRepository: string;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// ---------------------------------------------------------------------------
|
|
195
|
+
// Progress (streaming updates for subagent / Task tool)
|
|
196
|
+
// ---------------------------------------------------------------------------
|
|
197
|
+
|
|
198
|
+
export interface ProgressEntry extends Partial<EntryBase> {
|
|
199
|
+
type: 'progress';
|
|
200
|
+
data: ProgressData;
|
|
201
|
+
parentToolUseID?: string;
|
|
202
|
+
toolUseID?: string;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export interface ProgressData {
|
|
206
|
+
message: {
|
|
207
|
+
type: 'user' | 'assistant';
|
|
208
|
+
message: UserMessage | AssistantMessage;
|
|
209
|
+
uuid?: string;
|
|
210
|
+
timestamp?: string;
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// ---------------------------------------------------------------------------
|
|
215
|
+
// Queue operation (messages typed while agent is busy)
|
|
216
|
+
// ---------------------------------------------------------------------------
|
|
217
|
+
|
|
218
|
+
export interface QueueOperationEntry {
|
|
219
|
+
type: 'queue-operation';
|
|
220
|
+
operation: 'enqueue' | 'dequeue';
|
|
221
|
+
sessionId: string;
|
|
222
|
+
timestamp: string;
|
|
223
|
+
content: string;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// ---------------------------------------------------------------------------
|
|
227
|
+
// Saved hook context
|
|
228
|
+
// ---------------------------------------------------------------------------
|
|
229
|
+
|
|
230
|
+
export interface SavedHookContextEntry extends Partial<EntryBase> {
|
|
231
|
+
type: 'saved_hook_context';
|
|
232
|
+
content: string[];
|
|
233
|
+
hookEvent?: string;
|
|
234
|
+
hookName?: string;
|
|
235
|
+
toolUseID?: string;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// ---------------------------------------------------------------------------
|
|
239
|
+
// Summary
|
|
240
|
+
// ---------------------------------------------------------------------------
|
|
241
|
+
|
|
242
|
+
export interface SummaryEntry {
|
|
243
|
+
type: 'summary';
|
|
244
|
+
summary: string;
|
|
245
|
+
leafUuid: string;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// ---------------------------------------------------------------------------
|
|
249
|
+
// Content blocks
|
|
250
|
+
// ---------------------------------------------------------------------------
|
|
251
|
+
|
|
252
|
+
export interface TextBlock {
|
|
253
|
+
type: 'text';
|
|
254
|
+
text: string;
|
|
255
|
+
citations?: TextCitation[] | null;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
export interface ThinkingBlock {
|
|
259
|
+
type: 'thinking';
|
|
260
|
+
thinking: string;
|
|
261
|
+
signature: string;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
export interface RedactedThinkingBlock {
|
|
265
|
+
type: 'redacted_thinking';
|
|
266
|
+
data: string;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export interface ToolUseBlock {
|
|
270
|
+
type: 'tool_use';
|
|
271
|
+
id: string;
|
|
272
|
+
name: BuiltinToolName | (string & {});
|
|
273
|
+
input: Record<string, unknown>;
|
|
274
|
+
/** Present in progress/streaming entries */
|
|
275
|
+
caller?: { type: string };
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
export interface ToolResultBlock {
|
|
279
|
+
type: 'tool_result';
|
|
280
|
+
tool_use_id: string;
|
|
281
|
+
content?: string | TextBlock[];
|
|
282
|
+
is_error?: boolean;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
export interface ImageBlock {
|
|
286
|
+
type: 'image';
|
|
287
|
+
source: Base64ImageSource | UrlImageSource;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
export interface DocumentBlock {
|
|
291
|
+
type: 'document';
|
|
292
|
+
source: Base64DocumentSource | PlainTextSource | UrlDocumentSource;
|
|
293
|
+
title?: string | null;
|
|
294
|
+
context?: string | null;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
export interface ServerToolUseBlock {
|
|
298
|
+
type: 'server_tool_use';
|
|
299
|
+
id: string;
|
|
300
|
+
name: 'web_search';
|
|
301
|
+
input: Record<string, unknown>;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
export interface WebSearchToolResultBlock {
|
|
305
|
+
type: 'web_search_tool_result';
|
|
306
|
+
tool_use_id: string;
|
|
307
|
+
content: WebSearchResultError | WebSearchResultItem[];
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
// ---------------------------------------------------------------------------
|
|
311
|
+
// Media sources
|
|
312
|
+
// ---------------------------------------------------------------------------
|
|
313
|
+
|
|
314
|
+
export interface Base64ImageSource {
|
|
315
|
+
type: 'base64';
|
|
316
|
+
media_type: 'image/jpeg' | 'image/png' | 'image/gif' | 'image/webp';
|
|
317
|
+
data: string;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
export interface UrlImageSource {
|
|
321
|
+
type: 'url';
|
|
322
|
+
url: string;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
export interface Base64DocumentSource {
|
|
326
|
+
type: 'base64';
|
|
327
|
+
media_type: 'application/pdf';
|
|
328
|
+
data: string;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
export interface PlainTextSource {
|
|
332
|
+
type: 'text';
|
|
333
|
+
media_type: 'text/plain';
|
|
334
|
+
data: string;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
export interface UrlDocumentSource {
|
|
338
|
+
type: 'url';
|
|
339
|
+
url: string;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// ---------------------------------------------------------------------------
|
|
343
|
+
// Citations
|
|
344
|
+
// ---------------------------------------------------------------------------
|
|
345
|
+
|
|
346
|
+
export type TextCitation =
|
|
347
|
+
| CitationCharLocation
|
|
348
|
+
| CitationPageLocation
|
|
349
|
+
| CitationContentBlockLocation
|
|
350
|
+
| CitationWebSearchResultLocation;
|
|
351
|
+
|
|
352
|
+
export interface CitationCharLocation {
|
|
353
|
+
type: 'char_location';
|
|
354
|
+
cited_text: string;
|
|
355
|
+
document_index: number;
|
|
356
|
+
document_title: string | null;
|
|
357
|
+
start_char_index: number;
|
|
358
|
+
end_char_index: number;
|
|
359
|
+
file_id: string | null;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
export interface CitationPageLocation {
|
|
363
|
+
type: 'page_location';
|
|
364
|
+
cited_text: string;
|
|
365
|
+
document_index: number;
|
|
366
|
+
document_title: string | null;
|
|
367
|
+
start_page_number: number;
|
|
368
|
+
end_page_number: number;
|
|
369
|
+
file_id: string | null;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
export interface CitationContentBlockLocation {
|
|
373
|
+
type: 'content_block_location';
|
|
374
|
+
cited_text: string;
|
|
375
|
+
document_index: number;
|
|
376
|
+
document_title: string | null;
|
|
377
|
+
start_block_index: number;
|
|
378
|
+
end_block_index: number;
|
|
379
|
+
file_id: string | null;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
export interface CitationWebSearchResultLocation {
|
|
383
|
+
type: 'web_search_result_location';
|
|
384
|
+
cited_text: string;
|
|
385
|
+
encrypted_index: string;
|
|
386
|
+
title: string | null;
|
|
387
|
+
url: string;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
// ---------------------------------------------------------------------------
|
|
391
|
+
// Web search results
|
|
392
|
+
// ---------------------------------------------------------------------------
|
|
393
|
+
|
|
394
|
+
export interface WebSearchResultError {
|
|
395
|
+
type: 'web_search_error';
|
|
396
|
+
error_code: string;
|
|
397
|
+
message: string;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
export interface WebSearchResultItem {
|
|
401
|
+
type: 'web_search_result';
|
|
402
|
+
url: string;
|
|
403
|
+
title: string;
|
|
404
|
+
encrypted_content: string;
|
|
405
|
+
page_age?: string | null;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
// ---------------------------------------------------------------------------
|
|
409
|
+
// Usage & metadata
|
|
410
|
+
// ---------------------------------------------------------------------------
|
|
411
|
+
|
|
412
|
+
export interface Usage {
|
|
413
|
+
input_tokens: number;
|
|
414
|
+
output_tokens: number;
|
|
415
|
+
cache_creation_input_tokens?: number | null;
|
|
416
|
+
cache_read_input_tokens?: number | null;
|
|
417
|
+
cache_creation?: CacheCreation | null;
|
|
418
|
+
server_tool_use?: ServerToolUsage | null;
|
|
419
|
+
service_tier?: 'standard' | 'priority' | 'batch' | null;
|
|
420
|
+
inference_geo?: string | null;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
export interface CacheCreation {
|
|
424
|
+
ephemeral_5m_input_tokens: number;
|
|
425
|
+
ephemeral_1h_input_tokens: number;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
export interface ServerToolUsage {
|
|
429
|
+
web_search_requests: number;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
export interface CompactMetadata {
|
|
433
|
+
trigger: 'auto' | 'manual';
|
|
434
|
+
preTokens: number;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
export interface MicrocompactMetadata {
|
|
438
|
+
trigger: 'auto' | 'manual';
|
|
439
|
+
preTokens: number;
|
|
440
|
+
tokensSaved: number;
|
|
441
|
+
compactedToolIds: string[];
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
export interface ThinkingMetadata {
|
|
445
|
+
maxThinkingTokens: number;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
export interface Todo {
|
|
449
|
+
content: string;
|
|
450
|
+
status: string;
|
|
451
|
+
activeForm?: string;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
// ---------------------------------------------------------------------------
|
|
455
|
+
// Enums / unions
|
|
456
|
+
// ---------------------------------------------------------------------------
|
|
457
|
+
|
|
458
|
+
export type Model =
|
|
459
|
+
| 'claude-opus-4-6'
|
|
460
|
+
| 'claude-opus-4-5-20251101'
|
|
461
|
+
| 'claude-sonnet-4-5-20250929'
|
|
462
|
+
| 'claude-haiku-4-5-20251001'
|
|
463
|
+
| '<synthetic>'
|
|
464
|
+
| (string & {});
|
|
465
|
+
|
|
466
|
+
export type StopReason =
|
|
467
|
+
| 'end_turn'
|
|
468
|
+
| 'max_tokens'
|
|
469
|
+
| 'stop_sequence'
|
|
470
|
+
| 'tool_use'
|
|
471
|
+
| 'pause_turn'
|
|
472
|
+
| 'refusal';
|
|
473
|
+
|
|
474
|
+
export type PermissionMode =
|
|
475
|
+
| 'default'
|
|
476
|
+
| 'plan'
|
|
477
|
+
| 'acceptEdits'
|
|
478
|
+
| 'dontAsk'
|
|
479
|
+
| 'bypassPermissions';
|
|
480
|
+
|
|
481
|
+
/** Built-in Claude Code tools (non-exhaustive — MCP tools use `mcp__<server>__<tool>` pattern) */
|
|
482
|
+
export type BuiltinToolName =
|
|
483
|
+
| 'AskUserQuestion'
|
|
484
|
+
| 'Bash'
|
|
485
|
+
| 'Edit'
|
|
486
|
+
| 'EnterPlanMode'
|
|
487
|
+
| 'ExitPlanMode'
|
|
488
|
+
| 'Glob'
|
|
489
|
+
| 'Grep'
|
|
490
|
+
| 'KillShell'
|
|
491
|
+
| 'ListMcpResourcesTool'
|
|
492
|
+
| 'NotebookEdit'
|
|
493
|
+
| 'Read'
|
|
494
|
+
| 'ReadMcpResourceTool'
|
|
495
|
+
| 'SendMessage'
|
|
496
|
+
| 'Skill'
|
|
497
|
+
| 'Task'
|
|
498
|
+
| 'TaskCreate'
|
|
499
|
+
| 'TaskGet'
|
|
500
|
+
| 'TaskList'
|
|
501
|
+
| 'TaskOutput'
|
|
502
|
+
| 'TaskStop'
|
|
503
|
+
| 'TaskUpdate'
|
|
504
|
+
| 'TodoWrite'
|
|
505
|
+
| 'WebFetch'
|
|
506
|
+
| 'WebSearch'
|
|
507
|
+
| 'Write';
|
|
508
|
+
|
|
509
|
+
// ---------------------------------------------------------------------------
|
|
510
|
+
// Parser helper type
|
|
511
|
+
// ---------------------------------------------------------------------------
|
|
512
|
+
|
|
513
|
+
/**
|
|
514
|
+
* Parse a single JSONL line into a typed TranscriptEntry.
|
|
515
|
+
*
|
|
516
|
+
* @example
|
|
517
|
+
* ```ts
|
|
518
|
+
* import type { TranscriptEntry } from 'claude-code-types';
|
|
519
|
+
* import { readFileSync } from 'fs';
|
|
520
|
+
*
|
|
521
|
+
* const entries: TranscriptEntry[] = readFileSync(path, 'utf-8')
|
|
522
|
+
* .split('\n')
|
|
523
|
+
* .filter(Boolean)
|
|
524
|
+
* .map(line => JSON.parse(line) as TranscriptEntry);
|
|
525
|
+
*
|
|
526
|
+
* for (const entry of entries) {
|
|
527
|
+
* switch (entry.type) {
|
|
528
|
+
* case 'user': console.log(entry.message.content); break;
|
|
529
|
+
* case 'assistant': console.log(entry.message.model); break;
|
|
530
|
+
* case 'system': console.log(entry.subtype); break;
|
|
531
|
+
* }
|
|
532
|
+
* }
|
|
533
|
+
* ```
|
|
534
|
+
*/
|
|
535
|
+
export type ParseLine = (line: string) => TranscriptEntry | null;
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "claude-code-types",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "TypeScript type definitions for Claude Code chat history JSONL files",
|
|
5
|
+
"types": "./index.d.ts",
|
|
6
|
+
"files": [
|
|
7
|
+
"index.d.ts"
|
|
8
|
+
],
|
|
9
|
+
"scripts": {
|
|
10
|
+
"typecheck": "tsc --noEmit"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"claude",
|
|
14
|
+
"claude-code",
|
|
15
|
+
"anthropic",
|
|
16
|
+
"types",
|
|
17
|
+
"typescript",
|
|
18
|
+
"jsonl",
|
|
19
|
+
"chat-history"
|
|
20
|
+
],
|
|
21
|
+
"author": "Pedro Carvalho",
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "https://github.com/pedropaulovc/claude-code-types.git"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"typescript": "^5.7.0"
|
|
29
|
+
}
|
|
30
|
+
}
|