関数

query()

Claude Code とやり取りするための主要な関数です。メッセージが到着するとストリーミングする非同期ジェネレーターを作成します。
function query({
  prompt,
  options
}: {
  prompt: string | AsyncIterable<SDKUserMessage>;
  options?: Options;
}): Query

パラメーター

パラメーター説明
promptstring | AsyncIterable<SDKUserMessage>文字列またはストリーミングモード用の非同期イテラブルとしての入力プロンプト
optionsOptionsオプションの設定オブジェクト(以下の Options 型を参照)

戻り値

追加のメソッドを持つ AsyncGenerator<SDKMessage, void> を拡張した Query オブジェクトを返します。

tool()

SDK MCP サーバーで使用するための型安全な MCP ツール定義を作成します。
function tool<Schema extends ZodRawShape>(
  name: string,
  description: string,
  inputSchema: Schema,
  handler: (args: z.infer<ZodObject<Schema>>, extra: unknown) => Promise<CallToolResult>
): SdkMcpToolDefinition<Schema>

パラメーター

パラメーター説明
namestringツールの名前
descriptionstringツールが何をするかの説明
inputSchemaSchema extends ZodRawShapeツールの入力パラメーターを定義する Zod スキーマ
handler(args, extra) => Promise<CallToolResult>ツールロジックを実行する非同期関数

createSdkMcpServer()

アプリケーションと同じプロセスで実行される MCP サーバーインスタンスを作成します。
function createSdkMcpServer(options: {
  name: string;
  version?: string;
  tools?: Array<SdkMcpToolDefinition<any>>;
}): McpSdkServerConfigWithInstance

パラメーター

パラメーター説明
options.namestringMCP サーバーの名前
options.versionstringオプションのバージョン文字列
options.toolsArray<SdkMcpToolDefinition>tool() で作成されたツール定義の配列

Options

query() 関数の設定オブジェクト。
プロパティデフォルト説明
abortControllerAbortControllernew AbortController()操作をキャンセルするためのコントローラー
additionalDirectoriesstring[][]Claude がアクセスできる追加ディレクトリ
allowedToolsstring[]すべてのツール許可されたツール名のリスト
appendSystemPromptstringundefinedデフォルトのシステムプロンプトに追加するテキスト
canUseToolCanUseToolundefinedツール使用のためのカスタム権限関数
continuebooleanfalse最新の会話を続行する
customSystemPromptstringundefinedデフォルトのシステムプロンプトを完全に置き換える
cwdstringprocess.cwd()現在の作業ディレクトリ
disallowedToolsstring[][]許可されていないツール名のリスト
envDict<string>process.env環境変数
executable'bun' | 'deno' | 'node'自動検出使用する JavaScript ランタイム
executableArgsstring[][]実行可能ファイルに渡す引数
extraArgsRecord<string, string | null>{}追加の引数
fallbackModelstringundefinedプライマリが失敗した場合に使用するモデル
hooksPartial<Record<HookEvent, HookCallbackMatcher[]>>{}イベント用のフックコールバック
includePartialMessagesbooleanfalse部分メッセージイベントを含める
maxThinkingTokensnumberundefined思考プロセスの最大トークン数
maxTurnsnumberundefined最大会話ターン数
mcpServersRecord<string, McpServerConfig>{}MCP サーバー設定
modelstringCLI からのデフォルト使用する Claude モデル
pathToClaudeCodeExecutablestring自動検出Claude Code 実行可能ファイルへのパス
permissionModePermissionMode'default'セッションの権限モード
permissionPromptToolNamestringundefined権限プロンプト用の MCP ツール名
resumestringundefined再開するセッション ID
stderr(data: string) => voidundefinedstderr 出力のコールバック
strictMcpConfigbooleanfalse厳密な MCP 検証を強制する

Query

query() 関数によって返されるインターフェース。
interface Query extends AsyncGenerator<SDKMessage, void> {
  interrupt(): Promise<void>;
  setPermissionMode(mode: PermissionMode): Promise<void>;
}

メソッド

