modified
--- a/claude-code-features.md +++ b/claude-code-features.md @@ -1,4 +1,4 @@ -The Agent SDK is built on the same foundation as Claude Code, which means your SDK agents have access to the same filesystem-based features: project instructions (`CLAUDE.md` and rules), skills, hooks, and more. When you omit `settingSources`, `query()` reads the same filesystem settings as the Claude Code CLI: user, project, and local settings, CLAUDE.md files, and `.claude/` skills, agents, and commands. To run without these, pass `settingSources: []`, which limits the agent to what you configure programmatically. Managed policy settings and the global `~/.claude.json` config are read regardless of this option. For more information, see What settingSources does not control. +The Agent SDK is built on the same foundation as Claude Code, which means your SDK agents have access to the same filesystem-based features: project instructions (`CLAUDE.md` and rules), skills, hooks, and more. When you omit `settingSources`, `query()` reads the same filesystem settings as the Claude Code CLI: user, project, and local settings, CLAUDE.md files, and `.claude/` skills, agents, and commands. To run without these, pass `settingSources: []`. Inputs such as managed policy settings and the global `~/.claude.json` config are still read. For more information, see What settingSources does not control. ## Control filesystem settings with settingSources @@ -72,7 +72,7 @@ Managed policy settings| Endpoint-managed policy, such as an MDM plist, registry policy, or managed settings file, loads from the host. [Server-managed settings](</docs/en/server-managed-settings>) are fetched on an [eligible configuration](</docs/en/server-managed-settings#platform-availability>) when the session authenticates with a qualifying credential, such as an organization OAuth login, a directly configured API key, or a `user_oauth` [Anthropic profile](</docs/en/authentication#anthropic-profiles-and-federation-credentials>)| Endpoint policy: remove the managed settings file, plist, or registry policy from the host. Server-managed settings: an [Owner](</docs/en/server-managed-settings#access-control>) in your Claude organization controls them; you can’t disable them from the SDK `~/.claude.json` global config| Always read| Relocate with `CLAUDE_CONFIG_DIR` in `env` Auto memory at `~/.claude/projects/<project>/memory/`| Loaded into the system prompt at session start. The agent writes new memories there with the standard `Write` and `Edit` tools rather than a dedicated memory tool, so those tools must be enabled for the agent to save memories| Set `autoMemoryEnabled: false` in settings, or `CLAUDE_CODE_DISABLE_AUTO_MEMORY=1` in `env` -[claude.ai MCP connectors](</docs/en/mcp#use-mcp-servers-from-claude-ai>)| Loaded when the session authenticates with your claude.ai login. Not loaded when `CLAUDE_CODE_OAUTH_TOKEN` holds a token from [`claude setup-token`](</docs/en/authentication#generate-a-long-lived-token>), which can only make model requests. Passing `mcpServers: {}` does not suppress the connectors| Set `strictMcpConfig: true`, [`disableClaudeAiConnectors: true`](</docs/en/mcp#disable-claude-ai-connectors>) in settings, or `ENABLE_CLAUDEAI_MCP_SERVERS=false` in `env` +[claude.ai MCP connectors](</docs/en/mcp#use-mcp-servers-from-claude-ai>)| Loaded when the session authenticates with your claude.ai login. Not loaded when `CLAUDE_CODE_OAUTH_TOKEN` holds a token from [`claude setup-token`](</docs/en/authentication#generate-a-long-lived-token>). Passing `mcpServers: {}` does not suppress the connectors| Set `strictMcpConfig: true`, [`disableClaudeAiConnectors: true`](</docs/en/mcp#disable-claude-ai-connectors>) in settings, or `ENABLE_CLAUDEAI_MCP_SERVERS=false` in `env` [`sandbox.credentials`](</docs/en/sandboxing#protect-credentials>) `deny` entries and file `mask` entries in `~/.claude/settings.json`| When the [command sandbox](</docs/en/sandboxing>) runs, Claude Code applies the `deny` entries and keeps the `credentials.files` `mask` entries as restrictions even when `settingSources` excludes user settings. Claude Code uses these entries only to narrow what sandboxed commands can access| Remove the entries from `~/.claude/settings.json` Do not rely on default `query()` options for multi-tenant isolation. Because the inputs above are read regardless of `settingSources`, an SDK process can pick up host-level configuration and per-directory memory. For multi-tenant deployments, run each tenant in its own filesystem and set `settingSources: []` plus `CLAUDE_CODE_DISABLE_AUTO_MEMORY=1` in `env`. [Server-managed settings](</docs/en/server-managed-settings>) are fetched when the process authenticates with an organization credential; filesystem isolation does not remove them. See [Secure deployment](</docs/en/agent-sdk/secure-deployment>).
modified
--- a/claude-code-features.md +++ b/claude-code-features.md @@ -101,7 +101,7 @@ ## Skills -Skills are markdown files that give your agent specialized knowledge and invocable workflows. Unlike `CLAUDE.md` (which loads every session), skills load on demand. The agent receives skill descriptions at startup and loads the full content when relevant. Skills are discovered from the filesystem through `settingSources`. When the `skills` option on `query()` is omitted, discovered user and project skills are enabled and the Skill tool is available, matching CLI behavior. To control which skills are enabled, pass `skills` as `"all"`, a list of skill names, or `[]` to disable all. When `skills` is set, the SDK adds the Skill tool to `allowedTools` automatically. If you also pass an explicit `tools` list, include `"Skill"` in that list so Claude can invoke skills. +Skills are markdown files that give your agent specialized knowledge and invocable workflows. Unlike `CLAUDE.md` (which loads every session), skills load on demand. The agent receives skill descriptions at startup and loads the full content when relevant. Skills are discovered from the filesystem through `settingSources`. When the `skills` option on `query()` is omitted, discovered user and project skills are enabled and the Skill tool is available, matching CLI behavior. To control which skills the main agent can invoke, pass `skills` as `"all"`, a list of skill names, or `[]` to disable all. If you also pass a `tools` list, include `"Skill"` so Claude can invoke skills. Python @@ -152,7 +152,7 @@ * **Filesystem hooks:** shell commands defined in `settings.json`, loaded when `settingSources` includes the relevant source. These are the same hooks you’d configure for [interactive Claude Code sessions](</docs/en/hooks-guide>). * **Programmatic hooks:** callback functions passed directly to `query()`. These run in your application process and can return structured decisions. See [Control execution with hooks](</docs/en/agent-sdk/hooks>). -Hook callbacks receive the tool input and return a decision dict. Returning `{}` means allow the tool to proceed. To block execution, return a `hookSpecificOutput` object with `permissionDecision: "deny"` and a `permissionDecisionReason`. The reason is sent to Claude as the tool result. See the [hooks guide](</docs/en/agent-sdk/hooks>) for the full callback signature and return types. +Hook callbacks receive the tool input and return a decision dict. For `PreToolUse`, return `{}` to make no decision, so the normal [permission flow](</docs/en/agent-sdk/permissions#how-permissions-are-evaluated>) applies. To block execution, return a `hookSpecificOutput` object with `permissionDecision: "deny"` and a `permissionDecisionReason`. The reason is sent to Claude as the tool result. See the [hooks guide](</docs/en/agent-sdk/hooks>) for the full callback signature and return types. Python @@ -175,7 +175,7 @@ "permissionDecisionReason": "Destructive command blocked", } } - return {} # Empty dict: allow the tool to proceed + return {} # Empty dict: no decision, normal permissions apply # Filesystem hooks from .claude/settings.json run automatically # when settingSources loads them. You can also add programmatic hooks: @@ -213,7 +213,7 @@ }, }; } - return {}; // Empty object: allow the tool to proceed + return {}; // Empty object: no decision, normal permissions apply }; // Filesystem hooks from .claude/settings.json run automatically
modified
Show diff (114 lines)
--- a/claude-code-features.md +++ b/claude-code-features.md @@ -1,10 +1,6 @@ The Agent SDK is built on the same foundation as Claude Code, which means your SDK agents have access to the same filesystem-based features: project instructions (`CLAUDE.md` and rules), skills, hooks, and more. When you omit `settingSources`, `query()` reads the same filesystem settings as the Claude Code CLI: user, project, and local settings, CLAUDE.md files, and `.claude/` skills, agents, and commands. To run without these, pass `settingSources: []`, which limits the agent to what you configure programmatically. Managed policy settings and the global `~/.claude.json` config are read regardless of this option. For more information, see What settingSources does not control. -## - -​ - -Control filesystem settings with settingSources +## Control filesystem settings with settingSources The setting sources option ([`setting_sources`](</docs/en/agent-sdk/python#claudeagentoptions>) in Python, [`settingSources`](</docs/en/agent-sdk/typescript#settingsource>) in TypeScript) controls which filesystem-based settings the SDK loads. Pass an explicit list to opt in to specific sources, or pass an empty array to disable user, project, and local settings. This example loads both user-level and project-level settings by setting `settingSources` to `["user", "project"]`: @@ -67,11 +63,7 @@ Omitting `settingSources` is equivalent to `["user", "project", "local"]`. The `cwd` option determines where the SDK looks for project-level inputs. Project `settings.json` loads from `<cwd>/.claude/` with no parent-directory fallback. -### - -​ - -What settingSources does not control +### What settingSources does not control `settingSources` covers user, project, and local settings. A few inputs are read regardless of its value: @@ -85,19 +77,11 @@ Do not rely on default `query()` options for multi-tenant isolation. Because the inputs above are read regardless of `settingSources`, an SDK process can pick up host-level configuration and per-directory memory. For multi-tenant deployments, run each tenant in its own filesystem and set `settingSources: []` plus `CLAUDE_CODE_DISABLE_AUTO_MEMORY=1` in `env`. [Server-managed settings](</docs/en/server-managed-settings>) are fetched when the process authenticates with an organization credential; filesystem isolation does not remove them. See [Secure deployment](</docs/en/agent-sdk/secure-deployment>). -## - -​ - -Project instructions (CLAUDE.md and rules) +## Project instructions (CLAUDE.md and rules) `CLAUDE.md` files and `.claude/rules/*.md` files give your agent persistent context about your project: coding conventions, build commands, architecture decisions, and instructions. When `settingSources` includes `"project"`, as in the `settingSources` example, the SDK loads these files into context at session start. The agent then follows your project conventions without you repeating them in every prompt. -### - -​ - -CLAUDE.md load locations +### CLAUDE.md load locations Level| Location| When loaded ---|---|--- @@ -115,11 +99,7 @@ For how to structure and organize CLAUDE.md content, see [Manage Claude’s memory](</docs/en/memory>). -## - -​ - -Skills +## Skills Skills are markdown files that give your agent specialized knowledge and invocable workflows. Unlike `CLAUDE.md` (which loads every session), skills load on demand. The agent receives skill descriptions at startup and loads the full content when relevant. Skills are discovered from the filesystem through `settingSources`. When the `skills` option on `query()` is omitted, discovered user and project skills are enabled and the Skill tool is available, matching CLI behavior. To control which skills are enabled, pass `skills` as `"all"`, a list of skill names, or `[]` to disable all. When `skills` is set, the SDK adds the Skill tool to `allowedTools` automatically. If you also pass an explicit `tools` list, include `"Skill"` in that list so Claude can invoke skills. @@ -165,11 +145,7 @@ Skills must be created as filesystem artifacts (`.claude/skills/<name>/SKILL.md`). The SDK does not have a programmatic API for registering skills. See [Agent Skills in the SDK](</docs/en/agent-sdk/skills>) for full details. -## - -​ - -Hooks +## Hooks The SDK supports two ways to define hooks, and they run side by side: @@ -256,11 +232,7 @@ } } -### - -​ - -When to use which hook type +### When to use which hook type Hook type| Best for ---|--- @@ -271,11 +243,7 @@ For full details on programmatic hooks, see [Control execution with hooks](</docs/en/agent-sdk/hooks>). For filesystem hook syntax, see [Hooks](</docs/en/hooks>). -## - -​ - -Choose the right feature +## Choose the right feature The Agent SDK gives you access to several ways to extend your agent’s behavior. If you’re unsure which to use, this table maps common goals to the right approach. @@ -291,11 +259,7 @@ Every feature you enable adds to your agent’s context window. For per-feature costs and how these features layer together, see [Extend Claude Code](</docs/en/features-overview#understand-context-costs>). -## - -​ - -Related resources +## Related resources * [Extend Claude Code](</docs/en/features-overview>): Conceptual overview of all extension features, with comparison tables and context cost analysis * [Skills in the SDK](</docs/en/agent-sdk/skills>): Full guide to using skills programmatically
modified
--- a/claude-code-features.md +++ b/claude-code-features.md @@ -63,9 +63,9 @@ ---|---|--- `"project"`| Project `settings.json` and hooks; project CLAUDE.md and `.claude/rules/*.md`; project skills, commands, and subagents| `<cwd>/.claude/` for `settings.json` and hooks; `<cwd>` and every parent directory for CLAUDE.md and rules; `<cwd>` and every parent directory up to the repository root for skills, commands, and subagents, plus the `.claude/skills/`, `.claude/commands/`, and `.claude/agents/` folders of each directory you pass through the `additionalDirectories` or `add_dirs` option, which the SDK passes to Claude Code as [`--add-dir`](</docs/en/permissions#additional-directories-grant-file-access-not-configuration>) `"user"`| User `settings.json`; user CLAUDE.md and `~/.claude/rules/*.md`; user skills, commands, and subagents| `~/.claude/` for `settings.json`, CLAUDE.md, and rules; `~/.claude/skills/`, `~/.claude/commands/`, and `~/.claude/agents/` for skills, commands, and subagents -`"local"`| CLAUDE.local.md, `.claude/settings.local.json`| `<cwd>/.claude/` for `settings.local.json`; `<cwd>` and every parent directory for CLAUDE.local.md - -Omitting `settingSources` is equivalent to `["user", "project", "local"]`. The `cwd` option determines where the SDK looks for project-level inputs. Project `settings.json` and hooks load only from `<cwd>/.claude/` with no parent-directory fallback. +`"local"`| CLAUDE.local.md, `.claude/settings.local.json`| `<cwd>/.claude/` for `settings.local.json`, which [can also load from the repository’s root](</docs/en/settings#where-claude-code-keeps-the-local-file-in-a-git-repository>) when `<cwd>` is inside a git repository; `<cwd>` and every parent directory for CLAUDE.local.md + +Omitting `settingSources` is equivalent to `["user", "project", "local"]`. The `cwd` option determines where the SDK looks for project-level inputs. Project `settings.json` loads from `<cwd>/.claude/` with no parent-directory fallback. ###
modified
--- a/claude-code-features.md +++ b/claude-code-features.md @@ -104,7 +104,7 @@ Project (root)| `<cwd>/CLAUDE.md` or `<cwd>/.claude/CLAUDE.md`| `settingSources` includes `"project"` Project rules| `<cwd>/.claude/rules/*.md` and `.claude/rules/*.md` in every parent directory| `settingSources` includes `"project"` Project (parent dirs)| `CLAUDE.md` files in directories above `cwd`| `settingSources` includes `"project"`, loaded at session start -Project (child dirs)| `CLAUDE.md` files in subdirectories of `cwd`| `settingSources` includes `"project"`, loaded on demand when the agent reads a file in that subtree +Project (child dirs)| `CLAUDE.md` files in subdirectories of `cwd`| `settingSources` includes `"project"`, loaded [on demand](</docs/en/memory#how-claude-md-files-load>) Local| `<cwd>/CLAUDE.local.md` and `CLAUDE.local.md` in every parent directory| `settingSources` includes `"local"` User| `~/.claude/CLAUDE.md`| `settingSources` includes `"user"` User rules| `~/.claude/rules/*.md`| `settingSources` includes `"user"`
modified
--- a/claude-code-features.md +++ b/claude-code-features.md @@ -279,7 +279,7 @@ The Agent SDK gives you access to several ways to extend your agent’s behavior. If you’re unsure which to use, this table maps common goals to the right approach. -You want to…| Use| SDK surface +What you want to do| Use| SDK surface ---|---|--- Set project conventions your agent always follows| [CLAUDE.md](</docs/en/memory>)| `settingSources: ["project"]` loads it automatically Give the agent reference material it loads when relevant| [Skills](</docs/en/agent-sdk/skills>)| `settingSources` \+ `skills` option
modified
--- a/claude-code-features.md +++ b/claude-code-features.md @@ -1,4 +1,4 @@ -The Agent SDK is built on the same foundation as Claude Code, which means your SDK agents have access to the same filesystem-based features: project instructions (`CLAUDE.md` and rules), skills, hooks, and more. When you omit `settingSources`, `query()` reads the same filesystem settings as the Claude Code CLI: user, project, and local settings, CLAUDE.md files, and `.claude/` skills, agents, and commands. To run without these, pass `settingSources: []`, which limits the agent to what you configure programmatically. Managed policy settings and the global `~/.claude.json` config are read regardless of this option. See What settingSources does not control. +The Agent SDK is built on the same foundation as Claude Code, which means your SDK agents have access to the same filesystem-based features: project instructions (`CLAUDE.md` and rules), skills, hooks, and more. When you omit `settingSources`, `query()` reads the same filesystem settings as the Claude Code CLI: user, project, and local settings, CLAUDE.md files, and `.claude/` skills, agents, and commands. To run without these, pass `settingSources: []`, which limits the agent to what you configure programmatically. Managed policy settings and the global `~/.claude.json` config are read regardless of this option. For more information, see What settingSources does not control. ## @@ -91,7 +91,7 @@ Project instructions (CLAUDE.md and rules) -`CLAUDE.md` files and `.claude/rules/*.md` files give your agent persistent context about your project: coding conventions, build commands, architecture decisions, and instructions. When `settingSources` includes `"project"` (as in the example above), the SDK loads these files into context at session start. The agent then follows your project conventions without you repeating them in every prompt. +`CLAUDE.md` files and `.claude/rules/*.md` files give your agent persistent context about your project: coding conventions, build commands, architecture decisions, and instructions. When `settingSources` includes `"project"`, as in the `settingSources` example, the SDK loads these files into context at session start. The agent then follows your project conventions without you repeating them in every prompt. ###
modified
--- a/claude-code-features.md +++ b/claude-code-features.md @@ -176,7 +176,7 @@ * **Filesystem hooks:** shell commands defined in `settings.json`, loaded when `settingSources` includes the relevant source. These are the same hooks you’d configure for [interactive Claude Code sessions](</docs/en/hooks-guide>). * **Programmatic hooks:** callback functions passed directly to `query()`. These run in your application process and can return structured decisions. See [Control execution with hooks](</docs/en/agent-sdk/hooks>). -Both types execute during the same hook lifecycle. If you already have hooks in your project’s `.claude/settings.json` and you set `settingSources: ["project"]`, those hooks run automatically in the SDK with no extra configuration. Hook callbacks receive the tool input and return a decision dict. Returning `{}` means allow the tool to proceed. To block execution, return a `hookSpecificOutput` object with `permissionDecision: "deny"` and a `permissionDecisionReason`. The reason is sent to Claude as the tool result. See the [hooks guide](</docs/en/agent-sdk/hooks>) for the full callback signature and return types. +Hook callbacks receive the tool input and return a decision dict. Returning `{}` means allow the tool to proceed. To block execution, return a `hookSpecificOutput` object with `permissionDecision: "deny"` and a `permissionDecisionReason`. The reason is sent to Claude as the tool result. See the [hooks guide](</docs/en/agent-sdk/hooks>) for the full callback signature and return types. Python
modified
--- a/claude-code-features.md +++ b/claude-code-features.md @@ -77,7 +77,7 @@ Input| Behavior| To disable ---|---|--- -Managed policy settings| Endpoint-managed policy, such as an MDM plist, registry policy, or managed settings file, loads from the host. [Server-managed settings](</docs/en/server-managed-settings>) are fetched on an [eligible configuration](</docs/en/server-managed-settings#platform-availability>) when the session authenticates with an organization OAuth login or a directly configured API key| Endpoint policy: remove the managed settings file, plist, or registry policy from the host. Server-managed settings: controlled by your org admin; cannot be disabled from the SDK +Managed policy settings| Endpoint-managed policy, such as an MDM plist, registry policy, or managed settings file, loads from the host. [Server-managed settings](</docs/en/server-managed-settings>) are fetched on an [eligible configuration](</docs/en/server-managed-settings#platform-availability>) when the session authenticates with a qualifying credential, such as an organization OAuth login, a directly configured API key, or a `user_oauth` [Anthropic profile](</docs/en/authentication#anthropic-profiles-and-federation-credentials>)| Endpoint policy: remove the managed settings file, plist, or registry policy from the host. Server-managed settings: an [Owner](</docs/en/server-managed-settings#access-control>) in your Claude organization controls them; you can’t disable them from the SDK `~/.claude.json` global config| Always read| Relocate with `CLAUDE_CONFIG_DIR` in `env` Auto memory at `~/.claude/projects/<project>/memory/`| Loaded into the system prompt at session start. The agent writes new memories there with the standard `Write` and `Edit` tools rather than a dedicated memory tool, so those tools must be enabled for the agent to save memories| Set `autoMemoryEnabled: false` in settings, or `CLAUDE_CODE_DISABLE_AUTO_MEMORY=1` in `env` [claude.ai MCP connectors](</docs/en/mcp#use-mcp-servers-from-claude-ai>)| Loaded when the session authenticates with your claude.ai login. Not loaded when `CLAUDE_CODE_OAUTH_TOKEN` holds a token from [`claude setup-token`](</docs/en/authentication#generate-a-long-lived-token>), which can only make model requests. Passing `mcpServers: {}` does not suppress the connectors| Set `strictMcpConfig: true`, [`disableClaudeAiConnectors: true`](</docs/en/mcp#disable-claude-ai-connectors>) in settings, or `ENABLE_CLAUDEAI_MCP_SERVERS=false` in `env`
modified
--- a/claude-code-features.md +++ b/claude-code-features.md @@ -1,4 +1,4 @@ -The Agent SDK is built on the same foundation as Claude Code, which means your SDK agents have access to the same filesystem-based features: project instructions (`CLAUDE.md` and rules), skills, hooks, and more. When you omit `settingSources`, `query()` reads the same filesystem settings as the Claude Code CLI: user, project, and local settings, CLAUDE.md files, and `.claude/` skills, agents, and commands. To run without these, pass `settingSources: []`, which limits the agent to what you configure programmatically. Managed policy settings and the global `~/.claude.json` config are read regardless of this option. See What settingSources does not control. For a conceptual overview of what each feature does and when to use it, see [Extend Claude Code](</docs/en/features-overview>). +The Agent SDK is built on the same foundation as Claude Code, which means your SDK agents have access to the same filesystem-based features: project instructions (`CLAUDE.md` and rules), skills, hooks, and more. When you omit `settingSources`, `query()` reads the same filesystem settings as the Claude Code CLI: user, project, and local settings, CLAUDE.md files, and `.claude/` skills, agents, and commands. To run without these, pass `settingSources: []`, which limits the agent to what you configure programmatically. Managed policy settings and the global `~/.claude.json` config are read regardless of this option. See What settingSources does not control. ## @@ -81,6 +81,7 @@ `~/.claude.json` global config| Always read| Relocate with `CLAUDE_CONFIG_DIR` in `env` Auto memory at `~/.claude/projects/<project>/memory/`| Loaded into the system prompt at session start. The agent writes new memories there with the standard `Write` and `Edit` tools rather than a dedicated memory tool, so those tools must be enabled for the agent to save memories| Set `autoMemoryEnabled: false` in settings, or `CLAUDE_CODE_DISABLE_AUTO_MEMORY=1` in `env` [claude.ai MCP connectors](</docs/en/mcp#use-mcp-servers-from-claude-ai>)| Loaded when the session authenticates with your claude.ai login. Not loaded when `CLAUDE_CODE_OAUTH_TOKEN` holds a token from [`claude setup-token`](</docs/en/authentication#generate-a-long-lived-token>), which can only make model requests. Passing `mcpServers: {}` does not suppress the connectors| Set `strictMcpConfig: true`, [`disableClaudeAiConnectors: true`](</docs/en/mcp#disable-claude-ai-connectors>) in settings, or `ENABLE_CLAUDEAI_MCP_SERVERS=false` in `env` +[`sandbox.credentials`](</docs/en/sandboxing#protect-credentials>) `deny` entries and file `mask` entries in `~/.claude/settings.json`| When the [command sandbox](</docs/en/sandboxing>) runs, Claude Code applies the `deny` entries and keeps the `credentials.files` `mask` entries as restrictions even when `settingSources` excludes user settings. Claude Code uses these entries only to narrow what sandboxed commands can access| Remove the entries from `~/.claude/settings.json` Do not rely on default `query()` options for multi-tenant isolation. Because the inputs above are read regardless of `settingSources`, an SDK process can pick up host-level configuration and per-directory memory. For multi-tenant deployments, run each tenant in its own filesystem and set `settingSources: []` plus `CLAUDE_CODE_DISABLE_AUTO_MEMORY=1` in `env`. [Server-managed settings](</docs/en/server-managed-settings>) are fetched when the process authenticates with an organization credential; filesystem isolation does not remove them. See [Secure deployment](</docs/en/agent-sdk/secure-deployment>). @@ -288,8 +289,6 @@ Run deterministic logic on tool calls (audit, block, transform)| [Hooks](</docs/en/agent-sdk/hooks>)| `hooks` parameter with callbacks, or shell scripts loaded via `settingSources` Give Claude structured tool access to an external service| [MCP](</docs/en/agent-sdk/mcp>)| `mcpServers` parameter -**Subagents versus agent teams:** Subagents are ephemeral and isolated: fresh conversation, one task, summary returned to parent. Agent teams coordinate multiple independent Claude Code instances that share a task list and message each other directly. Agent teams are a CLI feature. See [What subagents inherit](</docs/en/agent-sdk/subagents#what-subagents-inherit>) and the [agent teams comparison](</docs/en/agent-teams#compare-with-subagents>) for details. - Every feature you enable adds to your agent’s context window. For per-feature costs and how these features layer together, see [Extend Claude Code](</docs/en/features-overview#understand-context-costs>). ##
modified
--- a/claude-code-features.md +++ b/claude-code-features.md @@ -61,8 +61,8 @@ Source| What it loads| Location ---|---|--- -`"project"`| Project CLAUDE.md, `.claude/rules/*.md`, project skills, project hooks, project `settings.json`| `<cwd>/.claude/` for `settings.json` and hooks; `<cwd>` and every parent directory for CLAUDE.md and rules; `<cwd>` and every parent directory up to the repository root for skills -`"user"`| User CLAUDE.md, `~/.claude/rules/*.md`, user skills, user settings| `~/.claude/` +`"project"`| Project `settings.json` and hooks; project CLAUDE.md and `.claude/rules/*.md`; project skills, commands, and subagents| `<cwd>/.claude/` for `settings.json` and hooks; `<cwd>` and every parent directory for CLAUDE.md and rules; `<cwd>` and every parent directory up to the repository root for skills, commands, and subagents, plus the `.claude/skills/`, `.claude/commands/`, and `.claude/agents/` folders of each directory you pass through the `additionalDirectories` or `add_dirs` option, which the SDK passes to Claude Code as [`--add-dir`](</docs/en/permissions#additional-directories-grant-file-access-not-configuration>) +`"user"`| User `settings.json`; user CLAUDE.md and `~/.claude/rules/*.md`; user skills, commands, and subagents| `~/.claude/` for `settings.json`, CLAUDE.md, and rules; `~/.claude/skills/`, `~/.claude/commands/`, and `~/.claude/agents/` for skills, commands, and subagents `"local"`| CLAUDE.local.md, `.claude/settings.local.json`| `<cwd>/.claude/` for `settings.local.json`; `<cwd>` and every parent directory for CLAUDE.local.md Omitting `settingSources` is equivalent to `["user", "project", "local"]`. The `cwd` option determines where the SDK looks for project-level inputs. Project `settings.json` and hooks load only from `<cwd>/.claude/` with no parent-directory fallback.
modified
--- a/claude-code-features.md +++ b/claude-code-features.md @@ -65,7 +65,7 @@ `"user"`| User CLAUDE.md, `~/.claude/rules/*.md`, user skills, user settings| `~/.claude/` `"local"`| CLAUDE.local.md, `.claude/settings.local.json`| `<cwd>/.claude/` for `settings.local.json`; `<cwd>` and every parent directory for CLAUDE.local.md -Omitting `settingSources` is equivalent to `["user", "project", "local"]`. The `cwd` option determines where the SDK looks for project-level inputs. CLAUDE.md and rules load from `<cwd>` and from every parent directory. Skills load from `<cwd>` and from every parent directory up to the repository root. Project `settings.json` and hooks load only from `<cwd>/.claude/` with no parent-directory fallback. +Omitting `settingSources` is equivalent to `["user", "project", "local"]`. The `cwd` option determines where the SDK looks for project-level inputs. Project `settings.json` and hooks load only from `<cwd>/.claude/` with no parent-directory fallback. ### @@ -164,8 +164,6 @@ Skills must be created as filesystem artifacts (`.claude/skills/<name>/SKILL.md`). The SDK does not have a programmatic API for registering skills. See [Agent Skills in the SDK](</docs/en/agent-sdk/skills>) for full details. -For more on creating and using skills, see [Agent Skills in the SDK](</docs/en/agent-sdk/skills>). - ## ​ @@ -177,7 +175,7 @@ * **Filesystem hooks:** shell commands defined in `settings.json`, loaded when `settingSources` includes the relevant source. These are the same hooks you’d configure for [interactive Claude Code sessions](</docs/en/hooks-guide>). * **Programmatic hooks:** callback functions passed directly to `query()`. These run in your application process and can return structured decisions. See [Control execution with hooks](</docs/en/agent-sdk/hooks>). -Both types execute during the same hook lifecycle. If you already have hooks in your project’s `.claude/settings.json` and you set `settingSources: ["project"]`, those hooks run automatically in the SDK with no extra configuration. Hook callbacks receive the tool input and return a decision dict. Returning `{}` means allow the tool to proceed. To block execution, return a `hookSpecificOutput` object with `permissionDecision: "deny"` and a `permissionDecisionReason`. The reason is sent to Claude as the tool result. The top-level `decision` and `reason` fields are deprecated for `PreToolUse`. See the [hooks guide](</docs/en/agent-sdk/hooks>) for the full callback signature and return types. +Both types execute during the same hook lifecycle. If you already have hooks in your project’s `.claude/settings.json` and you set `settingSources: ["project"]`, those hooks run automatically in the SDK with no extra configuration. Hook callbacks receive the tool input and return a decision dict. Returning `{}` means allow the tool to proceed. To block execution, return a `hookSpecificOutput` object with `permissionDecision: "deny"` and a `permissionDecisionReason`. The reason is sent to Claude as the tool result. See the [hooks guide](</docs/en/agent-sdk/hooks>) for the full callback signature and return types. Python
modified
--- a/claude-code-features.md +++ b/claude-code-features.md @@ -80,7 +80,7 @@ Managed policy settings| Endpoint-managed policy, such as an MDM plist, registry policy, or managed settings file, loads from the host. [Server-managed settings](</docs/en/server-managed-settings>) are fetched on an [eligible configuration](</docs/en/server-managed-settings#platform-availability>) when the session authenticates with an organization OAuth login or a directly configured API key| Endpoint policy: remove the managed settings file, plist, or registry policy from the host. Server-managed settings: controlled by your org admin; cannot be disabled from the SDK `~/.claude.json` global config| Always read| Relocate with `CLAUDE_CONFIG_DIR` in `env` Auto memory at `~/.claude/projects/<project>/memory/`| Loaded into the system prompt at session start. The agent writes new memories there with the standard `Write` and `Edit` tools rather than a dedicated memory tool, so those tools must be enabled for the agent to save memories| Set `autoMemoryEnabled: false` in settings, or `CLAUDE_CODE_DISABLE_AUTO_MEMORY=1` in `env` -[claude.ai MCP connectors](</docs/en/mcp#use-mcp-servers-from-claude-ai>)| Loaded when the active authentication method is a claude.ai subscription. Passing `mcpServers: {}` does not suppress them| Set `strictMcpConfig: true`, [`disableClaudeAiConnectors: true`](</docs/en/mcp#disable-claude-ai-connectors>) in settings, or `ENABLE_CLAUDEAI_MCP_SERVERS=false` in `env` +[claude.ai MCP connectors](</docs/en/mcp#use-mcp-servers-from-claude-ai>)| Loaded when the session authenticates with your claude.ai login. Not loaded when `CLAUDE_CODE_OAUTH_TOKEN` holds a token from [`claude setup-token`](</docs/en/authentication#generate-a-long-lived-token>), which can only make model requests. Passing `mcpServers: {}` does not suppress the connectors| Set `strictMcpConfig: true`, [`disableClaudeAiConnectors: true`](</docs/en/mcp#disable-claude-ai-connectors>) in settings, or `ENABLE_CLAUDEAI_MCP_SERVERS=false` in `env` Do not rely on default `query()` options for multi-tenant isolation. Because the inputs above are read regardless of `settingSources`, an SDK process can pick up host-level configuration and per-directory memory. For multi-tenant deployments, run each tenant in its own filesystem and set `settingSources: []` plus `CLAUDE_CODE_DISABLE_AUTO_MEMORY=1` in `env`. [Server-managed settings](</docs/en/server-managed-settings>) are fetched when the process authenticates with an organization credential; filesystem isolation does not remove them. See [Secure deployment](</docs/en/agent-sdk/secure-deployment>).
modified
Show diff (149 lines)
--- a/claude-code-features.md +++ b/claude-code-features.md @@ -13,23 +13,27 @@ TypeScript from claude_agent_sdk import query, ClaudeAgentOptions, AssistantMessage, ResultMessage - - async for message in query( - prompt="Help me refactor the auth module", - options=ClaudeAgentOptions( - # "user" loads from ~/.claude/, "project" loads from ./.claude/ in cwd. - # Together they give the agent access to CLAUDE.md, skills, hooks, and - # permissions from both locations. - setting_sources=["user", "project"], - allowed_tools=["Read", "Edit", "Bash"], - ), - ): - if isinstance(message, AssistantMessage): - for block in message.content: - if hasattr(block, "text"): - print(block.text) - if isinstance(message, ResultMessage) and message.subtype == "success": - print(f"\nResult: {message.result}") + import asyncio + + async def main(): + async for message in query( + prompt="Help me refactor the auth module", + options=ClaudeAgentOptions( + # "user" loads from ~/.claude/, "project" loads from ./.claude/ in cwd. + # Together they give the agent access to CLAUDE.md, skills, hooks, and + # permissions from both locations. + setting_sources=["user", "project"], + allowed_tools=["Read", "Edit", "Bash"], + ), + ): + if isinstance(message, AssistantMessage): + for block in message.content: + if hasattr(block, "text"): + print(block.text) + if isinstance(message, ResultMessage) and message.subtype == "success": + print(f"\nResult: {message.result}") + + asyncio.run(main()) import { query } from "@anthropic-ai/claude-agent-sdk"; @@ -53,7 +57,7 @@ } } -Each source loads settings from a specific location, where `<cwd>` is the working directory you pass via the `cwd` option, or the process’s current directory if unset. For the full type definition, see [`SettingSource`](</docs/en/agent-sdk/typescript#settingsource>) (TypeScript) or [`SettingSource`](</docs/en/agent-sdk/python#settingsource>) (Python). +When this runs, the assistant’s response prints to stdout, followed by a final result line once the run completes. Each source loads settings from a specific location, where `<cwd>` is the working directory you pass via the `cwd` option, or the process’s current directory if unset. For the full type definition, see [`SettingSource`](</docs/en/agent-sdk/typescript#settingsource>) (TypeScript) or [`SettingSource`](</docs/en/agent-sdk/python#settingsource>) (Python). Source| What it loads| Location ---|---|--- @@ -123,19 +127,23 @@ TypeScript from claude_agent_sdk import query, ClaudeAgentOptions, ResultMessage + import asyncio # Skills in .claude/skills/ are discovered automatically # when settingSources includes "project" - async for message in query( - prompt="Review this PR using our code review checklist", - options=ClaudeAgentOptions( - setting_sources=["user", "project"], - skills="all", - allowed_tools=["Read", "Grep", "Glob"], - ), - ): - if isinstance(message, ResultMessage) and message.subtype == "success": - print(message.result) + async def main(): + async for message in query( + prompt="Review this PR using our code review checklist", + options=ClaudeAgentOptions( + setting_sources=["user", "project"], + skills="all", + allowed_tools=["Read", "Grep", "Glob"], + ), + ): + if isinstance(message, ResultMessage) and message.subtype == "success": + print(message.result) + + asyncio.run(main()) import { query } from "@anthropic-ai/claude-agent-sdk"; @@ -176,11 +184,12 @@ TypeScript from claude_agent_sdk import query, ClaudeAgentOptions, HookMatcher, ResultMessage + import asyncio # PreToolUse hook callback. Positional args: # input_data: HookInput dict with tool_name, tool_input, hook_event_name # tool_use_id: str | None, the ID of the tool call being intercepted - # context: HookContext, carries session metadata + # context: HookContext, reserved for future abort-signal support async def audit_bash(input_data, tool_use_id, context): command = input_data.get("tool_input", {}).get("command", "") if "rm -rf" in command: @@ -195,19 +204,22 @@ # Filesystem hooks from .claude/settings.json run automatically # when settingSources loads them. You can also add programmatic hooks: - async for message in query( - prompt="Refactor the auth module", - options=ClaudeAgentOptions( - setting_sources=["project"], # Loads hooks from .claude/settings.json - hooks={ - "PreToolUse": [ - HookMatcher(matcher="Bash", hooks=[audit_bash]), - ] - }, - ), - ): - if isinstance(message, ResultMessage) and message.subtype == "success": - print(message.result) + async def main(): + async for message in query( + prompt="Refactor the auth module", + options=ClaudeAgentOptions( + setting_sources=["project"], # Loads hooks from .claude/settings.json + hooks={ + "PreToolUse": [ + HookMatcher(matcher="Bash", hooks=[audit_bash]), + ] + }, + ), + ): + if isinstance(message, ResultMessage) and message.subtype == "success": + print(message.result) + + asyncio.run(main()) import { query, type HookInput, type HookJSONOutput } from "@anthropic-ai/claude-agent-sdk"; @@ -254,7 +266,7 @@ Hook type| Best for ---|--- **Filesystem** (`settings.json`)| Sharing hooks between CLI and SDK sessions. Supports `"command"` (shell scripts), `"http"` (POST to an endpoint), `"mcp_tool"` (call a connected MCP server’s tool), `"prompt"` (LLM evaluates a prompt), and `"agent"` (spawns a verifier agent). These fire in the main agent and any subagents it spawns. -**Programmatic** (callbacks in `query()`)| Application-specific logic, structured decisions, and in-process integration. These also fire inside subagents. The callback receives `agent_id` and `agent_type` to distinguish. +**Programmatic** (callbacks in `query()`)| Application-specific logic, structured decisions, and in-process integration. These also fire inside subagents. The hook input, the callback’s first argument, carries `agent_id` and `agent_type` fields that identify which agent fired the hook. The TypeScript SDK supports additional hook events beyond Python, including `SessionStart`, `SessionEnd`, `TeammateIdle`, and `TaskCompleted`. See the [hooks guide](</docs/en/agent-sdk/hooks>) for the full event compatibility table.
modified
--- a/claude-code-features.md +++ b/claude-code-features.md @@ -31,6 +31,28 @@ if isinstance(message, ResultMessage) and message.subtype == "success": print(f"\nResult: {message.result}") + import { query } from "@anthropic-ai/claude-agent-sdk"; + + for await (const message of query({ + prompt: "Help me refactor the auth module", + options: { + // "user" loads from ~/.claude/, "project" loads from ./.claude/ in cwd. + // Together they give the agent access to CLAUDE.md, skills, hooks, and + // permissions from both locations. + settingSources: ["user", "project"], + allowedTools: ["Read", "Edit", "Bash"] + } + })) { + if (message.type === "assistant") { + for (const block of message.message.content) { + if (block.type === "text") console.log(block.text); + } + } + if (message.type === "result" && message.subtype === "success") { + console.log(`\nResult: ${message.result}`); + } + } + Each source loads settings from a specific location, where `<cwd>` is the working directory you pass via the `cwd` option, or the process’s current directory if unset. For the full type definition, see [`SettingSource`](</docs/en/agent-sdk/typescript#settingsource>) (TypeScript) or [`SettingSource`](</docs/en/agent-sdk/python#settingsource>) (Python). Source| What it loads| Location @@ -114,6 +136,23 @@ ): if isinstance(message, ResultMessage) and message.subtype == "success": print(message.result) + + import { query } from "@anthropic-ai/claude-agent-sdk"; + + // Skills in .claude/skills/ are discovered automatically + // when settingSources includes "project" + for await (const message of query({ + prompt: "Review this PR using our code review checklist", + options: { + settingSources: ["user", "project"], + skills: "all", + allowedTools: ["Read", "Grep", "Glob"] + } + })) { + if (message.type === "result" && message.subtype === "success") { + console.log(message.result); + } + } Skills must be created as filesystem artifacts (`.claude/skills/<name>/SKILL.md`). The SDK does not have a programmatic API for registering skills. See [Agent Skills in the SDK](</docs/en/agent-sdk/skills>) for full details. @@ -170,6 +209,42 @@ if isinstance(message, ResultMessage) and message.subtype == "success": print(message.result) + import { query, type HookInput, type HookJSONOutput } from "@anthropic-ai/claude-agent-sdk"; + + // PreToolUse hook callback. HookInput is a discriminated union on + // hook_event_name, so narrowing on it gives TypeScript the right + // tool_input shape for this event. + const auditBash = async (input: HookInput): Promise<HookJSONOutput> => { + if (input.hook_event_name !== "PreToolUse") return {}; + const toolInput = input.tool_input as { command?: string }; + if (toolInput.command?.includes("rm -rf")) { + return { + hookSpecificOutput: { + hookEventName: "PreToolUse", + permissionDecision: "deny", + permissionDecisionReason: "Destructive command blocked", + }, + }; + } + return {}; // Empty object: allow the tool to proceed + }; + + // Filesystem hooks from .claude/settings.json run automatically + // when settingSources loads them. You can also add programmatic hooks: + for await (const message of query({ + prompt: "Refactor the auth module", + options: { + settingSources: ["project"], // Loads hooks from .claude/settings.json + hooks: { + PreToolUse: [{ matcher: "Bash", hooks: [auditBash] }] + } + } + })) { + if (message.type === "result" && message.subtype === "success") { + console.log(message.result); + } + } + ### ​
modified
--- a/claude-code-features.md +++ b/claude-code-features.md @@ -53,7 +53,7 @@ ---|---|--- Managed policy settings| Endpoint-managed policy, such as an MDM plist, registry policy, or managed settings file, loads from the host. [Server-managed settings](</docs/en/server-managed-settings>) are fetched on an [eligible configuration](</docs/en/server-managed-settings#platform-availability>) when the session authenticates with an organization OAuth login or a directly configured API key| Endpoint policy: remove the managed settings file, plist, or registry policy from the host. Server-managed settings: controlled by your org admin; cannot be disabled from the SDK `~/.claude.json` global config| Always read| Relocate with `CLAUDE_CONFIG_DIR` in `env` -Auto memory at `~/.claude/projects/<project>/memory/`| Loaded by default into the system prompt| Set `autoMemoryEnabled: false` in settings, or `CLAUDE_CODE_DISABLE_AUTO_MEMORY=1` in `env` +Auto memory at `~/.claude/projects/<project>/memory/`| Loaded into the system prompt at session start. The agent writes new memories there with the standard `Write` and `Edit` tools rather than a dedicated memory tool, so those tools must be enabled for the agent to save memories| Set `autoMemoryEnabled: false` in settings, or `CLAUDE_CODE_DISABLE_AUTO_MEMORY=1` in `env` [claude.ai MCP connectors](</docs/en/mcp#use-mcp-servers-from-claude-ai>)| Loaded when the active authentication method is a claude.ai subscription. Passing `mcpServers: {}` does not suppress them| Set `strictMcpConfig: true`, [`disableClaudeAiConnectors: true`](</docs/en/mcp#disable-claude-ai-connectors>) in settings, or `ENABLE_CLAUDEAI_MCP_SERVERS=false` in `env` Do not rely on default `query()` options for multi-tenant isolation. Because the inputs above are read regardless of `settingSources`, an SDK process can pick up host-level configuration and per-directory memory. For multi-tenant deployments, run each tenant in its own filesystem and set `settingSources: []` plus `CLAUDE_CODE_DISABLE_AUTO_MEMORY=1` in `env`. [Server-managed settings](</docs/en/server-managed-settings>) are fetched when the process authenticates with an organization credential; filesystem isolation does not remove them. See [Secure deployment](</docs/en/agent-sdk/secure-deployment>).
modified
--- a/claude-code-features.md +++ b/claude-code-features.md @@ -51,12 +51,12 @@ Input| Behavior| To disable ---|---|--- -Managed policy settings| Always loaded when present on the host| Remove the managed settings file +Managed policy settings| Endpoint-managed policy, such as an MDM plist, registry policy, or managed settings file, loads from the host. [Server-managed settings](</docs/en/server-managed-settings>) are fetched on an [eligible configuration](</docs/en/server-managed-settings#platform-availability>) when the session authenticates with an organization OAuth login or a directly configured API key| Endpoint policy: remove the managed settings file, plist, or registry policy from the host. Server-managed settings: controlled by your org admin; cannot be disabled from the SDK `~/.claude.json` global config| Always read| Relocate with `CLAUDE_CONFIG_DIR` in `env` Auto memory at `~/.claude/projects/<project>/memory/`| Loaded by default into the system prompt| Set `autoMemoryEnabled: false` in settings, or `CLAUDE_CODE_DISABLE_AUTO_MEMORY=1` in `env` [claude.ai MCP connectors](</docs/en/mcp#use-mcp-servers-from-claude-ai>)| Loaded when the active authentication method is a claude.ai subscription. Passing `mcpServers: {}` does not suppress them| Set `strictMcpConfig: true`, [`disableClaudeAiConnectors: true`](</docs/en/mcp#disable-claude-ai-connectors>) in settings, or `ENABLE_CLAUDEAI_MCP_SERVERS=false` in `env` -Do not rely on default `query()` options for multi-tenant isolation. Because the inputs above are read regardless of `settingSources`, an SDK process can pick up host-level configuration and per-directory memory. For multi-tenant deployments, run each tenant in its own filesystem and set `settingSources: []` plus `CLAUDE_CODE_DISABLE_AUTO_MEMORY=1` in `env`. See [Secure deployment](</docs/en/agent-sdk/secure-deployment>). +Do not rely on default `query()` options for multi-tenant isolation. Because the inputs above are read regardless of `settingSources`, an SDK process can pick up host-level configuration and per-directory memory. For multi-tenant deployments, run each tenant in its own filesystem and set `settingSources: []` plus `CLAUDE_CODE_DISABLE_AUTO_MEMORY=1` in `env`. [Server-managed settings](</docs/en/server-managed-settings>) are fetched when the process authenticates with an organization credential; filesystem isolation does not remove them. See [Secure deployment](</docs/en/agent-sdk/secure-deployment>). ##
modified
--- a/claude-code-features.md +++ b/claude-code-features.md @@ -54,7 +54,7 @@ Managed policy settings| Always loaded when present on the host| Remove the managed settings file `~/.claude.json` global config| Always read| Relocate with `CLAUDE_CONFIG_DIR` in `env` Auto memory at `~/.claude/projects/<project>/memory/`| Loaded by default into the system prompt| Set `autoMemoryEnabled: false` in settings, or `CLAUDE_CODE_DISABLE_AUTO_MEMORY=1` in `env` -[claude.ai MCP connectors](</docs/en/mcp#use-mcp-servers-from-claude-ai>)| Loaded when the active authentication method is a claude.ai subscription. Passing `mcpServers: {}` does not suppress them| Set `strictMcpConfig: true`, or `ENABLE_CLAUDEAI_MCP_SERVERS=false` in `env` +[claude.ai MCP connectors](</docs/en/mcp#use-mcp-servers-from-claude-ai>)| Loaded when the active authentication method is a claude.ai subscription. Passing `mcpServers: {}` does not suppress them| Set `strictMcpConfig: true`, [`disableClaudeAiConnectors: true`](</docs/en/mcp#disable-claude-ai-connectors>) in settings, or `ENABLE_CLAUDEAI_MCP_SERVERS=false` in `env` Do not rely on default `query()` options for multi-tenant isolation. Because the inputs above are read regardless of `settingSources`, an SDK process can pick up host-level configuration and per-directory memory. For multi-tenant deployments, run each tenant in its own filesystem and set `settingSources: []` plus `CLAUDE_CODE_DISABLE_AUTO_MEMORY=1` in `env`. See [Secure deployment](</docs/en/agent-sdk/secure-deployment>).
modified
--- a/claude-code-features.md +++ b/claude-code-features.md @@ -1,9 +1,3 @@ -> ## Documentation Index -> -> Fetch the complete documentation index at: <https://code.claude.com/docs/llms.txt> -> -> Use this file to discover all available pages before exploring further. - The Agent SDK is built on the same foundation as Claude Code, which means your SDK agents have access to the same filesystem-based features: project instructions (`CLAUDE.md` and rules), skills, hooks, and more. When you omit `settingSources`, `query()` reads the same filesystem settings as the Claude Code CLI: user, project, and local settings, CLAUDE.md files, and `.claude/` skills, agents, and commands. To run without these, pass `settingSources: []`, which limits the agent to what you configure programmatically. Managed policy settings and the global `~/.claude.json` config are read regardless of this option. See What settingSources does not control. For a conceptual overview of what each feature does and when to use it, see [Extend Claude Code](</docs/en/features-overview>). ##
modified
--- a/claude-code-features.md +++ b/claude-code-features.md @@ -60,6 +60,7 @@ Managed policy settings| Always loaded when present on the host| Remove the managed settings file `~/.claude.json` global config| Always read| Relocate with `CLAUDE_CONFIG_DIR` in `env` Auto memory at `~/.claude/projects/<project>/memory/`| Loaded by default into the system prompt| Set `autoMemoryEnabled: false` in settings, or `CLAUDE_CODE_DISABLE_AUTO_MEMORY=1` in `env` +[claude.ai MCP connectors](</docs/en/mcp#use-mcp-servers-from-claude-ai>)| Loaded when the active authentication method is a claude.ai subscription. Passing `mcpServers: {}` does not suppress them| Set `strictMcpConfig: true`, or `ENABLE_CLAUDEAI_MCP_SERVERS=false` in `env` Do not rely on default `query()` options for multi-tenant isolation. Because the inputs above are read regardless of `settingSources`, an SDK process can pick up host-level configuration and per-directory memory. For multi-tenant deployments, run each tenant in its own filesystem and set `settingSources: []` plus `CLAUDE_CODE_DISABLE_AUTO_MEMORY=1` in `env`. See [Secure deployment](</docs/en/agent-sdk/secure-deployment>). @@ -99,7 +100,7 @@ Skills -Skills are markdown files that give your agent specialized knowledge and invocable workflows. Unlike `CLAUDE.md` (which loads every session), skills load on demand. The agent receives skill descriptions at startup and loads the full content when relevant. Skills are discovered from the filesystem through `settingSources`. When the `skills` option on `query()` is omitted, discovered user and project skills are enabled and the Skill tool is available, matching CLI behavior. To control which skills are enabled, pass `skills` as `"all"`, a list of skill names, or `[]` to disable all. The SDK enables the Skill tool automatically when `skills` is set, so you do not need to add it to `allowedTools`. +Skills are markdown files that give your agent specialized knowledge and invocable workflows. Unlike `CLAUDE.md` (which loads every session), skills load on demand. The agent receives skill descriptions at startup and loads the full content when relevant. Skills are discovered from the filesystem through `settingSources`. When the `skills` option on `query()` is omitted, discovered user and project skills are enabled and the Skill tool is available, matching CLI behavior. To control which skills are enabled, pass `skills` as `"all"`, a list of skill names, or `[]` to disable all. When `skills` is set, the SDK adds the Skill tool to `allowedTools` automatically. If you also pass an explicit `tools` list, include `"Skill"` in that list so Claude can invoke skills. Python @@ -135,7 +136,7 @@ * **Filesystem hooks:** shell commands defined in `settings.json`, loaded when `settingSources` includes the relevant source. These are the same hooks you’d configure for [interactive Claude Code sessions](</docs/en/hooks-guide>). * **Programmatic hooks:** callback functions passed directly to `query()`. These run in your application process and can return structured decisions. See [Control execution with hooks](</docs/en/agent-sdk/hooks>). -Both types execute during the same hook lifecycle. If you already have hooks in your project’s `.claude/settings.json` and you set `settingSources: ["project"]`, those hooks run automatically in the SDK with no extra configuration. Hook callbacks receive the tool input and return a decision dict. Returning `{}` (an empty dict) means allow the tool to proceed. Returning `{"decision": "block", "reason": "..."}` prevents execution and the reason is sent to Claude as the tool result. See the [hooks guide](</docs/en/agent-sdk/hooks>) for the full callback signature and return types. +Both types execute during the same hook lifecycle. If you already have hooks in your project’s `.claude/settings.json` and you set `settingSources: ["project"]`, those hooks run automatically in the SDK with no extra configuration. Hook callbacks receive the tool input and return a decision dict. Returning `{}` means allow the tool to proceed. To block execution, return a `hookSpecificOutput` object with `permissionDecision: "deny"` and a `permissionDecisionReason`. The reason is sent to Claude as the tool result. The top-level `decision` and `reason` fields are deprecated for `PreToolUse`. See the [hooks guide](</docs/en/agent-sdk/hooks>) for the full callback signature and return types. Python @@ -150,7 +151,13 @@ async def audit_bash(input_data, tool_use_id, context): command = input_data.get("tool_input", {}).get("command", "") if "rm -rf" in command: - return {"decision": "block", "reason": "Destructive command blocked"} + return { + "hookSpecificOutput": { + "hookEventName": "PreToolUse", + "permissionDecision": "deny", + "permissionDecisionReason": "Destructive command blocked", + } + } return {} # Empty dict: allow the tool to proceed # Filesystem hooks from .claude/settings.json run automatically @@ -178,7 +185,7 @@ Hook type| Best for ---|--- **Filesystem** (`settings.json`)| Sharing hooks between CLI and SDK sessions. Supports `"command"` (shell scripts), `"http"` (POST to an endpoint), `"mcp_tool"` (call a connected MCP server’s tool), `"prompt"` (LLM evaluates a prompt), and `"agent"` (spawns a verifier agent). These fire in the main agent and any subagents it spawns. -**Programmatic** (callbacks in `query()`)| Application-specific logic; returning structured decisions; in-process integration. Scoped to the main session only. +**Programmatic** (callbacks in `query()`)| Application-specific logic, structured decisions, and in-process integration. These also fire inside subagents. The callback receives `agent_id` and `agent_type` to distinguish. The TypeScript SDK supports additional hook events beyond Python, including `SessionStart`, `SessionEnd`, `TeammateIdle`, and `TaskCompleted`. See the [hooks guide](</docs/en/agent-sdk/hooks>) for the full event compatibility table.
modified
--- a/claude-code-features.md +++ b/claude-code-features.md @@ -41,11 +41,11 @@ Source| What it loads| Location ---|---|--- -`"project"`| Project CLAUDE.md, `.claude/rules/*.md`, project skills, project hooks, project `settings.json`| `<cwd>/.claude/` and each parent directory up to the filesystem root (stopping when a `.claude/` is found or no more parents exist) +`"project"`| Project CLAUDE.md, `.claude/rules/*.md`, project skills, project hooks, project `settings.json`| `<cwd>/.claude/` for `settings.json` and hooks; `<cwd>` and every parent directory for CLAUDE.md and rules; `<cwd>` and every parent directory up to the repository root for skills `"user"`| User CLAUDE.md, `~/.claude/rules/*.md`, user skills, user settings| `~/.claude/` -`"local"`| CLAUDE.local.md (gitignored), `.claude/settings.local.json`| `<cwd>/` - -Omitting `settingSources` is equivalent to `["user", "project", "local"]`. The `cwd` option determines where the SDK looks for project settings. If neither `cwd` nor any of its parent directories contains a `.claude/` folder, project-level features won’t load. +`"local"`| CLAUDE.local.md, `.claude/settings.local.json`| `<cwd>/.claude/` for `settings.local.json`; `<cwd>` and every parent directory for CLAUDE.local.md + +Omitting `settingSources` is equivalent to `["user", "project", "local"]`. The `cwd` option determines where the SDK looks for project-level inputs. CLAUDE.md and rules load from `<cwd>` and from every parent directory. Skills load from `<cwd>` and from every parent directory up to the repository root. Project `settings.json` and hooks load only from `<cwd>/.claude/` with no parent-directory fallback. ### @@ -80,10 +80,10 @@ Level| Location| When loaded ---|---|--- Project (root)| `<cwd>/CLAUDE.md` or `<cwd>/.claude/CLAUDE.md`| `settingSources` includes `"project"` -Project rules| `<cwd>/.claude/rules/*.md`| `settingSources` includes `"project"` +Project rules| `<cwd>/.claude/rules/*.md` and `.claude/rules/*.md` in every parent directory| `settingSources` includes `"project"` Project (parent dirs)| `CLAUDE.md` files in directories above `cwd`| `settingSources` includes `"project"`, loaded at session start Project (child dirs)| `CLAUDE.md` files in subdirectories of `cwd`| `settingSources` includes `"project"`, loaded on demand when the agent reads a file in that subtree -Local (gitignored)| `<cwd>/CLAUDE.local.md`| `settingSources` includes `"local"` +Local| `<cwd>/CLAUDE.local.md` and `CLAUDE.local.md` in every parent directory| `settingSources` includes `"local"` User| `~/.claude/CLAUDE.md`| `settingSources` includes `"user"` User rules| `~/.claude/rules/*.md`| `settingSources` includes `"user"`
modified
--- a/claude-code-features.md +++ b/claude-code-features.md @@ -99,7 +99,7 @@ Skills -Skills are markdown files that give your agent specialized knowledge and invocable workflows. Unlike `CLAUDE.md` (which loads every session), skills load on demand. The agent receives skill descriptions at startup and loads the full content when relevant. Skills are discovered from the filesystem through `settingSources`. With default options, user and project skills load automatically. The `Skill` tool is enabled by default when you don’t specify `allowedTools`. If you are using an `allowedTools` allowlist, include `"Skill"` explicitly. +Skills are markdown files that give your agent specialized knowledge and invocable workflows. Unlike `CLAUDE.md` (which loads every session), skills load on demand. The agent receives skill descriptions at startup and loads the full content when relevant. Skills are discovered from the filesystem through `settingSources`. When the `skills` option on `query()` is omitted, discovered user and project skills are enabled and the Skill tool is available, matching CLI behavior. To control which skills are enabled, pass `skills` as `"all"`, a list of skill names, or `[]` to disable all. The SDK enables the Skill tool automatically when `skills` is set, so you do not need to add it to `allowedTools`. Python @@ -113,7 +113,8 @@ prompt="Review this PR using our code review checklist", options=ClaudeAgentOptions( setting_sources=["user", "project"], - allowed_tools=["Skill", "Read", "Grep", "Glob"], + skills="all", + allowed_tools=["Read", "Grep", "Glob"], ), ): if isinstance(message, ResultMessage) and message.subtype == "success": @@ -194,8 +195,8 @@ You want to…| Use| SDK surface ---|---|--- Set project conventions your agent always follows| [CLAUDE.md](</docs/en/memory>)| `settingSources: ["project"]` loads it automatically -Give the agent reference material it loads when relevant| [Skills](</docs/en/agent-sdk/skills>)| `settingSources` \+ `allowedTools: ["Skill"]` -Run a reusable workflow (deploy, review, release)| [User-invocable skills](</docs/en/agent-sdk/skills>)| `settingSources` \+ `allowedTools: ["Skill"]` +Give the agent reference material it loads when relevant| [Skills](</docs/en/agent-sdk/skills>)| `settingSources` \+ `skills` option +Run a reusable workflow (deploy, review, release)| [User-invocable skills](</docs/en/agent-sdk/skills>)| `settingSources` \+ `skills` option Delegate an isolated subtask to a fresh context (research, review)| [Subagents](</docs/en/agent-sdk/subagents>)| `agents` parameter + `allowedTools: ["Agent"]` Coordinate multiple Claude Code instances with shared task lists and direct inter-agent messaging| [Agent teams](</docs/en/agent-teams>)| Not directly configured via SDK options. Agent teams are a CLI feature where one session acts as the team lead, coordinating work across independent teammates Run deterministic logic on tool calls (audit, block, transform)| [Hooks](</docs/en/agent-sdk/hooks>)| `hooks` parameter with callbacks, or shell scripts loaded via `settingSources`
modified
--- a/claude-code-features.md +++ b/claude-code-features.md @@ -12,7 +12,7 @@ Control filesystem settings with settingSources -The setting sources option ([`setting_sources`](</docs/en/agent-sdk/python#claude-agent-options>) in Python, [`settingSources`](</docs/en/agent-sdk/typescript#setting-source>) in TypeScript) controls which filesystem-based settings the SDK loads. Pass an explicit list to opt in to specific sources, or pass an empty array to disable user, project, and local settings. This example loads both user-level and project-level settings by setting `settingSources` to `["user", "project"]`: +The setting sources option ([`setting_sources`](</docs/en/agent-sdk/python#claudeagentoptions>) in Python, [`settingSources`](</docs/en/agent-sdk/typescript#settingsource>) in TypeScript) controls which filesystem-based settings the SDK loads. Pass an explicit list to opt in to specific sources, or pass an empty array to disable user, project, and local settings. This example loads both user-level and project-level settings by setting `settingSources` to `["user", "project"]`: Python @@ -37,7 +37,7 @@ if isinstance(message, ResultMessage) and message.subtype == "success": print(f"\nResult: {message.result}") -Each source loads settings from a specific location, where `<cwd>` is the working directory you pass via the `cwd` option (or the process’s current directory if unset). For the full type definition, see [`SettingSource`](</docs/en/agent-sdk/typescript#setting-source>) (TypeScript) or [`SettingSource`](</docs/en/agent-sdk/python#setting-source>) (Python). +Each source loads settings from a specific location, where `<cwd>` is the working directory you pass via the `cwd` option, or the process’s current directory if unset. For the full type definition, see [`SettingSource`](</docs/en/agent-sdk/typescript#settingsource>) (TypeScript) or [`SettingSource`](</docs/en/agent-sdk/python#settingsource>) (Python). Source| What it loads| Location ---|---|---
modified
--- a/claude-code-features.md +++ b/claude-code-features.md @@ -1,3 +1,9 @@ +> ## Documentation Index +> +> Fetch the complete documentation index at: <https://code.claude.com/docs/llms.txt> +> +> Use this file to discover all available pages before exploring further. + The Agent SDK is built on the same foundation as Claude Code, which means your SDK agents have access to the same filesystem-based features: project instructions (`CLAUDE.md` and rules), skills, hooks, and more. When you omit `settingSources`, `query()` reads the same filesystem settings as the Claude Code CLI: user, project, and local settings, CLAUDE.md files, and `.claude/` skills, agents, and commands. To run without these, pass `settingSources: []`, which limits the agent to what you configure programmatically. Managed policy settings and the global `~/.claude.json` config are read regardless of this option. See What settingSources does not control. For a conceptual overview of what each feature does and when to use it, see [Extend Claude Code](</docs/en/features-overview>). ##
modified
--- a/claude-code-features.md +++ b/claude-code-features.md @@ -170,7 +170,7 @@ Hook type| Best for ---|--- -**Filesystem** (`settings.json`)| Sharing hooks between CLI and SDK sessions. Supports `"command"` (shell scripts), `"http"` (POST to an endpoint), `"prompt"` (LLM evaluates a prompt), and `"agent"` (spawns a verifier agent). These fire in the main agent and any subagents it spawns. +**Filesystem** (`settings.json`)| Sharing hooks between CLI and SDK sessions. Supports `"command"` (shell scripts), `"http"` (POST to an endpoint), `"mcp_tool"` (call a connected MCP server’s tool), `"prompt"` (LLM evaluates a prompt), and `"agent"` (spawns a verifier agent). These fire in the main agent and any subagents it spawns. **Programmatic** (callbacks in `query()`)| Application-specific logic; returning structured decisions; in-process integration. Scoped to the main session only. The TypeScript SDK supports additional hook events beyond Python, including `SessionStart`, `SessionEnd`, `TeammateIdle`, and `TaskCompleted`. See the [hooks guide](</docs/en/agent-sdk/hooks>) for the full event compatibility table.
modified
--- a/claude-code-features.md +++ b/claude-code-features.md @@ -1,12 +1,12 @@ -The Agent SDK is built on the same foundation as Claude Code, which means your SDK agents have access to the same filesystem-based features: project instructions (`CLAUDE.md` and rules), skills, hooks, and more. By default, the SDK loads no filesystem settings. Your agent runs in isolation mode with only what you pass programmatically. To load CLAUDE.md, skills, or filesystem hooks, set `settingSources` to tell the SDK where to look. For a conceptual overview of what each feature does and when to use it, see [Extend Claude Code](</docs/en/features-overview>). - -## - -​ - -Enable Claude Code features with settingSources - -The setting sources option ([`setting_sources`](</docs/en/agent-sdk/python#claude-agent-options>) in Python, [`settingSources`](</docs/en/agent-sdk/typescript#setting-source>) in TypeScript) controls which filesystem-based settings the SDK loads. Without it, your agent won’t discover skills, `CLAUDE.md` files, or project-level hooks. This example loads both user-level and project-level settings by setting `settingSources` to `["user", "project"]`: +The Agent SDK is built on the same foundation as Claude Code, which means your SDK agents have access to the same filesystem-based features: project instructions (`CLAUDE.md` and rules), skills, hooks, and more. When you omit `settingSources`, `query()` reads the same filesystem settings as the Claude Code CLI: user, project, and local settings, CLAUDE.md files, and `.claude/` skills, agents, and commands. To run without these, pass `settingSources: []`, which limits the agent to what you configure programmatically. Managed policy settings and the global `~/.claude.json` config are read regardless of this option. See What settingSources does not control. For a conceptual overview of what each feature does and when to use it, see [Extend Claude Code](</docs/en/features-overview>). + +## + +​ + +Control filesystem settings with settingSources + +The setting sources option ([`setting_sources`](</docs/en/agent-sdk/python#claude-agent-options>) in Python, [`settingSources`](</docs/en/agent-sdk/typescript#setting-source>) in TypeScript) controls which filesystem-based settings the SDK loads. Pass an explicit list to opt in to specific sources, or pass an empty array to disable user, project, and local settings. This example loads both user-level and project-level settings by setting `settingSources` to `["user", "project"]`: Python @@ -39,9 +39,23 @@ `"user"`| User CLAUDE.md, `~/.claude/rules/*.md`, user skills, user settings| `~/.claude/` `"local"`| CLAUDE.local.md (gitignored), `.claude/settings.local.json`| `<cwd>/` -To match the full Claude Code CLI behavior, use `["user", "project", "local"]`. - -The `cwd` option determines where the SDK looks for project settings. If neither `cwd` nor any of its parent directories contains a `.claude/` folder, project-level features won’t load. Auto memory (the `~/.claude/projects/<project>/memory/` directory that Claude Code uses to persist notes across interactive sessions) is a CLI-only feature and is never loaded by the SDK. +Omitting `settingSources` is equivalent to `["user", "project", "local"]`. The `cwd` option determines where the SDK looks for project settings. If neither `cwd` nor any of its parent directories contains a `.claude/` folder, project-level features won’t load. + +### + +​ + +What settingSources does not control + +`settingSources` covers user, project, and local settings. A few inputs are read regardless of its value: + +Input| Behavior| To disable +---|---|--- +Managed policy settings| Always loaded when present on the host| Remove the managed settings file +`~/.claude.json` global config| Always read| Relocate with `CLAUDE_CONFIG_DIR` in `env` +Auto memory at `~/.claude/projects/<project>/memory/`| Loaded by default into the system prompt| Set `autoMemoryEnabled: false` in settings, or `CLAUDE_CODE_DISABLE_AUTO_MEMORY=1` in `env` + +Do not rely on default `query()` options for multi-tenant isolation. Because the inputs above are read regardless of `settingSources`, an SDK process can pick up host-level configuration and per-directory memory. For multi-tenant deployments, run each tenant in its own filesystem and set `settingSources: []` plus `CLAUDE_CODE_DISABLE_AUTO_MEMORY=1` in `env`. See [Secure deployment](</docs/en/agent-sdk/secure-deployment>). ## @@ -79,7 +93,7 @@ Skills -Skills are markdown files that give your agent specialized knowledge and invocable workflows. Unlike `CLAUDE.md` (which loads every session), skills load on demand. The agent receives skill descriptions at startup and loads the full content when relevant. To use skills in the SDK, set `settingSources` so the agent discovers skill files from the filesystem. The `Skill` tool is enabled by default when you don’t specify `allowedTools`. If you are using an `allowedTools` allowlist, include `"Skill"` explicitly. +Skills are markdown files that give your agent specialized knowledge and invocable workflows. Unlike `CLAUDE.md` (which loads every session), skills load on demand. The agent receives skill descriptions at startup and loads the full content when relevant. Skills are discovered from the filesystem through `settingSources`. With default options, user and project skills load automatically. The `Skill` tool is enabled by default when you don’t specify `allowedTools`. If you are using an `allowedTools` allowlist, include `"Skill"` explicitly. Python
added
Show diff (202 lines)
--- a/claude-code-features.md +++ b/claude-code-features.md @@ -0,0 +1,199 @@ +The Agent SDK is built on the same foundation as Claude Code, which means your SDK agents have access to the same filesystem-based features: project instructions (`CLAUDE.md` and rules), skills, hooks, and more. By default, the SDK loads no filesystem settings. Your agent runs in isolation mode with only what you pass programmatically. To load CLAUDE.md, skills, or filesystem hooks, set `settingSources` to tell the SDK where to look. For a conceptual overview of what each feature does and when to use it, see [Extend Claude Code](</docs/en/features-overview>). + +## + +​ + +Enable Claude Code features with settingSources + +The setting sources option ([`setting_sources`](</docs/en/agent-sdk/python#claude-agent-options>) in Python, [`settingSources`](</docs/en/agent-sdk/typescript#setting-source>) in TypeScript) controls which filesystem-based settings the SDK loads. Without it, your agent won’t discover skills, `CLAUDE.md` files, or project-level hooks. This example loads both user-level and project-level settings by setting `settingSources` to `["user", "project"]`: + +Python + +TypeScript + + from claude_agent_sdk import query, ClaudeAgentOptions, AssistantMessage, ResultMessage + + async for message in query( + prompt="Help me refactor the auth module", + options=ClaudeAgentOptions( + # "user" loads from ~/.claude/, "project" loads from ./.claude/ in cwd. + # Together they give the agent access to CLAUDE.md, skills, hooks, and + # permissions from both locations. + setting_sources=["user", "project"], + allowed_tools=["Read", "Edit", "Bash"], + ), + ): + if isinstance(message, AssistantMessage): + for block in message.content: + if hasattr(block, "text"): + print(block.text) + if isinstance(message, ResultMessage) and message.subtype == "success": + print(f"\nResult: {message.result}") + +Each source loads settings from a specific location, where `<cwd>` is the working directory you pass via the `cwd` option (or the process’s current directory if unset). For the full type definition, see [`SettingSource`](</docs/en/agent-sdk/typescript#setting-source>) (TypeScript) or [`SettingSource`](</docs/en/agent-sdk/python#setting-source>) (Python). + +Source| What it loads| Location +---|---|--- +`"project"`| Project CLAUDE.md, `.claude/rules/*.md`, project skills, project hooks, project `settings.json`| `<cwd>/.claude/` and each parent directory up to the filesystem root (stopping when a `.claude/` is found or no more parents exist) +`"user"`| User CLAUDE.md, `~/.claude/rules/*.md`, user skills, user settings| `~/.claude/` +`"local"`| CLAUDE.local.md (gitignored), `.claude/settings.local.json`| `<cwd>/` + +To match the full Claude Code CLI behavior, use `["user", "project", "local"]`. + +The `cwd` option determines where the SDK looks for project settings. If neither `cwd` nor any of its parent directories contains a `.claude/` folder, project-level features won’t load. Auto memory (the `~/.claude/projects/<project>/memory/` directory that Claude Code uses to persist notes across interactive sessions) is a CLI-only feature and is never loaded by the SDK. + +## + +​ + +Project instructions (CLAUDE.md and rules) + +`CLAUDE.md` files and `.claude/rules/*.md` files give your agent persistent context about your project: coding conventions, build commands, architecture decisions, and instructions. When `settingSources` includes `"project"` (as in the example above), the SDK loads these files into context at session start. The agent then follows your project conventions without you repeating them in every prompt. + +### + +​ + +CLAUDE.md load locations + +Level| Location| When loaded +---|---|--- +Project (root)| `<cwd>/CLAUDE.md` or `<cwd>/.claude/CLAUDE.md`| `settingSources` includes `"project"` +Project rules| `<cwd>/.claude/rules/*.md`| `settingSources` includes `"project"` +Project (parent dirs)| `CLAUDE.md` files in directories above `cwd`| `settingSources` includes `"project"`, loaded at session start +Project (child dirs)| `CLAUDE.md` files in subdirectories of `cwd`| `settingSources` includes `"project"`, loaded on demand when the agent reads a file in that subtree +Local (gitignored)| `<cwd>/CLAUDE.local.md`| `settingSources` includes `"local"` +User| `~/.claude/CLAUDE.md`| `settingSources` includes `"user"` +User rules| `~/.claude/rules/*.md`| `settingSources` includes `"user"` + +All levels are additive: if both project and user CLAUDE.md files exist, the agent sees both. There is no hard precedence rule between levels; if instructions conflict, the outcome depends on how Claude interprets them. Write non-conflicting rules, or state precedence explicitly in the more specific file (“These project instructions override any conflicting user-level defaults”). + +You can also inject context directly via `systemPrompt` without using CLAUDE.md files. See [Modify system prompts](</docs/en/agent-sdk/modifying-system-prompts>). Use CLAUDE.md when you want the same context shared between interactive Claude Code sessions and your SDK agents. + +For how to structure and organize CLAUDE.md content, see [Manage Claude’s memory](</docs/en/memory>). + +## + +​ + +Skills + +Skills are markdown files that give your agent specialized knowledge and invocable workflows. Unlike `CLAUDE.md` (which loads every session), skills load on demand. The agent receives skill descriptions at startup and loads the full content when relevant. To use skills in the SDK, set `settingSources` so the agent discovers skill files from the filesystem. The `Skill` tool is enabled by default when you don’t specify `allowedTools`. If you are using an `allowedTools` allowlist, include `"Skill"` explicitly. + +Python + +TypeScript + + from claude_agent_sdk import query, ClaudeAgentOptions, ResultMessage + + # Skills in .claude/skills/ are discovered automatically + # when settingSources includes "project" + async for message in query( + prompt="Review this PR using our code review checklist", + options=ClaudeAgentOptions( + setting_sources=["user", "project"], + allowed_tools=["Skill", "Read", "Grep", "Glob"], + ), + ): + if isinstance(message, ResultMessage) and message.subtype == "success": + print(message.result) + +Skills must be created as filesystem artifacts (`.claude/skills/<name>/SKILL.md`). The SDK does not have a programmatic API for registering skills. See [Agent Skills in the SDK](</docs/en/agent-sdk/skills>) for full details. + +For more on creating and using skills, see [Agent Skills in the SDK](</docs/en/agent-sdk/skills>). + +## + +​ + +Hooks + +The SDK supports two ways to define hooks, and they run side by side: + + * **Filesystem hooks:** shell commands defined in `settings.json`, loaded when `settingSources` includes the relevant source. These are the same hooks you’d configure for [interactive Claude Code sessions](</docs/en/hooks-guide>). + * **Programmatic hooks:** callback functions passed directly to `query()`. These run in your application process and can return structured decisions. See [Control execution with hooks](</docs/en/agent-sdk/hooks>). + +Both types execute during the same hook lifecycle. If you already have hooks in your project’s `.claude/settings.json` and you set `settingSources: ["project"]`, those hooks run automatically in the SDK with no extra configuration. Hook callbacks receive the tool input and return a decision dict. Returning `{}` (an empty dict) means allow the tool to proceed. Returning `{"decision": "block", "reason": "..."}` prevents execution and the reason is sent to Claude as the tool result. See the [hooks guide](</docs/en/agent-sdk/hooks>) for the full callback signature and return types. + +Python + +TypeScript + + from claude_agent_sdk import query, ClaudeAgentOptions, HookMatcher, ResultMessage + + # PreToolUse hook callback. Positional args: + # input_data: HookInput dict with tool_name, tool_input, hook_event_name + # tool_use_id: str | None, the ID of the tool call being intercepted + # context: HookContext, carries session metadata + async def audit_bash(input_data, tool_use_id, context): + command = input_data.get("tool_input", {}).get("command", "") + if "rm -rf" in command: + return {"decision": "block", "reason": "Destructive command blocked"} + return {} # Empty dict: allow the tool to proceed + + # Filesystem hooks from .claude/settings.json run automatically + # when settingSources loads them. You can also add programmatic hooks: + async for message in query( + prompt="Refactor the auth module", + options=ClaudeAgentOptions( + setting_sources=["project"], # Loads hooks from .claude/settings.json + hooks={ + "PreToolUse": [ + HookMatcher(matcher="Bash", hooks=[audit_bash]), + ] + }, + ), + ): + if isinstance(message, ResultMessage) and message.subtype == "success": + print(message.result) + +### + +​ + +When to use which hook type + +Hook type| Best for +---|--- +**Filesystem** (`settings.json`)| Sharing hooks between CLI and SDK sessions. Supports `"command"` (shell scripts), `"http"` (POST to an endpoint), `"prompt"` (LLM evaluates a prompt), and `"agent"` (spawns a verifier agent). These fire in the main agent and any subagents it spawns. +**Programmatic** (callbacks in `query()`)| Application-specific logic; returning structured decisions; in-process integration. Scoped to the main session only. + +The TypeScript SDK supports additional hook events beyond Python, including `SessionStart`, `SessionEnd`, `TeammateIdle`, and `TaskCompleted`. See the [hooks guide](</docs/en/agent-sdk/hooks>) for the full event compatibility table. + +For full details on programmatic hooks, see [Control execution with hooks](</docs/en/agent-sdk/hooks>). For filesystem hook syntax, see [Hooks](</docs/en/hooks>). + +## + +​ + +Choose the right feature + +The Agent SDK gives you access to several ways to extend your agent’s behavior. If you’re unsure which to use, this table maps common goals to the right approach. + +You want to…| Use| SDK surface +---|---|--- +Set project conventions your agent always follows| [CLAUDE.md](</docs/en/memory>)| `settingSources: ["project"]` loads it automatically +Give the agent reference material it loads when relevant| [Skills](</docs/en/agent-sdk/skills>)| `settingSources` \+ `allowedTools: ["Skill"]` +Run a reusable workflow (deploy, review, release)| [User-invocable skills](</docs/en/agent-sdk/skills>)| `settingSources` \+ `allowedTools: ["Skill"]` +Delegate an isolated subtask to a fresh context (research, review)| [Subagents](</docs/en/agent-sdk/subagents>)| `agents` parameter + `allowedTools: ["Agent"]` +Coordinate multiple Claude Code instances with shared task lists and direct inter-agent messaging| [Agent teams](</docs/en/agent-teams>)| Not directly configured via SDK options. Agent teams are a CLI feature where one session acts as the team lead, coordinating work across independent teammates +Run deterministic logic on tool calls (audit, block, transform)| [Hooks](</docs/en/agent-sdk/hooks>)| `hooks` parameter with callbacks, or shell scripts loaded via `settingSources` +Give Claude structured tool access to an external service| [MCP](</docs/en/agent-sdk/mcp>)| `mcpServers` parameter + +**Subagents versus agent teams:** Subagents are ephemeral and isolated: fresh conversation, one task, summary returned to parent. Agent teams coordinate multiple independent Claude Code instances that share a task list and message each other directly. Agent teams are a CLI feature. See [What subagents inherit](</docs/en/agent-sdk/subagents#what-subagents-inherit>) and the [agent teams comparison](</docs/en/agent-teams#compare-with-subagents>) for details. + +Every feature you enable adds to your agent’s context window. For per-feature costs and how these features layer together, see [Extend Claude Code](</docs/en/features-overview#understand-context-costs>). + +## + +​ + +Related resources + + * [Extend Claude Code](</docs/en/features-overview>): Conceptual overview of all extension features, with comparison tables and context cost analysis + * [Skills in the SDK](</docs/en/agent-sdk/skills>): Full guide to using skills programmatically + * [Subagents](</docs/en/agent-sdk/subagents>): Define and invoke subagents for isolated subtasks + * [Hooks](</docs/en/agent-sdk/hooks>): Intercept and control agent behavior at key execution points + * [Permissions](</docs/en/agent-sdk/permissions>): Control tool access with modes, rules, and callbacks + * [System prompts](</docs/en/agent-sdk/modifying-system-prompts>): Inject context without CLAUDE.md files