Skip to main content
Glama
README.md
# mcp-claude-code

An [MCP](https://modelcontextprotocol.io) server that drives the **Claude Code CLI** in headless mode, so any MCP client (Claude Desktop, Antigravity, Cursor, another agent…) can delegate coding tasks to Claude Code, resume sessions, inspect context usage and read account limits.

## Requirements

- Node.js 18+
- [Claude Code](https://docs.claude.com/en/docs/claude-code) installed and logged in (`claude` on `PATH`, or set `CLAUDE_BIN`)

## Install

```bash
git clone https://github.com/<owner>/mcp-claude-code.git
cd mcp-claude-code
npm install
```

## Client configuration

```json
{
  "mcpServers": {
    "claude-code": {
      "command": "node",
      "args": ["/path/to/mcp-claude-code/server.mjs"],
      "env": {
        "WORKSPACE_DIR": "/path/to/your/project"
      }
    }
  }
}
```

## Tools

| Tool | Arguments | Description |
| --- | --- | --- |
| `claude_run_task` | `prompt` (required), `sessionId`, `model` (`opus`\|`sonnet`\|`haiku`\|`fable`), `effort` (`low`…`max`), `cwd`, `permissionMode` (`bypassPermissions`\|`acceptEdits`\|`plan`\|`default`), `timeoutMs` | Runs a task with `claude -p --output-format stream-json`. Starts a new session or resumes `sessionId`. Returns the final response, session ID, tools executed, token usage, cost and where it ran. 30 min hard timeout (configurable) plus a 5 min inactivity watchdog. |
| `claude_session_status` | `sessionId` (required), `projectDir` | Reads the session JSONL under `~/.claude/projects` and reports context tokens, % of the 1M window, active model, turn counts and a near-limit flag. |
| `claude_list_sessions` | `limit` (default 10), `cwd` | Lists the most recent sessions with initial prompt, model and context usage. Optionally filtered by project directory. |
| `claude_compact_session` | `sessionId` (required), `cwd` | Sends `/compact` to a session and reports tokens before/after. |
| `claude_account_limits` | — | Live 5-hour and weekly quota (% used/remaining, reset times) captured from Claude Code `rate_limit_event`s (cached 3 min), plus today's token consumption across all local sessions. |
| `claude_configure` | `model`, `effort` | Reads or updates the default model/effort used when `claude_run_task` omits them. |

> ⚠️ `permissionMode` defaults to `bypassPermissions` (`--dangerously-skip-permissions`). Only point this server at workspaces where unattended command execution is acceptable, or pass a stricter mode.

## Environment variables

See [`.env.example`](.env.example). All are optional.

| Variable | Default | Purpose |
| --- | --- | --- |
| `WORKSPACE_DIR` | server `cwd` | Default working directory for tasks |
| `CLAUDE_BIN` | auto-detected | Path to the `claude` CLI |
| `CLAUDE_MCP_SETTINGS_FILE` | `~/.config/mcp-claude-code/settings.json` | Persisted defaults from `claude_configure` |
| `CLAUDE_MCP_QUOTA_FILE` | `~/.claude-live-quota.json` | Quota telemetry cache |
| `CLAUDE_MCP_LOCALE` | `es-AR` | Locale for reset-time formatting |

### Optional remote SSH worker

By default every task runs locally. Set `CLAUDE_REMOTE_SSH_HOST` to run tasks on another machine over SSH instead:

| Variable | Default | Purpose |
| --- | --- | --- |
| `CLAUDE_REMOTE_SSH_HOST` | *(unset → disabled)* | SSH host or `~/.ssh/config` alias (key-based login required) |
| `CLAUDE_REMOTE_BIN` | `claude` | Claude Code binary on the remote host |
| `CLAUDE_REMOTE_WORKSPACE_DIR` | local `cwd` | Working directory on the remote host |
| `CLAUDE_REMOTE_SYNC_SESSIONS` | `1` | `rsync` session JSONL files to/from the remote so `--resume` and the session tools keep working |
| `CLAUDE_REMOTE_FORWARD_TOKEN` | `0` | Forward the local `CLAUDE_CODE_OAUTH_TOKEN` over stdin (never on the command line) |
| `FORCE_LOCAL_CLAUDE` | `0` | `1` forces local execution |

If the SSH connection fails before any output (exit 255), the task is retried locally.

## Development

```bash
npm run check   # node --check on every module
npm start       # run the stdio server
```

## License

MIT

TDQS

A3.5/5.0

Scored across 6 tools

Disambiguation4/5

Each tool maps to a fairly distinct action (list, compact, account quota, configure, run, status), but claude_list_sessions and claude_session_status overlap since both report tokens and model, differing mainly in scope and detail level. claude_account_limits vs claude_session_status also both surface token/limit information, which could cause occasional misselection.

Naming Consistency4/5

All tools share a claude_ prefix and snake_case, which is highly predictable. Minor deviations exist: account_limits is noun-only and configure is verb-only, while the rest follow verb_noun (list_sessions, compact_session, run_task, session_status).

Tool Count5/5

Six tools is a well-scoped set for a Claude Code session manager: discovery, inspection, maintenance, configuration, quota check, and task execution. Each tool clearly earns its place with no filler.

Completeness3/5

Core lifecycle is covered (list, inspect, compact, run, configure, quota), but there is no way to read a session's actual transcript or task output, nor to delete/clean up or stop a running session. These gaps will force agents to work around missing read/cleanup operations when a task result needs inspecting.

Maintenance

ActivityMaintained
ResponsivenessNo recent community issues