メソッド説明
interrupt()クエリを中断します(ストリーミング入力モードでのみ利用可能)
setPermissionMode()権限モードを変更します(ストリーミング入力モードでのみ利用可能)

PermissionMode

type PermissionMode = 
  | 'default'           // 標準の権限動作
  | 'acceptEdits'       // ファイル編集を自動承認
  | 'bypassPermissions' // すべての権限チェックをバイパス
  | 'plan'              // 計画モード - 実行なし

CanUseTool

ツール使用を制御するためのカスタム権限関数型。
type CanUseTool = (
  toolName: string,
  input: ToolInput,
  options: {
    signal: AbortSignal;
    suggestions?: PermissionUpdate[];
  }
) => Promise<PermissionResult>;

PermissionResult

権限チェックの結果。
type PermissionResult = 
  | {
      behavior: 'allow';
      updatedInput: ToolInput;
      updatedPermissions?: PermissionUpdate[];
    }
  | {
      behavior: 'deny';
      message: string;
      interrupt?: boolean;
    }

McpServerConfig

MCP サーバーの設定。
type McpServerConfig = 
  | McpStdioServerConfig
  | McpSSEServerConfig
  | McpHttpServerConfig
  | McpSdkServerConfigWithInstance;

McpStdioServerConfig

type McpStdioServerConfig = {
  type?: 'stdio';
  command: string;
  args?: string[];
  env?: Record<string, string>;
}

McpSSEServerConfig

type McpSSEServerConfig = {
  type: 'sse';
  url: string;
  headers?: Record<string, string>;
}

McpHttpServerConfig

type McpHttpServerConfig = {
  type: 'http';
  url: string;
  headers?: Record<string, string>;
}

McpSdkServerConfigWithInstance

type McpSdkServerConfigWithInstance = {
  type: 'sdk';
  name: string;
  instance: McpServer;
}

メッセージ型

SDKMessage

クエリによって返される可能性のあるすべてのメッセージのユニオン型。
type SDKMessage = 
  | SDKAssistantMessage
  | SDKUserMessage
  | SDKUserMessageReplay
  | SDKResultMessage
  | SDKSystemMessage
  | SDKPartialAssistantMessage
  | SDKCompactBoundaryMessage;

SDKAssistantMessage

アシスタント応答メッセージ。
type SDKAssistantMessage = {
  type: 'assistant';
  uuid: UUID;
  session_id: string;
  message: APIAssistantMessage; // Anthropic SDK から
  parent_tool_use_id: string | null;
}

SDKUserMessage

ユーザー入力メッセージ。
type SDKUserMessage = {
  type: 'user';
  uuid?: UUID;
  session_id: string;
  message: APIUserMessage; // Anthropic SDK から
  parent_tool_use_id: string | null;
}

SDKUserMessageReplay

必須の UUID を持つ再生されたユーザーメッセージ。
type SDKUserMessageReplay = {
  type: 'user';
  uuid: UUID;
  session_id: string;
  message: APIUserMessage;
  parent_tool_use_id: string | null;
}

SDKResultMessage

最終結果メッセージ。
type SDKResultMessage = 
  | {
      type: 'result';
      subtype: 'success';
      uuid: UUID;
      session_id: string;
      duration_ms: number;
      duration_api_ms: number;
      is_error: boolean;
      num_turns: number;
      result: string;
      total_cost_usd: number;
      usage: NonNullableUsage;
      permission_denials: SDKPermissionDenial[];
    }
  | {
      type: 'result';
      subtype: 'error_max_turns' | 'error_during_execution';
      uuid: UUID;
      session_id: string;
      duration_ms: number;
      duration_api_ms: number;
      is_error: boolean;
      num_turns: number;
      total_cost_usd: number;
      usage: NonNullableUsage;
      permission_denials: SDKPermissionDenial[];
    }

SDKSystemMessage

システム初期化メッセージ。
type SDKSystemMessage = {
  type: 'system';
  subtype: 'init';
  uuid: UUID;
  session_id: string;
  apiKeySource: ApiKeySource;
  cwd: string;
  tools: string[];
  mcp_servers: {
    name: string;
    status: string;
  }[];
  model: string;
  permissionMode: PermissionMode;
  slash_commands: string[];
  output_style: string;
}

