Add auto-slash-command hook for intercepting and replacing slash commands

This hook intercepts user messages starting with '/' and REPLACES them with the actual command template output instead of injecting instructions. The implementation includes:

- Slash command detection (detector.ts) - identifies messages starting with '/'
- Command discovery and execution (executor.ts) - loads templates from ~/.claude/commands/ or similar
- Hook integration (index.ts) - registers with chat.message event to replace output.parts
- Comprehensive test coverage - 37 tests covering detection, replacement, error handling, and command exclusions
- Configuration support in HookNameSchema

Key features:
- Supports excluded commands to skip processing
- Loads command templates from user's command directory
- Replaces user input before reaching the LLM
- Tests all edge cases including missing files, malformed templates, and special commands

🤖 Generated with assistance of OhMyOpenCode (https://github.com/code-yeongyu/oh-my-opencode)
This commit is contained in:
YeonGyu-Kim
2026-01-01 20:59:36 +09:00
parent b30c17ac77
commit 490c0b626f
10 changed files with 953 additions and 0 deletions

View File

@@ -69,6 +69,7 @@ export const HookNameSchema = z.enum([
"preemptive-compaction",
"compaction-context-injector",
"claude-code-hooks",
"auto-slash-command",
])
export const BuiltinCommandNameSchema = z.enum([