embed.js 1.0 KB

1234567891011121314151617181920212223242526
  1. /* eslint-disable custom-rules/no-top-level-side-effects */
  2. // This file ships UNBUNDLED alongside sdk.mjs in the npm package.
  3. // It is NOT pre-compiled — the user's bundler processes it directly.
  4. //
  5. // Usage for compiled Bun binaries (`bun build --compile`):
  6. //
  7. // import cliPath from '@anthropic-ai/claude-agent-sdk/embed'
  8. // import { query } from '@anthropic-ai/claude-agent-sdk'
  9. //
  10. // for await (const msg of query({
  11. // prompt: "hello",
  12. // options: { pathToClaudeCodeExecutable: cliPath },
  13. // })) {
  14. // console.log(msg)
  15. // }
  16. //
  17. // How it works:
  18. // 1. The `import ... with { type: 'file' }` tells Bun's bundler to embed cli.js
  19. // into the compiled binary's $bunfs virtual filesystem
  20. // 2. At runtime, extractFromBunfs() copies it to a temp directory so it can be
  21. // spawned as a subprocess (child processes cannot access the parent's $bunfs)
  22. import embeddedCliPath from './cli.js' with { type: 'file' }
  23. import { extractFromBunfs } from './extractFromBunfs.js'
  24. export default extractFromBunfs(embeddedCliPath)