Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

claudeHistoryWorker.ts

25 lines1.0 KB

1import { forkSession, getSessionMessages } from "@anthropic-ai/claude-agent-sdk";
2import * as Schema from "effect/Schema";
3​
4// A separate process gives SDK history helpers the provider's environment without
5// mutating the server's environment. This entry is bundled alongside the server.
6const [method, sessionId, rawOptions] = process.argv.slice(2);
7const options = Schema.decodeSync(
8 Schema.fromJsonString(
9 Schema.Struct({
10 dir: Schema.optionalKey(Schema.String),
11 includeSystemMessages: Schema.optionalKey(Schema.Boolean),
12 upToMessageId: Schema.optionalKey(Schema.String),
13 }),
14 ),
15)(rawOptions ?? "{}");
16if (!sessionId) throw new Error("Claude history session id is required.");
17const result =
18 method === "getSessionMessages"
19 ? await getSessionMessages(sessionId, options)
20 : method === "forkSession"
21 ? await forkSession(sessionId, options)
22 : (() => {
23 throw new Error("Unknown Claude history operation.");
24 })();
25process.stdout.write(JSON.stringify(result));