ai-sdk-provider-claude-code 3.4.3 → 3.5.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.
@@ -1,5 +1,7 @@
1
1
  # Usage Guide
2
2
 
3
+ > **Historical:** Covers legacy provider versions 0.x (AI SDK v4). See the [main README](../../README.md) for current documentation.
4
+
3
5
  ## Essential Examples
4
6
 
5
7
  ### Streaming Responses
@@ -0,0 +1,7 @@
1
+ # AI SDK v4 Documentation (Historical)
2
+
3
+ > **Historical:** These documents cover legacy provider versions 0.x (AI SDK v4, `@anthropic-ai/claude-code`). For current documentation, see the [main README](../../README.md).
4
+
5
+ - [GUIDE.md](GUIDE.md) - Usage guide
6
+ - [TROUBLESHOOTING.md](TROUBLESHOOTING.md) - Common issues and solutions
7
+ - [DEVELOPMENT-STATUS.md](DEVELOPMENT-STATUS.md) - Development status
@@ -1,5 +1,7 @@
1
1
  # Usage Guide (AI SDK v5)
2
2
 
3
+ > **Historical:** Covers legacy provider versions 1.x–2.x (AI SDK v5). Much still applies to 3.x; new features are documented in the [main README](../../README.md).
4
+
3
5
  ## Essential Examples
4
6
 
5
7
  ### Streaming Responses
