Feature request: Remote session control (compact, loop, slash commands via API/MCP)
Problem
Claude Code slash commands (/compact, /loop, etc.) can only be typed directly in the terminal. There's no way to trigger them remotely — not from hooks, not from MCP tools, not from external integrations like Telegram.
This creates significant friction for users who:
- Interact primarily via Telegram/Discord MCP integrations from mobile
- Run long sessions where compaction is needed but they're away from the terminal
- Want to trigger /loop or other commands from external automation
Current Workaround
Run Claude Code inside tmux, then use tmux send-keys -t session "/compact" Enter from SSH/remote. This works but requires terminal multiplexer setup and SSH access.
Proposed Solutions (any of these would help)
Option A: Remote command API
Expose a local API endpoint (e.g., localhost:PORT/api/command) that accepts slash commands:
\\\bash\
curl -X POST localhost:3456/api/command -d '{"command": "/compact"}'
\\
Option B: MCP tool for session control
Add a built-in MCP tool (e.g., \SessionControl\) that the agent can invoke:
\\\\
SessionControl({ action: "compact" })
SessionControl({ action: "loop", prompt: "check CI" })
\\
Option C: File-based command interface
Watch a file (e.g., \~/.claude/remote-commands\) for commands. External processes write to it, Claude Code reads and executes.
Option D: Hook-triggered commands
Allow hooks to return special directives that trigger slash commands:
\\\json\
{ "directive": "compact" }
\\
Use Case
User runs Claude Code with Telegram MCP. They interact from their phone all day. When context gets full, the agent auto-prepares for compaction but cannot trigger /compact itself. User must physically go to the terminal. With remote control, the Telegram message "!compact" could trigger it seamlessly.
Environment
- Claude Code 2.1.101
- macOS, Opus 4.6 (1M context)
- Telegram MCP integration
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