CLI startup
CLINotFoundError: Claude Code not found
The Python SDK launches the Claude Code CLI as a subprocess. When it can’t find aclaude executable, connecting fails with a CLINotFoundError:
ClaudeAgentOptions(cli_path=...) and it points at a missing file. Without cli_path, the SDK searches your PATH and common install locations, and the message includes install instructions for your platform.
To fix it:
- Install Claude Code if it isn’t installed. See Install Claude Code for the command on your platform.
- If you set
cli_path, confirm the file exists and is theclaudeexecutable. - If you rely on
PATHresolution, confirmclaude --versionworks in the same environment your application runs in. Processes you launch outside your shell, such as from an IDE or a service manager, often run with a differentPATH.
CLIConnectionError: Refusing to execute batch script
On Windows, connecting fails with aCLIConnectionError when the CLI path the Python SDK uses is a .bat or .cmd batch script, including the claude.cmd shim that an npm install creates:
cmd.exe /c invocation, and cmd.exe re-parses the whole command line at execution time, so an argument value can execute injected commands.
Most Windows installs never reach this error. The Windows x64 wheel of claude-agent-sdk bundles a claude.exe, and the SDK prefers the bundled CLI, then any native claude.exe it can discover, before falling back to a batch shim. You see the refusal in two cases:
- You set
ClaudeAgentOptions(cli_path=...)to a.bator.cmdfile, such as npm’sclaude.cmdshim. - Your install has no bundled or native
claude.exe, for example a source install on ARM64 Windows where the onlyclaudeon yourPATHis the npm shim.
- If you set
ClaudeAgentOptions(cli_path=...), point it at aclaude.exeor remove the option. The SDK skips discovery whilecli_pathis set, so a native install alone can’t take effect. - Install Claude Code natively in PowerShell:
irm https://claude.ai/install.ps1 | iex - On x64 Windows, install the
claude-agent-sdkwheel, which bundlesclaude.exe.
claude-agent-sdk 0.2.124, the Python SDK spawned batch scripts through cmd.exe without this check.
Structured outputs
structured_output is None but the result says success
A result message can end withsubtype: "success" while structured_output is None in Python or undefined in TypeScript. The run completes, but no validated output exists. One way to hit this is a schema no output can satisfy, for example conflicting length constraints. The run ends without a validation error, and the only signal is the missing structured_output.
Treat this result as a failure in application code. Check both that subtype is success and that structured_output is present before using it. The Error handling section shows this pattern for both SDKs.
If it happens repeatedly with a schema you believe is correct, verify the schema is satisfiable, then simplify it until outputs validate, and reintroduce constraints one at a time.