SDKPartialAssistantMessage

ストリーミング部分メッセージ(includePartialMessages が true の場合のみ)。
type SDKPartialAssistantMessage = {
  type: 'stream_event';
  event: RawMessageStreamEvent; // Anthropic SDK から
  parent_tool_use_id: string | null;
  uuid: UUID;
  session_id: string;
}

SDKCompactBoundaryMessage

会話圧縮境界を示すメッセージ。
type SDKCompactBoundaryMessage = {
  type: 'system';
  subtype: 'compact_boundary';
  uuid: UUID;
  session_id: string;
  compact_metadata: {
    trigger: 'manual' | 'auto';
    pre_tokens: number;
  };
}

SDKPermissionDenial

拒否されたツール使用に関する情報。
type SDKPermissionDenial = {
  tool_name: string;
  tool_use_id: string;
  tool_input: ToolInput;
}

フック型

HookEvent

利用可能なフックイベント。
type HookEvent = 
  | 'PreToolUse'
  | 'PostToolUse'
  | 'Notification'
  | 'UserPromptSubmit'
  | 'SessionStart'
  | 'SessionEnd'
  | 'Stop'
  | 'SubagentStop'
  | 'PreCompact';

HookCallback

フックコールバック関数型。
type HookCallback = (
  input: HookInput, // すべてのフック入力型のユニオン
  toolUseID: string | undefined,
  options: { signal: AbortSignal }
) => Promise<HookJSONOutput>;

HookCallbackMatcher

オプションのマッチャーを持つフック設定。
interface HookCallbackMatcher {
  matcher?: string;
  hooks: HookCallback[];
}

HookInput

すべてのフック入力型のユニオン型。
type HookInput = 
  | PreToolUseHookInput
  | PostToolUseHookInput
  | NotificationHookInput
  | UserPromptSubmitHookInput
  | SessionStartHookInput
  | SessionEndHookInput
  | StopHookInput
  | SubagentStopHookInput
  | PreCompactHookInput;

BaseHookInput

すべてのフック入力型が拡張するベースインターフェース。
type BaseHookInput = {
  session_id: string;
  transcript_path: string;
  cwd: string;
  permission_mode?: string;
}

PreToolUseHookInput

type PreToolUseHookInput = BaseHookInput & {
  hook_event_name: 'PreToolUse';
  tool_name: string;
  tool_input: ToolInput;
}

PostToolUseHookInput

type PostToolUseHookInput = BaseHookInput & {
  hook_event_name: 'PostToolUse';
  tool_name: string;
  tool_input: ToolInput;
  tool_response: ToolOutput;
}

NotificationHookInput

type NotificationHookInput = BaseHookInput & {
  hook_event_name: 'Notification';
  message: string;
  title?: string;
}

UserPromptSubmitHookInput

type UserPromptSubmitHookInput = BaseHookInput & {
  hook_event_name: 'UserPromptSubmit';
  prompt: string;
}

SessionStartHookInput

type SessionStartHookInput = BaseHookInput & {
  hook_event_name: 'SessionStart';
  source: 'startup' | 'resume' | 'clear' | 'compact';
}

SessionEndHookInput

type SessionEndHookInput = BaseHookInput & {
  hook_event_name: 'SessionEnd';
  reason: 'clear' | 'logout' | 'prompt_input_exit' | 'other';
}

StopHookInput

type StopHookInput = BaseHookInput & {
  hook_event_name: 'Stop';
  stop_hook_active: boolean;
}

SubagentStopHookInput

type SubagentStopHookInput = BaseHookInput & {
  hook_event_name: 'SubagentStop';
  stop_hook_active: boolean;
}

PreCompactHookInput

type PreCompactHookInput = BaseHookInput & {
  hook_event_name: 'PreCompact';
  trigger: 'manual' | 'auto';
  custom_instructions: string | null;
}

HookJSONOutput

フックの戻り値。
type HookJSONOutput = AsyncHookJSONOutput | SyncHookJSONOutput;

