self-claude-mcp

self-claude-mcp

MCP server for Claude Code self-management, enabling hot restart and context compaction commands.

Category
Visit Server

README

self-claude-mcp

Requires Claude Code | SIGN UP HERE

MCP server for Claude Code self-management commands (hot restart, compaction).

Installation

pip install self-claude-mcp

Add to your Claude MCP config:

{
  "mcpServers": {
    "self-claude": {
      "command": "self-claude-mcp",
      "env": {
        "AUTOPOIESIS": "1"
      }
    }
  }
}

Note: AUTOPOIESIS=1 is optional. If set, restart messages will remind Claude to enable autopoiesis-mcp (makes Claude loop on purpose). Remove the env block if you don't use it.

Setup

After installing the MCP, Claude needs to install bash scripts for the commands to work.

Ask Claude to run:

Use self_claude with setup_only=True and install the scripts

Or manually: call self_claude(cmd="", setup_only=True) to get the installation instructions.

Requirements

  • tmux: Scripts use tmux for session management
  • Claude Code: Must be running inside a tmux session named "claude"

Starting Claude in tmux

Use claude-debug (installed by setup) or manually:

tmux -u new-session -d -s claude
tmux send-keys -t claude 'claude --debug' Enter
tmux -u attach -t claude

Usage

Once set up, Claude can use these commands:

Command Description
self_claude("self_restart") Hot restart with auto-resume
self_claude("self_compact") Trigger context compaction
self_claude("", setup_only=True) Get installation instructions

Hot Restart

Use when MCP configs change and you need to reload without losing conversation:

  1. Claude calls self_claude("self_restart") → returns bash self_restart
  2. Claude runs bash self_restart
  3. Handler sends /exit, waits for death, relaunches, sends /resume, selects session 1

Compaction

Use when context is running low:

  1. Claude calls self_claude("self_compact") → returns bash self_compact
  2. Claude runs bash self_compact
  3. Sends /compact to the tmux session

Troubleshooting

"No tmux session 'claude'"

Make sure Claude Code is running inside a tmux session named "claude":

tmux -u new-session -s claude
claude --debug

"Handler not found"

Run the setup instructions again:

self_claude(cmd="", setup_only=True)

Then install the scripts to /usr/local/bin/.

Restart hangs

Check the handler log:

cat /tmp/claude_restart_handler.log

Common issues:

  • pgrep -x "claude" matches wrong process → verify with pgrep -x "claude"
  • tmux session died → restart with claude-debug

Docker / Container

If running in a container, make sure:

  • tmux is installed: apt install tmux
  • Scripts are in PATH: /usr/local/bin/ or ~/.local/bin/
  • Container user can write to /tmp/

Scripts Installed

Script Location Purpose
claude-debug /usr/local/bin/ Start Claude in tmux background
self_restart /usr/local/bin/ Orchestrator (spawns handler)
claude_restart_handler /usr/local/bin/ Detached handler (does actual restart)
self_compact /usr/local/bin/ Trigger compaction
rules /usr/local/bin/ Manage Claude Code rule files

rules command

Manage Claude Code rule files from the command line:

# Add a rule
rules global my-rules "Always use TypeScript"
rules project api-rules "Use REST conventions"

# List rules
rules show global
rules show project

# Delete a rule
rules delete global my-rules

Rules are stored in ~/.claude/rules/ (global) or ./.claude/rules/ (project).

Environment Variables

Variable Description
AUTOPOIESIS=1 Enable autopoiesis warning in restart message. Requires autopoiesis-mcp.

Set in your shell profile or export before running Claude.

Security Note

⚠️ Warning: You should disallow this MCP on subagents. Subagents running these commands can cause strange interactions.

License

MIT

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured