claudecode-mcp
The claudecode-mcp server wraps the headless Claude Code CLI as MCP tools, enabling stateless, one-shot prompts against Claude models from any MCP-compatible client. It spawns a new Claude Code process per call with no session persistence.
Three core tools:
claude_prompt– Send a simple text prompt and receive a text response, with optional model selection and system prompt.claude_prompt_with_context– Same as above, but enriched with free-form context text and/or local file contents (prepended as labeled blocks), with safety checks to prevent path traversal.claude_prompt_structured– Send a prompt and receive a validated JSON response by providing a JSON Schema; the server instructs the model to conform to the schema and validates output before returning it (requiresclaudeCLI v2.1.0+).
Notable operational details:
Inherits authentication from the underlying
claudeCLI (OAuth, keychain, orANTHROPIC_API_KEY).Per-call timeouts (default 10 min) and output size caps (default 50 MB) prevent runaway processes.
Child processes use an explicit environment variable allowlist for security.
Debug logging available via
DEBUG=claudecode-mcp.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@claudecode-mcpclaude_prompt_structured write a Python function to calculate factorial with schema validation"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
claudecode-mcp
Local stdio MCP server that wraps the headless Claude Code CLI as MCP tools. Stateless, spawn-per-call.
Tools
claude_prompt { prompt, model?, system_prompt? }claude_prompt_with_context { prompt, context?, files?, model?, system_prompt? }claude_prompt_structured { prompt, schema, model?, system_prompt? }— usesclaude --json-schema; fails loudly if the installed CLI lacks that flag.
Install from npm
npm install -g claudecode-mcpOr install locally and reference the binary from node_modules/.bin/. The
package exposes a claudecode-mcp executable that runs the stdio server.
You also need the claude CLI
on your PATH, authenticated however you normally use it (OAuth, keychain,
or ANTHROPIC_API_KEY). This server inherits that auth — it does not manage
credentials of its own.
Recommended claude CLI version: 2.1.0 or later. claude_prompt_structured
needs the --json-schema flag, and --no-session-persistence had a brief
regression in v2.0.57 (see anthropics/claude-code#20398)
that's resolved in current 2.1.x builds.
Build from source
npm install
npm run build
node dist/server.jsRegister
Claude Code (~/.claude/mcp.json):
{
"mcpServers": {
"claudecode": {
"command": "claudecode-mcp"
}
}
}If you installed locally instead of globally, point command at node and
args at the absolute path to dist/server.js:
{
"mcpServers": {
"claudecode": {
"command": "node",
"args": ["/absolute/path/to/claudecode-mcp/dist/server.js"]
}
}
}Examples
The examples/ directory ships with the npm tarball. Each *.json is a
single JSON-RPC tools/call request for one of the three tools. See
examples/README.md for a one-liner to drive them
against node dist/server.js.
skill.sh
skill.sh is a minimal shell wrapper for direct CLI invocation outside MCP.
Usage: ./skill.sh "<prompt>" [working_dir]. It runs claude --print with
the same flags the MCP server uses. Not installed with the npm package.
Debug logging
Set DEBUG=claudecode-mcp to get one structured JSON line per spawn / call
on stderr. No prompt bodies are logged — only tool names, byte counts, exit
codes, and durations.
DEBUG=claudecode-mcp claudecode-mcpTest live
npm run test:liveRuns tiny real prompts against claude. Skipped unless CLAUDECODE_MCP_LIVE=1.
Troubleshooting
claude: command not found (or spawn claude ENOENT).
The MCP server invokes claude from your shell PATH. If your claude CLI
lives outside PATH (or you're launching the MCP under a process that has a
different PATH, e.g. some IDEs), set CLAUDECODE_MCP_CLAUDE_BIN to the
absolute path of the binary:
export CLAUDECODE_MCP_CLAUDE_BIN=/usr/local/bin/claudeVerify the binary works on its own first:
"$CLAUDECODE_MCP_CLAUDE_BIN" --versionAuth not configured / Please run claude login.
This server runs claude as a child process and inherits its auth. If
claude --print "hi" fails on your shell, the MCP will fail too. Fix the CLI
first:
For OAuth/keychain auth: run
claude loginonce interactively.For API-key auth:
export ANTHROPIC_API_KEY=sk-ant-...in the environment that launches the MCP server (your shell, your IDE, your launchd plist, etc.).
--bare is intentionally not used — it would disable OAuth/keychain and
force ANTHROPIC_API_KEY. That's a deliberate design decision, not a bug.
claude_prompt_structured errors with "does not support the --json-schema flag".
Your installed claude CLI predates --json-schema. Upgrade Claude Code
(npm i -g @anthropic-ai/claude-code or whatever your install method is) or
fall back to claude_prompt.
Design notes
No session tracking. No
session_idin tool inputs.--no-session-persistencealways.No
working_dirparameter. Usesprocess.cwd()of the MCP server process.Argv array spawning — never shell-interpolated.
--bareis opt-in viaCLAUDECODE_MCP_BARE=1. Default keeps OAuth/keychain auth working, but pins--strict-mcp-config --mcp-config '{"mcpServers":{}}'so the wrapped subprocess does NOT load the user's own MCP servers (avoids the recursion footgun where this server is itself in~/.claude/mcp.json). In bare mode, OAuth/keychain are unavailable; you must setANTHROPIC_API_KEYor passapiKeyHelpervia--settings. See https://code.claude.com/docs/en/headless#start-faster-with-bare-mode.
Subprocess timeout and output cap
Default 10-minute per-call timeout. Override with
CLAUDECODE_MCP_TIMEOUT_MS=<ms>. On timeout the subprocess is sentSIGTERMand thenSIGKILLafter a 2s grace, and the tool call rejects with anInvokeTimeoutError.Default 50 MB cap on combined stdout/stderr from a single call. Override with
CLAUDECODE_MCP_MAX_OUTPUT_BYTES=<bytes>. On overflow the subprocess is killed and the call rejects withOutputTooLargeError. There is no silent truncation — truncated JSON would parse to wrong data.
File context safety (claude_prompt_with_context)
File paths must be relative to the server process's working directory. Absolute paths,
..escapes, and symlinks pointing outside cwd are rejected.Per-file size cap, default 5 MB. Override with
CLAUDECODE_MCP_MAX_FILE_BYTES=<bytes>.File contents and paths are inserted into the prompt inside
----- file: NAME -----fenced blocks (not pseudo-XML), so quotes or angle brackets in paths cannot break the block boundaries.
Subprocess environment
The child inherits an explicit allowlist of environment variables, not the full parent env. Pass-through includes:
Shell/locale:
PATH,HOME,USER,LOGNAME,SHELL,TERM,TZ,TMPDIR,LANG,LC_*,XDG_*.Anthropic auth:
ANTHROPIC_API_KEY,ANTHROPIC_AUTH_TOKEN,CLAUDE_CODE_OAUTH_TOKEN,CLAUDE_CODE_OAUTH_REFRESH_TOKEN,CLAUDE_CODE_OAUTH_SCOPES.Cloud provider auth:
AWS_BEARER_TOKEN_BEDROCK,ANTHROPIC_AWS_*,ANTHROPIC_FOUNDRY_API_KEY,ANTHROPIC_VERTEX_PROJECT_ID.Routing:
ANTHROPIC_BASE_URL,ANTHROPIC_*_BASE_URL.Model selection:
ANTHROPIC_MODEL,ANTHROPIC_DEFAULT_*_MODEL,ANTHROPIC_BETAS.TLS:
CLAUDE_CODE_CERT_STORE,CLAUDE_CODE_CLIENT_CERT,CLAUDE_CODE_CLIENT_KEY,CLAUDE_CODE_CLIENT_KEY_PASSPHRASE.Locations:
CLAUDE_CONFIG_DIR,CLAUDE_CODE_DEBUG_LOGS_DIR.Anything in
CLAUDECODE_MCP_EXTRA_ENV(comma-separated key names).
Always force-set: NO_COLOR=1, TERM=dumb. Always stripped (unless
CLAUDECODE_MCP_FORWARD_DANGEROUS=1): CLAUDE_CODE_SHELL_PREFIX,
CLAUDE_CODE_EXTRA_BODY, ANTHROPIC_CUSTOM_HEADERS,
CLAUDE_CODE_SCRIPT_CAPS, CLAUDECODE.
Error messages
Errors returned to MCP clients are truncated (1 KB) and redact sk-ant-*
tokens, Bearer … headers, and any verbatim copies of values held in known
auth env vars. The full untruncated stderr is logged to the MCP server's local
stderr for debugging.
License
MIT © 2026 Trevor Spencer
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Latest Blog Posts
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/trevoraspencer/claudecode-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server