AsyncHookJSONOutput

type AsyncHookJSONOutput = {
  async: true;
  asyncTimeout?: number;
}

SyncHookJSONOutput

type SyncHookJSONOutput = {
  continue?: boolean;
  suppressOutput?: boolean;
  stopReason?: string;
  decision?: 'approve' | 'block';
  systemMessage?: string;
  reason?: string;
  hookSpecificOutput?:
    | {
        hookEventName: 'PreToolUse';
        permissionDecision?: 'allow' | 'deny' | 'ask';
        permissionDecisionReason?: string;
      }
    | {
        hookEventName: 'UserPromptSubmit';
        additionalContext?: string;
      }
    | {
        hookEventName: 'SessionStart';
        additionalContext?: string;
      }
    | {
        hookEventName: 'PostToolUse';
        additionalContext?: string;
      };
}

ツール入力型

すべての組み込み Claude Code ツールの入力スキーマのドキュメント。これらの型は @anthropic/claude-code-sdk からエクスポートされ、型安全なツールインタラクションに使用できます。

ToolInput

注意: これは明確性のためのドキュメント専用型です。すべてのツール入力型のユニオンを表します。
type ToolInput = 
  | AgentInput
  | BashInput
  | BashOutputInput
  | FileEditInput
  | FileMultiEditInput
  | FileReadInput
  | FileWriteInput
  | GlobInput
  | GrepInput
  | KillShellInput
  | NotebookEditInput
  | WebFetchInput
  | WebSearchInput
  | TodoWriteInput
  | ExitPlanModeInput
  | ListMcpResourcesInput
  | ReadMcpResourceInput;

Task

ツール名: Task
interface AgentInput {
  /**
   * タスクの短い(3-5語)説明
   */
  description: string;
  /**
   * エージェントが実行するタスク
   */
  prompt: string;
  /**
   * このタスクに使用する専門エージェントの種類
   */
  subagent_type: string;
}
複雑な多段階タスクを自律的に処理する新しいエージェントを起動します。

Bash

ツール名: Bash
interface BashInput {
  /**
   * 実行するコマンド
   */
  command: string;
  /**
   * オプションのタイムアウト(ミリ秒、最大 600000)
   */
  timeout?: number;
  /**
   * このコマンドが何をするかの明確で簡潔な説明(5-10語)
   */
  description?: string;
  /**
   * このコマンドをバックグラウンドで実行する場合は true に設定
   */
  run_in_background?: boolean;
}
オプションのタイムアウトとバックグラウンド実行を持つ永続的なシェルセッションで bash コマンドを実行します。

BashOutput

ツール名: BashOutput
interface BashOutputInput {
  /**
   * 出力を取得するバックグラウンドシェルの ID
   */
  bash_id: string;
  /**
   * 出力行をフィルタリングするオプションの正規表現
   */
  filter?: string;
}
実行中または完了したバックグラウンド bash シェルから出力を取得します。

Edit

ツール名: Edit
interface FileEditInput {
  /**
   * 変更するファイルの絶対パス
   */
  file_path: string;
  /**
   * 置換する文字列
   */
  old_string: string;
  /**
   * 置換後の文字列(old_string と異なる必要があります)
   */
  new_string: string;
  /**
   * old_string のすべての出現を置換する(デフォルト false)
   */
  replace_all?: boolean;
}
ファイル内で正確な文字列置換を実行します。

MultiEdit

ツール名: MultiEdit
interface FileMultiEditInput {
  /**
   * 変更するファイルの絶対パス
   */
  file_path: string;
  /**
   * 順次実行する編集操作の配列
   */
  edits: Array<{
    /**
     * 置換する文字列
     */
    old_string: string;
    /**
     * 置換後の文字列
     */
    new_string: string;
    /**
     * すべての出現を置換する(デフォルト false)
     */
    replace_all?: boolean;
  }>;
}
単一のファイルに対して一度の操作で複数の編集を行います。

Read