@@ -0,0 +1,10 @@
1
+ # AI SDK v5 Documentation (Historical)
2
+
3
+ > **Historical:** These documents cover legacy provider versions 1.x–2.x (AI SDK v5). Much of the guidance still applies to 3.x, but new features are documented in the [main README](../../README.md).
4
+
5
+ - [GUIDE.md](GUIDE.md) - Usage guide
6
+ - [TROUBLESHOOTING.md](TROUBLESHOOTING.md) - Common issues and solutions
7
+ - [TOOL_STREAMING_SUPPORT.md](TOOL_STREAMING_SUPPORT.md) - Tool streaming event semantics
8
+ - [V5_BREAKING_CHANGES.md](V5_BREAKING_CHANGES.md) - v0.x to v1.x migration guide
9
+ - [V5_MIGRATION_PLAN.md](V5_MIGRATION_PLAN.md), [V5_MIGRATION_SUMMARY.md](V5_MIGRATION_SUMMARY.md), [V5_MIGRATION_TASKS.md](V5_MIGRATION_TASKS.md) - Internal v5 migration records
10
+ - [DEVELOPMENT-STATUS.md](DEVELOPMENT-STATUS.md) - Development status
@@ -0,0 +1,117 @@
1
+ # Session Management
2
+
3
+ Every `generateText`/`streamText` call through this provider runs as a Claude Code **session**. By default the CLI persists each session as a JSONL transcript under `~/.claude/projects/` (honoring `CLAUDE_CONFIG_DIR`), and the session ID is surfaced in `providerMetadata['claude-code'].sessionId` so you can resume, fork, inspect, retitle, tag, or delete it later.
4
+
5
+ This guide ties together the session-related **settings** (passed to `claudeCode(modelId, settings)`) and the session **helper functions** (re-exported from the Claude Agent SDK).
6
+
7
+ For a runnable end-to-end walkthrough, see [examples/session-management.ts](../examples/session-management.ts) (`npm run example:sessions`).
8
+
9
+ ## Session settings
10
+
11
+ | Setting | Type | Description |
12
+ | ----------------- | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
13
+ | `sessionId` | `string` | Use a specific session ID for a **new** session (deterministic tracking/correlation). Must be a UUID. |
14
+ | `resume` | `string` | Resume an existing session by ID. The conversation context is restored from the persisted transcript. |
15
+ | `resumeSessionAt` | `string` | When resuming, restore the session only up to a specific message UUID (later messages are discarded from context). |
16
+ | `forkSession` | `boolean` | When resuming, fork to a **new** session ID instead of continuing under the original ID (combine with `sessionId` to choose the fork's ID). |
17
+ | `continue` | `boolean` | Continue the most recent conversation for the working directory, without needing its ID. |
18
+ | `persistSession` | `boolean` | When `false`, the session is not written to `~/.claude/projects/` and cannot be resumed or inspected later. Useful for ephemeral workflows. Default `true`. |
19
+ | `title` | `string` | Custom title for a **new** session (instead of auto-generating one from the first prompt). When resuming, the resumed session's persisted title takes precedence. |
20
+
21
+ ### Capturing the session ID
22
+
23
+ ```ts
24
+ import { generateText } from 'ai';
25
+ import { claudeCode } from 'ai-sdk-provider-claude-code';
26
+
27
+ const result = await generateText({
28
+ model: claudeCode('sonnet'),
29
+ prompt: 'Remember this code word: papaya. Reply with OK.',
30
+ });
31
+
32
+ const sessionId = result.providerMetadata?.['claude-code']?.sessionId as string;
33
+ ```
34
+
35
+ ### Resuming a session
36
+
37
+ ```ts
38
+ const followUp = await generateText({
39
+ model: claudeCode('sonnet', { resume: sessionId }),
40
+ prompt: 'What was the code word?',
41
+ });
42
+ // followUp.text mentions "papaya"; the session keeps the same ID.
43
+ ```
44
+
45
+ ### Forking at query time (the `forkSession` setting)
46
+
47
+ ```ts
48
+ const branched = await generateText({
49
+ model: claudeCode('sonnet', { resume: sessionId, forkSession: true }),
50
+ prompt: 'Explore an alternative approach from here.',
51
+ });
52
+ // branched runs under a NEW session ID; the original transcript is untouched.
53
+ const forkId = branched.providerMetadata?.['claude-code']?.sessionId as string;
54
+ ```
55
+
56
+ ## Session helper functions
57
+
58
+ These are re-exported from `@anthropic-ai/claude-agent-sdk` for convenience — no extra dependency needed. They are plain async functions, independent of any provider/model instance.
59
+
60
+ | Helper | Description |
61
+ | --------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
62
+ | `listSessions(options?)` | List metadata for all persisted sessions (`SDKSessionInfo[]`) — the discovery API for building session pickers. Supports filtering options (e.g. by project directory via `dir`, plus `limit`). |
63
+ | `getSessionMessages(sessionId, options?)` | Read the main conversation transcript of a session (`SessionMessage[]`) — the counterpart to `getSubagentMessages()` for the top-level thread. |
64
+ | `getSessionInfo(sessionId, options?)` | Read metadata for one session (`SDKSessionInfo`: `summary`, `customTitle`, `firstPrompt`, `lastModified`, `cwd`, `gitBranch`, `tag`, ...). Returns `undefined` if not found. |
65
+ | `forkSession(sessionId, options?)` | Copy a session's transcript into a new session ID **without running a query** (optionally sliced via `upToMessageId`, retitled via `title`). Returns `{ sessionId }`, resumable via the `resume` setting. |
66
+ | `renameSession(sessionId, title, options?)` | Retitle an existing session. |
67
+ | `tagSession(sessionId, tag, options?)` | Set (or clear, with `null`) a session's tag. |
68
+ | `deleteSession(sessionId, options?)` | Delete a session's persisted transcript. |
69
+ | `listSubagents(sessionId, options?)` | List agent IDs of subagent transcripts recorded under a session. |
70
+ | `getSubagentMessages(sessionId, agentId, options?)` | Read a subagent's transcript messages (`SessionMessage[]`). |
71
+ | `importSessionToStore(sessionId, store, options?)` | Copy a local JSONL session (and, by default, its subagent transcripts) into a custom `SessionStore` (alpha). |
72
+ | `foldSessionSummary(prev, key, entries, options?)` | Pure utility for `SessionStore` implementers: fold appended entries into a `SessionSummaryEntry` inside `append()` (alpha). |
73
+
74
+ ```ts
75
+ import {
76
+ forkSession,
77
+ getSessionInfo,
78
+ renameSession,
79
+ deleteSession,
80
+ } from 'ai-sdk-provider-claude-code';
81
+
82
+ const info = await getSessionInfo(sessionId);
83
+ console.log(info?.summary, info?.lastModified);
84
+
85
+ const fork = await forkSession(sessionId, { title: 'experiment branch' });
86
+ // ...resume the fork via claudeCode('sonnet', { resume: fork.sessionId })...
87
+
88
+ await renameSession(sessionId, 'main investigation');
89
+ await deleteSession(fork.sessionId);
90
+ ```
91
+
92
+ ### Two ways to fork
93
+
94
+ - **`forkSession` setting** (`{ resume, forkSession: true }`) — fork **and run a query** in one step; the new ID arrives in `providerMetadata`.
95
+ - **`forkSession()` helper** — fork the stored transcript **without** running a query (and optionally slice it with `upToMessageId`); resume it later with the `resume` setting.
96
+
97
+ ## Disk storage vs custom `SessionStore`
98
+
99
+ By default, everything above operates on the local JSONL files under `~/.claude/projects/` (the directory the CLI writes to; `CLAUDE_CONFIG_DIR` relocates it). Helpers that take an `options` object accept `dir` to scope the lookup to one project directory — when omitted, all project directories are searched.
100
+
101
+ For custom backends (Postgres, S3, Redis, ...), the SDK defines a **`SessionStore`** adapter (alpha — subject to upstream change):
102
+
103
+ - The `sessionStore` **setting** (with `sessionStoreFlush`, `loadTimeoutMs`) mirrors transcripts to your store **in addition to** local files while queries run. It cannot be combined with `persistSession: false` (local writes are required for the mirror) or `enableFileCheckpointing: true`, and combining it with `continue: true` (without an explicit `resume` ID) requires the store to implement `listSessions()` — the SDK uses it to discover the most recent session. The provider rejects all three invalid combinations at validation time.
104
+ - Each helper's `options.sessionStore` redirects that helper to read/write **your store instead of the local filesystem** (e.g. `getSessionInfo(id, { sessionStore: myStore })`).
105
+ - `importSessionToStore()` migrates an existing local session into a store; `foldSessionSummary()` and the `SessionKey`/`SessionStoreEntry`/`SessionSummaryEntry` types are the building blocks for writing a store; `InMemorySessionStore` is a reference implementation for tests.
106
+
107
+ ## `title` setting vs `renameSession()`
108
+
109
+ - The `title` **setting** only names a **new** session at creation time. When resuming, the resumed session's persisted title takes precedence and the setting is ignored.
110
+ - To retitle an **existing** session, use the `renameSession()` helper.
111
+ - `forkSession()` accepts its own `title` for the fork; if omitted, the fork derives its title from the original (`"<original> (fork)"`).
112
+
113
+ ## Notes
114
+
115
+ - `sessionId` cannot be combined with `continue` or `resume` unless `forkSession: true` is also set (in which case it names the forked session's ID). The provider enforces this — and the UUID requirement — at validation time, and on multi-turn conversations it stops forwarding `sessionId` once it auto-resumes via the captured session ID (which already carries the custom ID).
116
+ - Sessions are stored per working directory (project). If you run queries with different `cwd` settings, pass `dir` to the helpers to disambiguate, or rely on the default search across all project directories.
117
+ - `persistSession: false` sessions never reach disk, so none of the helpers can see them.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-sdk-provider-claude-code",
3
- "version": "3.4.3",
3
+ "version": "3.5.0",
4
4
  "description": "AI SDK v6 provider for Claude via Claude Agent SDK (use Pro/Max subscription)",
5
5
  "keywords": [
6
6
  "ai-sdk",
@@ -64,6 +64,13 @@
64
64
  "example:object": "npm run build && npx tsx examples/generate-object.ts",
65
65
  "example:object:constraints": "npm run build && npx tsx examples/generate-object-constraints.ts",
66
66
  "example:tools": "npm run build && npx tsx examples/tool-management.ts",
67
+ "example:ai-sdk-tools": "npm run build && npx tsx examples/ai-sdk-tools.ts",
68
+ "example:sessions": "npm run build && npx tsx examples/session-management.ts",
69
+ "example:hooks-permissions": "npm run build && npx tsx examples/hooks-permission-denied.ts",
70
+ "example:warm-start": "npm run build && npx tsx examples/warm-start.ts",
71
+ "example:context-usage": "npm run build && npx tsx examples/context-usage.ts",
72
+ "example:prompt-suggestions": "npm run build && npx tsx examples/prompt-suggestions.ts",
73
+ "example:skills-option": "npm run build && npx tsx examples/skills-option.ts",
67
74
  "example:mcp:filesystem": "npm run build && npx tsx examples/mcp-filesystem.ts",
68
75
  "example:mcp:exa": "npm run build && npx tsx examples/mcp-exa.ts",
69
76
  "example:timeout": "npm run build && npx tsx examples/long-running-tasks.ts",
@@ -74,7 +81,7 @@
74
81
  "dependencies": {
75
82
  "@ai-sdk/provider": "^3.0.0",
76
83
  "@ai-sdk/provider-utils": "^4.0.1",
77
- "@anthropic-ai/claude-agent-sdk": "^0.2.63"
84
+ "@anthropic-ai/claude-agent-sdk": "^0.3.170"
78
85
  },
79
86
  "devDependencies": {
80
87
  "@edge-runtime/vm": "5.0.0",