@anthropic-ai/claude-code 1.0.35 → 1.0.36

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anthropic-ai/claude-code",
3
- "version": "1.0.35",
3
+ "version": "1.0.36",
4
4
  "main": "sdk.mjs",
5
5
  "types": "sdk.d.ts",
6
6
  "bin": {
package/sdk.d.ts CHANGED
@@ -121,7 +121,7 @@ export type SDKMessage =
121
121
  | SDKSystemMessage
122
122
 
123
123
  type Props = {
124
- prompt: string
124
+ prompt: string | AsyncIterable<SDKUserMessage>
125
125
  abortController?: AbortController
126
126
  options?: Options
127
127
  }
package/sdk.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  // (c) Anthropic PBC. All rights reserved. Use is subject to Anthropic's Commercial Terms of Service (https://www.anthropic.com/legal/commercial-terms).
2
2
 
3
- // Version: 1.0.35
3
+ // Version: 1.0.36
4
4
 
5
5
  // src/entrypoints/sdk.ts
6
6
  import { spawn } from "child_process";
@@ -68,10 +68,11 @@ async function* query({
68
68
  }
69
69
  args.push("--fallback-model", fallbackModel);
70
70
  }
71
- if (!prompt.trim()) {
72
- throw new RangeError("Prompt is required");
71
+ if (typeof prompt === "string") {
72
+ args.push("--print", prompt.trim());
73
+ } else {
74
+ args.push("--input-format", "stream-json");
73
75
  }
74
- args.push("--print", prompt.trim());
75
76
  if (!existsSync(pathToClaudeCodeExecutable)) {
76
77
  throw new ReferenceError(`Claude Code executable not found at ${pathToClaudeCodeExecutable}. Is options.pathToClaudeCodeExecutable set?`);
77
78
  }
@@ -84,7 +85,11 @@ async function* query({
84
85
  ...process.env
85
86
  }
86
87
  });
87
- child.stdin.end();
88
+ if (typeof prompt === "string") {
89
+ child.stdin.end();
90
+ } else {
91
+ streamToStdin(prompt, child.stdin, abortController);
92
+ }
88
93
  if (process.env.DEBUG) {
89
94
  child.stderr.on("data", (data) => {
90
95
  console.error("Claude Code stderr:", data.toString());
@@ -136,6 +141,15 @@ async function* query({
136
141
  }
137
142
  }
138
143
  }
144
+ async function streamToStdin(stream, stdin, abortController) {
145
+ for await (const message of stream) {
146
+ if (abortController.signal.aborted)
147
+ break;
148
+ stdin.write(JSON.stringify(message) + `
149
+ `);
150
+ }
151
+ stdin.end();
152
+ }
139
153
  function logDebug(message) {
140
154
  if (process.env.DEBUG) {
141
155
  console.debug(message);
Binary file