ツール名: Read
interface FileReadInput {
  /**
   * 読み取るファイルの絶対パス
   */
  file_path: string;
  /**
   * 読み取りを開始する行番号
   */
  offset?: number;
  /**
   * 読み取る行数
   */
  limit?: number;
}
テキスト、画像、PDF、Jupyter ノートブックを含むローカルファイルシステムからファイルを読み取ります。

Write

ツール名: Write
interface FileWriteInput {
  /**
   * 書き込むファイルの絶対パス
   */
  file_path: string;
  /**
   * ファイルに書き込むコンテンツ
   */
  content: string;
}
ローカルファイルシステムにファイルを書き込み、存在する場合は上書きします。

Glob

ツール名: Glob
interface GlobInput {
  /**
   * ファイルにマッチさせる glob パターン
   */
  pattern: string;
  /**
   * 検索するディレクトリ(デフォルトは cwd)
   */
  path?: string;
}
任意のコードベースサイズで動作する高速ファイルパターンマッチング。

Grep

ツール名: Grep
interface GrepInput {
  /**
   * 検索する正規表現パターン
   */
  pattern: string;
  /**
   * 検索するファイルまたはディレクトリ(デフォルトは cwd)
   */
  path?: string;
  /**
   * ファイルをフィルタリングする glob パターン(例:"*.js")
   */
  glob?: string;
  /**
   * 検索するファイルタイプ(例:"js"、"py"、"rust")
   */
  type?: string;
  /**
   * 出力モード:"content"、"files_with_matches"、または "count"
   */
  output_mode?: 'content' | 'files_with_matches' | 'count';
  /**
   * 大文字小文字を区別しない検索
   */
  '-i'?: boolean;
  /**
   * 行番号を表示(content モード用)
   */
  '-n'?: boolean;
  /**
   * 各マッチの前に表示する行数
   */
  '-B'?: number;
  /**
   * 各マッチの後に表示する行数
   */
  '-A'?: number;
  /**
   * 各マッチの前後に表示する行数
   */
  '-C'?: number;
  /**
   * 出力を最初の N 行/エントリに制限
   */
  head_limit?: number;
  /**
   * マルチラインモードを有効にする
   */
  multiline?: boolean;
}
正規表現サポートを持つ ripgrep 上に構築された強力な検索ツール。

KillBash

ツール名: KillBash
interface KillShellInput {
  /**
   * 終了するバックグラウンドシェルの ID
   */
  shell_id: string;
}
ID によって実行中のバックグラウンド bash シェルを終了します。

NotebookEdit

ツール名: NotebookEdit
interface NotebookEditInput {
  /**
   * Jupyter ノートブックファイルの絶対パス
   */
  notebook_path: string;
  /**
   * 編集するセルの ID
   */
  cell_id?: string;
  /**
   * セルの新しいソース
   */
  new_source: string;
  /**
   * セルのタイプ(code または markdown)
   */
  cell_type?: 'code' | 'markdown';
  /**
   * 編集のタイプ(replace、insert、delete)
   */
  edit_mode?: 'replace' | 'insert' | 'delete';
}
Jupyter ノートブックファイル内のセルを編集します。

WebFetch

ツール名: WebFetch
interface WebFetchInput {
  /**
   * コンテンツを取得する URL
   */
  url: string;
  /**
   * 取得したコンテンツに対して実行するプロンプト
   */
  prompt: string;
}
URL からコンテンツを取得し、AI モデルで処理します。

WebSearch

ツール名: WebSearch
interface WebSearchInput {
  /**
   * 使用する検索クエリ
   */
  query: string;
  /**
   * これらのドメインからの結果のみを含める
   */
  allowed_domains?: string[];
  /**
   * これらのドメインからの結果を含めない
   */
  blocked_domains?: string[];
}
ウェブを検索し、フォーマットされた結果を返します。

TodoWrite

ツール名: TodoWrite
interface TodoWriteInput {
  /**
   * 更新された todo リスト
   */
  todos: Array<{
    /**
     * タスクの説明
     */
    content: string;
    /**
     * タスクのステータス
     */
    status: 'pending' | 'in_progress' | 'completed';
    /**
     * タスク説明のアクティブ形式
     */
    activeForm: string;
  }>;
}
進捗を追跡するための構造化されたタスクリストを作成・管理します。

