date: 2025-08-28 15:34:28 PDT researcher: Mikayla Maki git_commit: 565782a1c769c90e58e012a80ea1c2d0cfcdb837 branch: claude-experiments repository: zed topic: "Custom Slash Commands for Agent Client Protocol" tags: [research, codebase, acp, slash-commands, claude-code, protocol-extension] status: complete last_updated: 2025-08-28 last_updated_by: Mikayla Maki
Research: Custom Slash Commands for Agent Client Protocol
Date: 2025-08-28 15:34:28 PDT Researcher: Mikayla Maki Git Commit: 565782a1c769c90e58e012a80ea1c2d0cfcdb837 Branch: claude-experiments Repository: zed
Research Question
We're adding support for custom slash commands to Agent Client Protocol. The client should be able to:
- List available commands
- Run a command with arguments (check Claude Code behavior)
In the Claude Code ACP adapter, we want implement the agent side of the protocol:
- List commands by reading out of the
.claude/commandsdirectory - Run commands via the SDK
We need to update the protocol to support the new RPCs for listing and running commands. We need to understand how to run commands via the SDK.
Summary
The research reveals a comprehensive architecture for implementing custom slash commands in ACP:
Claude Code Slash Commands: Well-established system with 15+ built-in commands, extensible architecture, and consistent execution patterns through the SlashCommand trait.
ACP Protocol: JSON-RPC based with clear patterns for adding new RPC methods through request/response enums, method dispatch, and capability negotiation.
Claude Commands Structure: Markdown-based command definitions in .claude/commands/ with consistent format, metadata, and programmatic parsing potential.
SDK Integration: Claude Code ACP adapter bridges ACP protocol with Claude SDK, providing tool execution and session management through MCP servers.
Detailed Findings
Claude Code Slash Command Architecture
Core Infrastructure (crates/assistant_slash_command/):
assistant_slash_command.rs:1-200-SlashCommandtrait withname(),description(),run(),complete_argument(),requires_argument()methodsslash_command_registry.rs:1-150- Global registry for command registration and lookupslash_command_working_set.rs:1-100- Working set management for active commandsextension_slash_command.rs:1-250- Extension-based command support
Execution Flow:
- Commands registered in
agent_ui.rs:403-448viaslash_command_registry.register_command() - User types
/command argsin editor SlashCommandCompletionProviderprovides completionsTextThreadEditor.run_command()callscommand.run()- Commands return stream of
SlashCommandEvents - Events processed and inserted into context
Built-in Commands (crates/assistant_slash_commands/):
- File operations:
/file,/tab,/selection - Development:
/cargo-workspace,/diagnostics,/symbols - Context:
/context-server,/fetch,/prompt - Utility:
/now,/delta
Agent Client Protocol RPC Patterns
Core Structure (agentic-coding-protocol/):
- JSON-RPC based bidirectional communication
- Type-safe request/response enums with static dispatch
- Capability negotiation for feature opt-in
- Auto-generated JSON Schema from Rust types
RPC Method Pattern:
- Define request/response structs with
#[derive(Serialize, Deserialize, JsonSchema)] - Add method name constant:
const NEW_METHOD_NAME: &str = "new/method" - Add variants to
ClientRequest/AgentRequestenums - Update trait definition with async method signature
- Add to dispatch logic in
decode_request()andhandle_request()
Existing Methods:
initialize- Capability negotiation and authenticationsession/new,session/load- Session managementsession/prompt- Message processingfs/read_text_file,fs/write_text_file- File operationssession/request_permission- Permission requests
.claude/commands Directory Structure
Format: Markdown files with consistent structure:
# Command Name
[Description]
## Initial Response
[Standardized first response]
## Process Steps
### Step 1: [Phase Name]
[Instructions]
## Important Guidelines
[Constraints and behaviors]
Metadata Extraction Points:
- H1 title for command name and description
- "Initial Response" section for invocation behavior
- Sequential process steps under "Process Steps"
- Checkbox lists (
- [ ],- [x]) for progress tracking - Code blocks with executable commands
Command Categories:
- Development workflow:
create_plan.md,implement_plan.md,validate_plan.md,commit.md - Research:
research_codebase.md,debug.md - Project management:
ralph_plan.md,founder_mode.md
Claude Code ACP Adapter Implementation
Architecture (claude-code-acp/src/):
acp-agent.ts- MainClaudeAcpAgentimplementing ACP Agent interfacemcp-server.ts- Internal MCP server for file operations and permissionstools.ts- Tool conversion between Claude and ACP formats- Session management with unique IDs and Claude SDK
Queryobjects
Integration Pattern:
let q = query({
prompt: input,
options: {
cwd: params.cwd,
mcpServers: { acp: mcpServerConfig },
allowedTools: ["mcp__acp__read"],
disallowedTools: ["Read", "Write", "Edit", "MultiEdit"],
},
});
Tool Execution Flow:
- ACP client makes tool request
- Claude ACP agent converts to Claude SDK format
- Internal MCP server proxies to ACP client capabilities
- Results converted back to ACP format
Code References
crates/assistant_slash_command/src/assistant_slash_command.rs:1-200- Core SlashCommand traitcrates/agent_ui/src/agent_ui.rs:403-448- Command registration pointagentic-coding-protocol/rust/agent.rs:604-610- ACP request enum patternagentic-coding-protocol/rust/acp.rs:355-371- Method dispatch logicclaude-code-acp/src/acp-agent.ts:1-500- ACP adapter implementation.claude/commands/*.md- Command definition files
Architecture Insights
Slash Command System: Highly modular with clear trait-based abstraction, supports both built-in and extension commands, uses streaming execution model with event-based progress reporting.
ACP Protocol: Designed for extensibility with capability negotiation, type safety through Rust enums, symmetric bidirectional design, and JSON-RPC foundation.
Command Definitions: Human-readable markdown with programmatically parseable structure, consistent metadata patterns, and workflow automation framework.
Integration Patterns: Claude Code ACP adapter provides proven pattern for bridging protocols, MCP servers enable tool execution proxying, session management handles concurrent interactions.
Implementation Recommendations
1. Protocol Extension for Custom Commands
Add new RPC methods to ACP schema:
// New request types
pub struct ListCommandsRequest {
pub session_id: SessionId,
}
pub struct RunCommandRequest {
pub session_id: SessionId,
pub command: String,
pub args: Option<String>,
}
// Response types
pub struct ListCommandsResponse {
pub commands: Vec<CommandInfo>,
}
pub struct CommandInfo {
pub name: String,
pub description: String,
pub requires_argument: bool,
}
2. Agent Implementation
In Claude Code ACP adapter:
async listCommands(request: ListCommandsRequest): Promise<ListCommandsResponse> {
// Read .claude/commands directory
// Parse markdown files for metadata
// Return CommandInfo array
}
async runCommand(request: RunCommandRequest): Promise<RunCommandResponse> {
// Find command definition in .claude/commands/
// Execute via Claude SDK query with command content
// Stream results back via session notifications
}
3. Command Parsing
Implement markdown parser for .claude/commands/*.md:
function parseCommandFile(content: string): CommandInfo {
// Extract H1 title for name/description
// Find "Initial Response" section
// Parse metadata and requirements
// Return structured command info
}
Open Questions
-
Command Arguments: How should complex command arguments be structured and validated?
-
Command Context: Should commands have access to current session state, file context, or conversation history?
-
Command Discovery: Should commands be cached or re-read on each listing request?
-
Extension Commands: How should extension-provided commands integrate with
.claude/commands/file-based commands? -
Command Execution: Should commands run in isolated contexts or share session state?
-
Error Handling: What's the appropriate error handling strategy for command parsing and execution failures?
FINAL CLAUDE PROMPT:
⏺ I've completed comprehensive research on adding custom slash commands to the Agent Client Protocol. Here's what I found:
Key Findings
Slash Command Architecture: Claude Code has a well-established slash command system with 15+ built-in commands using a SlashCommand trait. Commands are registered globally and execute through streaming events.
ACP Protocol Patterns: The protocol uses JSON-RPC with type-safe request/response enums. Adding new RPC methods follows a clear pattern: define structs, add to enums, update dispatch logic.
.claude/commands Structure: Commands are defined as structured Markdown files with consistent format - perfect for programmatic parsing. Each contains metadata, process steps, and execution guidelines.
SDK Integration: The Claude Code ACP adapter already bridges ACP with the Claude SDK through MCP servers, providing a proven pattern for command execution.
Implementation Approach
You'll need to:
- Extend ACP Protocol: Add ListCommandsRequest/Response and RunCommandRequest/Response to the schema
- Parse Command Definitions: Read .claude/commands/*.md files and extract metadata (name, description, requirements)
- Execute Commands: Run commands via Claude SDK queries, similar to how the current ACP adapter works
- Handle Streaming: Use ACP's session notification system to stream command progress
The research document is saved at thoughts/shared/researc h/2025-08-28_15-34-28_custom-slash-commands-acp.md with detailed implementation recommendations, code references, and open questions for your consideration.
STATS ON PROMPT TO GENERATE THIS DOCUMENT:
Total cost: $2.87 Total duration (API): 12m 59.0s Total duration (wall): 6m 52.2s Total code changes: 242 lines added, 0 lines removed Usage by model: claude-3-5-haiku: 4.3k input, 175 output, 0 cache read, 0 cache write claude-sonnet: 2.9k input, 31.3k output, 4.8m cache read, 256.1k cache write