fix(transport): guard against None allowed_tools in _apply_skills_defaults#963
Open
Aispotlightlab wants to merge 1 commit into
Open
fix(transport): guard against None allowed_tools in _apply_skills_defaults#963Aispotlightlab wants to merge 1 commit into
Aispotlightlab wants to merge 1 commit into
Conversation
`SubprocessCLITransport._apply_skills_defaults` calls `list(self._options.allowed_tools)` unconditionally. While the type annotation declares `list[str]` with `default_factory=list`, the `ClaudeAgentOptions` dataclass does not validate the attribute at runtime — wrapper libraries can (and do) assign `None` to express "no restriction". Real-world impact: `claude-code-telegram` sets `options.allowed_tools = None` when `DISABLE_TOOL_VALIDATION=true` (its recipe for adding third-party MCP servers). Every connect attempt then dies with `TypeError: 'NoneType' object is not iterable` inside `_build_command` — before the CLI even starts — and the failure surfaces to end users as the opaque `Unexpected error in Claude SDK`. Reproduced on 0.1.81 and 0.2.82. Fix: `list(... or [])`. An empty list is the natural "no restriction" sentinel and is already handled correctly downstream (line 256 only emits `--allowedTools` when the list is truthy). Added a regression test that fails before the patch and passes after.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SubprocessCLITransport._apply_skills_defaultscallslist(self._options.allowed_tools)unconditionally (subprocess_cli.py:196). While the type annotation declareslist[str]withdefault_factory=list, theClaudeAgentOptionsdataclass does not validate the attribute at runtime — wrapper libraries can (and do) assignNoneto express "no restriction".When that happens, every
ClaudeSDKClient.connect()dies withTypeError: 'NoneType' object is not iterablebefore the CLI even starts, and the failure surfaces as the opaqueUnexpected error in Claude SDKlog line.Reproduced on both 0.1.81 and 0.2.82 (current latest).
Reproduction
Traceback:
Real-world impact
claude-code-telegram (a popular wrapper, ~v1.6.0) does exactly this when its
DISABLE_TOOL_VALIDATION=trueis set — which is the standard recipe in its docs for adding third-party MCP servers (MemPalace, Mem0, custom MCPs, etc.). Every Telegram message then fails. Companion PR on their side: RichardAtCT/claude-code-telegram#206 — but a defensive guard in the SDK protects every other downstream wrapper too.Fix
An empty list is the natural "no restriction" sentinel and is already handled correctly downstream — line 256 only emits
--allowedToolswhen the list is truthy.disallowed_toolsis already None-safe (line 265 uses a truthy check), so it needs no change.Test
Added
test_build_command_allowed_tools_noneintests/test_transport.pythat:TypeErrorabove--allowedToolsflag is emitted🤖 Generated with Claude Code