ExitPlanMode

ツール名: ExitPlanMode
interface ExitPlanModeInput {
  /**
   * ユーザーの承認のために実行する計画
   */
  plan: string;
}
計画モードを終了し、ユーザーに計画の承認を求めます。

ListMcpResources

ツール名: ListMcpResources
interface ListMcpResourcesInput {
  /**
   * リソースをフィルタリングするオプションのサーバー名
   */
  server?: string;
}
接続されたサーバーから利用可能な MCP リソースをリストします。

ReadMcpResource

ツール名: ReadMcpResource
interface ReadMcpResourceInput {
  /**
   * MCP サーバー名
   */
  server: string;
  /**
   * 読み取るリソース URI
   */
  uri: string;
}
サーバーから特定の MCP リソースを読み取ります。

ツール出力型

すべての組み込み Claude Code ツールの出力スキーマのドキュメント。これらの型は各ツールによって返される実際の応答データを表します。

ToolOutput

注意: これは明確性のためのドキュメント専用型です。すべてのツール出力型のユニオンを表します。
type ToolOutput = 
  | TaskOutput
  | BashOutput
  | BashOutputToolOutput
  | EditOutput
  | MultiEditOutput
  | ReadOutput
  | WriteOutput
  | GlobOutput
  | GrepOutput
  | KillBashOutput
  | NotebookEditOutput
  | WebFetchOutput
  | WebSearchOutput
  | TodoWriteOutput
  | ExitPlanModeOutput
  | ListMcpResourcesOutput
  | ReadMcpResourceOutput;

Task

ツール名: Task
interface TaskOutput {
  /**
   * サブエージェントからの最終結果メッセージ
   */
  result: string;
  /**
   * トークン使用統計
   */
  usage?: {
    input_tokens: number;
    output_tokens: number;
    cache_creation_input_tokens?: number;
    cache_read_input_tokens?: number;
  };
  /**
   * 総コスト(USD)
   */
  total_cost_usd?: number;
  /**
   * 実行時間(ミリ秒)
   */
  duration_ms?: number;
}
委任されたタスクを完了した後のサブエージェントからの最終結果を返します。

Bash

ツール名: Bash
interface BashOutput {
  /**
   * stdout と stderr の結合出力
   */
  output: string;
  /**
   * コマンドの終了コード
   */
  exitCode: number;
  /**
   * コマンドがタイムアウトにより終了されたかどうか
   */
  killed?: boolean;
  /**
   * バックグラウンドプロセス用のシェル ID
   */
  shellId?: string;
}
終了ステータス付きのコマンド出力を返します。バックグラウンドコマンドは shellId と共に即座に返されます。

BashOutput

ツール名: BashOutput
interface BashOutputToolOutput {
  /**
   * 最後のチェック以降の新しい出力
   */
  output: string;
  /**
   * 現在のシェルステータス
   */
  status: 'running' | 'completed' | 'failed';
  /**
   * 終了コード(完了時)
   */
  exitCode?: number;
}
バックグラウンドシェルからの増分出力を返します。

Edit

ツール名: Edit
interface EditOutput {
  /**
   * 確認メッセージ
   */
  message: string;
  /**
   * 実行された置換の数
   */
  replacements: number;
  /**
   * 編集されたファイルパス
   */
  file_path: string;
}
置換数と共に成功した編集の確認を返します。

MultiEdit

ツール名: MultiEdit
interface MultiEditOutput {
  /**
   * 成功メッセージ
   */
  message: string;
  /**
   * 適用された編集の総数
   */
  edits_applied: number;
  /**
   * 編集されたファイルパス
   */
  file_path: string;
}
すべての編集を順次適用した後の確認を返します。

Read

ツール名: Read
type ReadOutput = 
  | TextFileOutput
  | ImageFileOutput
  | PDFFileOutput
  | NotebookFileOutput;

