claude-code-mcp

claude-code-mcp

An MCP server that gives orchestrator agents fine-grained control over interactive Claude Code sessions running inside tmux, enabling mid-session steering, interruption, and token-efficient result extraction.

Category
访问服务器

README

claude-code-mcp

It ssounds dumb... but its literally that. Using Claude Code through an MCP server. Its neant for orchestrator agents (like Hermes), giving it fine-grained control over interactive Claude Code sessions running inside tmux.

The core value: a long-running Claude Code REPL stays alive in a tmux pane, and your orchestrator can steer it at any point — send the initial prompt, inject a follow-up message mid-session, interrupt a stuck run, or read back only the final answer (token-efficient by default). Way better than using it through 'claude -p'.

Why an orchestrator needs this

When Hermes (or any multi-agent system) delegates a coding task to Claude Code, it needs more than a one-shot call. It needs to:

Need This server's tool
Send a prompt, get back only the final answer session_send
Steer a follow-up into an already-running session session_send on an existing session
Interrupt a runaway or wrong-direction task session_interrupt
Check whether Claude is still thinking or idle session_status / health
Resume a session after a restart without losing history session_start + --resume
Destroy a session when the task is done session_destroy

Why not claude -p?

claude -p (print / pipeline mode) exits after one response. There is no channel to inject a follow-up — every turn requires spawning a fresh process and loses accumulated context.

This server keeps the interactive REPL (claude with no flags) alive in a tmux pane so prompts can be injected at any time via tmux key injection, history accumulates inside the running process, and mid-run interrupts (Ctrl-C) work as expected.

Features

  • Steer mid-session — session_send injects into an already-running session as naturally as typing; no restart required.
  • Send & auto-create — if the session doesn't exist yet it is created transparently; no separate session_start call required.
  • Resume across restarts — store a Claude session ID once; all future recreations use claude --resume <id> automatically.
  • Working directory persistence — supply working_dir once; recreated sessions start in the same directory.
  • Hard interrupt — sends Ctrl-C with no extra text injected.
  • Health / state — health reports binary availability and all session states at a glance; session_status drills into one session.
  • Token-efficient — default output is the extracted assistant text only; full pane dump is opt-in via raw=True.
  • Pure stdlib + mcp SDK — no heavy dependencies.

Requirements

Tool Version
Python ≥ 3.11
tmux ≥ 3.4
Claude Code ≥ 2.0

Installation

pip install claude-code-mcp

Or with uv:

uv tool install claude-code-mcp

For development:

git clone https://github.com/joschi655/claude-code-mcp
cd claude-code-mcp
pip install -e ".[dev]"

MCP configuration

Claude Desktop / Claude Code (~/.claude/claude_desktop_config.json)

{
  "mcpServers": {
    "claude-code-mcp": {
      "command": "claude-code-mcp"
    }
  }
}

With uvx (no install required)

{
  "mcpServers": {
    "claude-code-mcp": {
      "command": "uvx",
      "args": ["claude-code-mcp"]
    }
  }
}

Hermes / custom MCP client

{
  "mcpServers": {
    "claude-code-mcp": {
      "command": "python",
      "args": ["-m", "claude_code_mcp"]
    }
  }
}

Tools

health()

System health check: returns binary availability and a summary of all known sessions.

{
  "tmux_available": true,
  "claude_available": true,
  "session_count": 1,
  "sessions": [...]
}

session_send(name, prompt, timeout?, raw?, claude_session_id?, working_dir?)

Send a prompt to a session — or steer a follow-up into an already-running one — and return Claude's final answer. The session is created automatically if it does not exist.

{ "name": "hermes-main", "prompt": "Now run the tests and fix any failures" }

Returns:

{ "response": "...", "timed_out": false, "raw": false }
  • timeout (default 120 s) — give up after this many seconds.
  • raw=true — returns the full pane dump instead of the extracted answer (useful for debugging).
  • claude_session_id — used when auto-creating: runs claude --resume <id>.
  • working_dir — used when auto-creating: starts the session in this directory and stores it in metadata for future recreations.

Steering example — Hermes delegates a task, then decides mid-flight to redirect it:

session_send("hermes-main", "implement feature X")
# … later, while Claude is still idle or about to start a wrong approach …
session_send("hermes-main", "actually focus on the auth module first")

session_start(name, claude_session_id?, working_dir?)

Explicitly create a new tmux + Claude Code session, or reconnect to an existing one.

  • If a tmux session called name already exists it is returned as-is.
  • If metadata for name has a stored claude_session_id, runs claude --resume <id> to restore conversation history.
  • working_dir is stored in metadata so future recreations start in the same directory.
{ "name": "hermes-main", "working_dir": "/home/user/myproject" }

Returns SessionInfo with tmux_alive, claude_alive, state, claude_session_id, working_dir.


session_interrupt(name)

Send Ctrl-C to abort the current operation. No extra text is sent. Use this when Hermes detects that Claude is going in the wrong direction and wants to redirect without waiting for a full response.


session_status(name)

Health check for a single session.

{
  "name": "hermes-main",
  "tmux_alive": true,
  "claude_alive": true,
  "state": "idle",
  "claude_session_id": null,
  "working_dir": "/home/user/myproject"
}

session_list()

List all managed sessions (from metadata) plus all live tmux sessions.


session_destroy(name)

Kill the tmux session and remove stored metadata.


session_set_claude_id(name, claude_session_id)

Associate a Claude session ID with name so future restarts can use --resume. Call this after the session is running and you know the ID (e.g. from /session-id inside Claude Code).

Typical orchestrator workflow

# One-step delegation (session is auto-created)
session_send("hermes-main", "implement feature X and run the tests")
# → creates session if needed, waits for Claude to finish, returns final answer

# Steer a follow-up into the running session
session_send("hermes-main", "the tests are failing — fix the import error first")

# Interrupt if Claude is going the wrong way
session_interrupt("hermes-main")
session_send("hermes-main", "forget the previous approach, use the adapter pattern")

# System overview
health()
# → { tmux_available: true, claude_available: true, session_count: 1, ... }

# Single session check
session_status("hermes-main")
# → { state: "idle", working_dir: "/home/user/myproject", ... }

# Tear down when done
session_destroy("hermes-main")

Session ID and --resume

Claude Code stores conversation history under a session ID. To preserve this across tmux restarts:

  1. Run session_send("name", "/session-id") to ask Claude for its ID.
  2. Call session_set_claude_id("name", "<id>") to persist it.
  3. After a restart, session_start("name") (or session_send) will automatically --resume.

Development

# Unit tests (no tmux/claude required)
pytest tests/test_parser.py tests/test_session_logic.py -v

# Integration tests (requires tmux + claude)
CLAUDE_TMUX_INTEGRATION=1 pytest tests/test_integration.py -v

License

MIT — see LICENSE.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选