[FEATURE] Allow triggering slash commands (e.g. /compact) programmatically via MCP or external channels
Preflight Checklist
- [x] I have searched existing requests and this feature hasn't been requested yet
- [x] This is a single feature request (not multiple features)
Problem Statement
When using Claude Code with MCP integrations like Telegram, users can interact with the agent remotely from their phone or other devices. However, slash commands like /compact can only be triggered by typing them directly in the CLI terminal.
If the user is away from their terminal (e.g., chatting via Telegram MCP on their phone), they have no way to trigger /compact or other session management commands remotely. They must physically go back to the terminal to run them.
As MCP adoption grows and more users interact with Claude Code through external channels, the inability to manage sessions remotely becomes a real friction point.
Proposed Solution
Expose a mechanism for MCP tools or the agent itself to trigger slash commands like /compact programmatically. This could be:
- A built-in tool (e.g.,
run_slash_command) that the agent can invoke on behalf of the user when requested - An API/hook that MCP servers can call to trigger session management commands
At minimum, /compact would be the most useful command to support remotely, since context management becomes critical during long remote sessions.
Alternative Solutions
- Manually going back to the terminal — Works but defeats the purpose of remote interaction via MCP
- Starting a new session — Loses all conversation context and state
- Using
claude -p(non-interactive mode) — Can be triggered remotely but loses session context and conversation history - File-based signaling — Agent watches a file for commands, but this is hacky and fragile
None of these provide a seamless remote session management experience.
Priority
Medium - Would be very helpful
Feature Category
MCP server integration
Use Case Example
- User starts a Claude Code session with Telegram MCP
- User leaves their desk and continues chatting with Claude via Telegram on their phone
- After a long conversation, context gets large
- User asks Claude to compact via Telegram
- Currently: Claude cannot run
/compact— user must physically go back to the terminal - With this feature: Claude triggers
/compactprogrammatically and the session continues smoothly
Additional Context
Related but different from #33679 which focuses on displaying MCP notifications in the chat UI. This request is specifically about allowing session management commands to be triggered from external channels.
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