interface TextFileOutput {
  /**
   * 行番号付きのファイル内容
   */
  content: string;
  /**
   * ファイル内の総行数
   */
  total_lines: number;
  /**
   * 実際に返された行数
   */
  lines_returned: number;
}

interface ImageFileOutput {
  /**
   * Base64 エンコードされた画像データ
   */
  image: string;
  /**
   * 画像の MIME タイプ
   */
  mime_type: string;
  /**
   * ファイルサイズ(バイト)
   */
  file_size: number;
}

interface PDFFileOutput {
  /**
   * ページ内容の配列
   */
  pages: Array<{
    page_number: number;
    text?: string;
    images?: Array<{
      image: string;
      mime_type: string;
    }>;
  }>;
  /**
   * 総ページ数
   */
  total_pages: number;
}

interface NotebookFileOutput {
  /**
   * Jupyter ノートブックセル
   */
  cells: Array<{
    cell_type: 'code' | 'markdown';
    source: string;
    outputs?: any[];
    execution_count?: number;
  }>;
  /**
   * ノートブックメタデータ
   */
  metadata?: Record<string, any>;
}
ファイルタイプに適した形式でファイル内容を返します。

Write

ツール名: Write
interface WriteOutput {
  /**
   * 成功メッセージ
   */
  message: string;
  /**
   * 書き込まれたバイト数
   */
  bytes_written: number;
  /**
   * 書き込まれたファイルパス
   */
  file_path: string;
}
ファイルの書き込み成功後の確認を返します。

Glob

ツール名: Glob
interface GlobOutput {
  /**
   * マッチするファイルパスの配列
   */
  matches: string[];
  /**
   * 見つかったマッチの数
   */
  count: number;
  /**
   * 使用された検索ディレクトリ
   */
  search_path: string;
}
glob パターンにマッチするファイルパスを変更時刻順にソートして返します。

Grep

ツール名: Grep
type GrepOutput = 
  | GrepContentOutput
  | GrepFilesOutput
  | GrepCountOutput;

interface GrepContentOutput {
  /**
   * コンテキスト付きのマッチする行
   */
  matches: Array<{
    file: string;
    line_number?: number;
    line: string;
    before_context?: string[];
    after_context?: string[];
  }>;
  /**
   * 総マッチ数
   */
  total_matches: number;
}

interface GrepFilesOutput {
  /**
   * マッチを含むファイル
   */
  files: string[];
  /**
   * マッチを含むファイル数
   */
  count: number;
}

interface GrepCountOutput {
  /**
   * ファイルごとのマッチ数
   */
  counts: Array<{
    file: string;
    count: number;
  }>;
  /**
   * すべてのファイルでの総マッチ数
   */
  total: number;
}
output_mode で指定された形式で検索結果を返します。

KillBash

ツール名: KillBash
interface KillBashOutput {
  /**
   * 成功メッセージ
   */
  message: string;
  /**
   * 終了されたシェルの ID
   */
  shell_id: string;
}
バックグラウンドシェルの終了後の確認を返します。

NotebookEdit

ツール名: NotebookEdit
interface NotebookEditOutput {
  /**
   * 成功メッセージ
   */
  message: string;
  /**
   * 実行された編集のタイプ
   */
  edit_type: 'replaced' | 'inserted' | 'deleted';
  /**
   * 影響を受けたセル ID
   */
  cell_id?: string;
  /**
   * 編集後のノートブック内の総セル数
   */
  total_cells: number;
}
Jupyter ノートブックの変更後の確認を返します。

WebFetch

ツール名: WebFetch
interface WebFetchOutput {
  /**
   * プロンプトに対する AI モデルの応答
   */
  response: string;
  /**
   * 取得された URL
   */
  url: string;
  /**
   * リダイレクト後の最終 URL
   */
  final_url?: string;
  /**
   * HTTP ステータスコード
   */
  status_code?: number;
}
取得されたウェブコンテンツの AI による分析を返します。

WebSearch

