Skip to content

Commit 1e2b7b5

Browse files
committed
refactor: share one constant for the skills="all" sentinel
Also document in the skills docstring that listed names must be exact.
1 parent e6756f1 commit 1e2b7b5

2 files changed

Lines changed: 15 additions & 5 deletions

File tree

src/claude_agent_sdk/_internal/transport/subprocess_cli.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@
2121
from ..._errors import CLIConnectionError, CLINotFoundError, ProcessError
2222
from ..._errors import CLIJSONDecodeError as SDKJSONDecodeError
2323
from ..._version import __version__
24-
from ...types import ClaudeAgentOptions, SystemPromptFile, SystemPromptPreset
24+
from ...types import (
25+
_SKILLS_ALL,
26+
ClaudeAgentOptions,
27+
SystemPromptFile,
28+
SystemPromptPreset,
29+
)
2530
from .._task_compat import TaskHandle, spawn_detached
2631
from . import Transport
2732

@@ -66,7 +71,7 @@ def _kill_active_children() -> None:
6671

6772
def _reject_bare_string_skills(skills: object) -> None:
6873
"""Reject a string in place of a list, which would iterate as characters."""
69-
if isinstance(skills, str) and skills != "all":
74+
if isinstance(skills, str) and skills != _SKILLS_ALL:
7075
raise TypeError(
7176
"ClaudeAgentOptions.skills must be a list of skill names or"
7277
f' "all", got the string {skills!r}. Did you mean [{skills!r}]?'
@@ -528,7 +533,7 @@ def _apply_skills_defaults(
528533
return allowed_tools, setting_sources
529534
_reject_bare_string_skills(skills)
530535

531-
if skills == "all":
536+
if skills == _SKILLS_ALL:
532537
if "Skill" not in allowed_tools:
533538
allowed_tools.append("Skill")
534539
else:

src/claude_agent_sdk/types.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from collections.abc import Awaitable, Callable
66
from dataclasses import dataclass, field
77
from pathlib import Path
8-
from typing import TYPE_CHECKING, Any, Literal, Protocol, TypeAlias
8+
from typing import TYPE_CHECKING, Any, Final, Literal, Protocol, TypeAlias
99

1010
if sys.version_info >= (3, 11):
1111
from typing import NotRequired, Required, TypedDict
@@ -31,6 +31,9 @@
3131

3232
# Agent definitions
3333
SettingSource = Literal["user", "project", "local"]
34+
35+
# The ClaudeAgentOptions.skills value meaning "every discovered skill".
36+
_SKILLS_ALL: Final = "all"
3437
EffortLevel: TypeAlias = Literal["low", "medium", "high", "xhigh", "max"]
3538

3639

@@ -1745,7 +1748,7 @@ def _warn_if_can_use_tool_shadowed(options: "ClaudeAgentOptions") -> None:
17451748
# allowed_tools, so it shadows the callback just like a hand-written entry.
17461749
# skills=[names] appends Skill(name) specifiers, which do not.
17471750
allowed_tools = options.allowed_tools
1748-
if options.skills == "all" and "Skill" not in allowed_tools:
1751+
if options.skills == _SKILLS_ALL and "Skill" not in allowed_tools:
17491752
allowed_tools = [*allowed_tools, "Skill"]
17501753
message = _get_can_use_tool_shadowed_warning(options.permission_mode, allowed_tools)
17511754
if message is not None:
@@ -2009,6 +2012,8 @@ class ClaudeAgentOptions:
20092012
- ``"all"``: enable every discovered skill.
20102013
- ``list[str]``: enable only the listed skills. Names match the SKILL.md
20112014
``name`` / directory name, or ``plugin:skill`` for plugin-qualified skills.
2015+
Names must be exact: wildcards, delimiters, and surrounding whitespace
2016+
raise at ``connect()``.
20122017
20132018
This is a **context filter**, not a sandbox: unlisted skills are hidden
20142019
from the model's listing and rejected by the Skill tool, but their files

0 commit comments

Comments
 (0)