claude
Runs a Claude Code session synchronously from an MCP client, with session resume, git worktree isolation, model and tool controls, and optional structured JSON output.
Instructions
Run a Claude Code (claude -p) session synchronously (or as a native MCP Task when the client advertises io.modelcontextprotocol/tasks). This server applies NO timeout of its own, but legacy MCP clients typically cut a tool call around 300s -- use claude_async + claude_wait for long runs or parallel fan-out on non-Tasks clients.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"prompt": "<prompt>"
},
"name": "claude"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cwd | No | Working directory for the Claude Code session. If relative, resolved against the server's cwd. On resume, defaults to the original session's cwd/worktree when omitted. | |
| bare | No | Minimal headless mode skipping hooks, plugins, CLAUDE.md discovery, and OAuth/keychain reads (passes --bare; requires API key or provider credentials). | |
| agent | No | Named agent for this session (passes --agent). | |
| model | No | Optional model alias or full model name (e.g. 'opus', 'sonnet', 'haiku', 'fable', or a full model identifier). Call claude_models to list available models, resolved IDs, and supported effort levels. | |
| tools | No | Built-in tools to expose: "" or [] for none, "default" for the default set, or comma-separated/array tool names (e.g. ["Read","Edit","Bash"]). | |
| agents | No | Custom agents definition (JSON object or file path; passes --agents). | |
| effort | No | Reasoning effort level for this session. | |
| prompt | Yes | The user prompt for the Claude Code session. | |
| add_dir | No | Additional directories Claude can access (passes repeatable --add-dir). | |
| settings | No | Extra settings to load (JSON object or file path; passes --settings). Prefer file paths over inline credentials. | |
| worktree | No | Create an isolated git worktree and branch (claude-swarm/<task_id>) based on HEAD so parallel tasks never conflict. Note: branches from HEAD and excludes uncommitted or untracked working-tree changes -- commit them first if the task needs them. Merge the branch back before expiry. | |
| max_turns | No | Maximum number of agentic turns for this invocation (passes --max-turns). | |
| mcp_config | No | MCP server configurations to load (array of JSON objects or file paths/JSON strings; passes repeatable --mcp-config). | |
| session_id | No | Optional session ID (or session name) from a previous Claude call. When set, resumes that conversation via --resume instead of starting fresh. | |
| json_schema | No | Optional JSON Schema (object or string) passed to --json-schema so Claude Code returns structuredContent.structured_output via its StructuredOutput tool. Callers should verify structured_output is present, as Claude CLI can still exit 0 without it on short-circuited CLI commands or prose fallbacks. | |
| fork_session | No | When resuming via session_id, create a new session ID instead of mutating the original session (passes --fork-session). | |
| allowed_tools | No | Tool allow rules (e.g. ["Bash(git *)", "Edit"]; passes --allowed-tools). | |
| system_prompt | No | Replace the default system prompt (passes --system-prompt). | |
| fallback_model | No | Optional fallback model(s) (comma-separated) when the primary model is busy or unavailable (passes --fallback-model). | |
| max_budget_usd | No | Maximum API spend in USD for this invocation (passes --max-budget-usd). | |
| permission_mode | No | Permission mode for tool approval (acceptEdits, auto, bypassPermissions, manual, dontAsk, plan). | |
| setting_sources | No | Comma-separated setting sources to load (e.g. "user,project,local", or "" to exclude all user/project/local settings). | |
| disallowed_tools | No | Tool deny rules (e.g. ["Bash(rm *)"]; passes --disallowed-tools). | |
| strict_mcp_config | No | Only use MCP servers from mcp_config, ignoring all other MCP configs (passes --strict-mcp-config). Explicit false overrides server default. | |
| append_system_prompt | No | Append text to the default system prompt (passes --append-system-prompt). | |
| disable_slash_commands | No | Disable all skills and slash commands (passes --disable-slash-commands). Explicit false overrides server default. | |
| no_session_persistence | No | Do not save the session transcript to disk; cannot be resumed later (passes --no-session-persistence). Explicit false overrides server default. | |
| dangerously_skip_permissions | No | Bypass all permission checks (passes --dangerously-skip-permissions). Explicit false overrides server default. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| text | Yes | ||
| model | No | ||
| usage | No | ||
| effort | No | ||
| status | Yes | ||
| failure | No | ||
| exit_code | No | ||
| num_turns | No | ||
| session_id | No | ||
| stop_reason | No | ||
| tool_errors | No | ||
| worktree_path | No | ||
| partial_output | No | ||
| result_subtype | No | ||
| permission_mode | No | ||
| terminal_reason | No | ||
| worktree_branch | No | ||
| duration_seconds | No | ||
| structured_output | No | ||
| permission_denials | No |