ツール名: WebSearch
interface WebSearchOutput {
  /**
   * 検索結果
   */
  results: Array<{
    title: string;
    url: string;
    snippet: string;
    /**
     * 利用可能な場合の追加メタデータ
     */
    metadata?: Record<string, any>;
  }>;
  /**
   * 結果の総数
   */
  total_results: number;
  /**
   * 検索されたクエリ
   */
  query: string;
}
ウェブからのフォーマットされた検索結果を返します。

TodoWrite

ツール名: TodoWrite
interface TodoWriteOutput {
  /**
   * 成功メッセージ
   */
  message: string;
  /**
   * 現在の todo 統計
   */
  stats: {
    total: number;
    pending: number;
    in_progress: number;
    completed: number;
  };
}
現在のタスク統計と共に確認を返します。

ExitPlanMode

ツール名: ExitPlanMode
interface ExitPlanModeOutput {
  /**
   * 確認メッセージ
   */
  message: string;
  /**
   * ユーザーが計画を承認したかどうか
   */
  approved?: boolean;
}
計画モード終了後の確認を返します。

ListMcpResources

ツール名: ListMcpResources
interface ListMcpResourcesOutput {
  /**
   * 利用可能なリソース
   */
  resources: Array<{
    uri: string;
    name: string;
    description?: string;
    mimeType?: string;
    server: string;
  }>;
  /**
   * リソースの総数
   */
  total: number;
}
利用可能な MCP リソースのリストを返します。

ReadMcpResource

ツール名: ReadMcpResource
interface ReadMcpResourceOutput {
  /**
   * リソースの内容
   */
  contents: Array<{
    uri: string;
    mimeType?: string;
    text?: string;
    blob?: string;
  }>;
  /**
   * リソースを提供したサーバー
   */
  server: string;
}
要求された MCP リソースの内容を返します。

権限型

PermissionUpdate

権限を更新するための操作。
type PermissionUpdate = 
  | {
      type: 'addRules';
      rules: PermissionRuleValue[];
      behavior: PermissionBehavior;
      destination: PermissionUpdateDestination;
    }
  | {
      type: 'replaceRules';
      rules: PermissionRuleValue[];
      behavior: PermissionBehavior;
      destination: PermissionUpdateDestination;
    }
  | {
      type: 'removeRules';
      rules: PermissionRuleValue[];
      behavior: PermissionBehavior;
      destination: PermissionUpdateDestination;
    }
  | {
      type: 'setMode';
      mode: PermissionMode;
      destination: PermissionUpdateDestination;
    }
  | {
      type: 'addDirectories';
      directories: string[];
      destination: PermissionUpdateDestination;
    }
  | {
      type: 'removeDirectories';
      directories: string[];
      destination: PermissionUpdateDestination;
    }

PermissionBehavior

type PermissionBehavior = 'allow' | 'deny' | 'ask';

PermissionUpdateDestination

type PermissionUpdateDestination = 
  | 'userSettings'     // グローバルユーザー設定
  | 'projectSettings'  // ディレクトリごとのプロジェクト設定
  | 'localSettings'    // gitignore されたローカル設定
  | 'session'          // 現在のセッションのみ

PermissionRuleValue

type PermissionRuleValue = {
  toolName: string;
  ruleContent?: string;
}

その他の型

ApiKeySource

type ApiKeySource = 'user' | 'project' | 'org' | 'temporary';

ConfigScope

type ConfigScope = 'local' | 'user' | 'project';

NonNullableUsage

すべての nullable フィールドを non-nullable にした Usage のバージョン。
type NonNullableUsage = {
  [K in keyof Usage]: NonNullable<Usage[K]>;
}

Usage

トークン使用統計(@anthropic-ai/sdk から)。
type Usage = {
  input_tokens: number | null;
  output_tokens: number | null;
  cache_creation_input_tokens?: number | null;
  cache_read_input_tokens?: number | null;
}

CallToolResult

MCP ツール結果型(@modelcontextprotocol/sdk/types.js から)。
type CallToolResult = {
  content: Array<{
    type: 'text' | 'image' | 'resource';
    // 追加フィールドは型によって異なります
  }>;
  isError?: boolean;
}

AbortError

中止操作用のカスタムエラークラス。
class AbortError extends Error {}

関連項目