lewibs/dark-factory/hook-dual-flow-command-dispatch
Claude Code and agent skill by lewibs/dark-factory
- community
Checking that the SKILL.md file is still in the repository.
How to implement a single hook script that serves two distinct flows (e.g., check and mutate) by dispatching on a 'command' field in tool_input, so both guard and write operations share one registration.
Install
npx vskill@latest install lewibs/dark-factory/hook-dual-flow-command-dispatchSKILL.md
The same SKILL.md was published earlier as lewibs/dark-factory/hook-dual-flow-command-dispatch.
When to use
When a hook needs to handle two logically related but distinct operations — for example, a pre-tool-use guard that checks state and a separate write path that marks state as complete — and you want to register only one hook entry rather than two separate scripts.
The pattern uses tool_input.command as a discriminator field. Callers that want the mutate path set command explicitly; calls without command default to the check path.
Steps
- In the hook's
main(), read thecommandfield fromtool_input:
``bash command_field=$(printf '%s' "$tool_input" | jq -r '.tool_input.command // ""') ``
- Dispatch to the appropriate function based on the field value:
```bash if [ "$command_field" = "mark-phase-complete" ]; then agent_name=$(printf '%s' "$tool_input" | jq -r '.tool_input.agentName // ""') phase_number=$(printf '%s' "$tool_input" | jq -r '.tool_input.phaseNumber // 0') markPhaseComplete "$agent_name" "$phase_number" return fi
# Default: check path agent_name=$(printf '%s' "$tool_input" | jq -r '.tool_input.agentName // ""') current_phase=$(printf '%s' "$tool_input" | jq -r '.tool_input.currentPhase // 0') checkPhaseOrder "$agent_name" "$current_phase" ```
- Implement both functions in the same script. Each function outputs JSON to stdout and calls
exit 0(never a non-zero exit — hooks must not crash Claude Code). The mutate function callsmarkPhaseComplete; the guard function callscheckPhaseOrderor equivalent.
- Register the hook once in
hooks/hooks.json:
``json { "PreToolUse": [ { "matcher": "", "hooks": [{ "type": "command", "command": "bash \"${CLAUDE_PLUGIN_ROOT}/agents/dark-factory/scripts/my-hook.sh\"" }] } ] } ` Both flows use the same registration. The command field in tool_input` selects which code path runs at call time.
- In tests, exercise each path by setting or omitting the
commandfield in the test fixture:
```python # Check path (no command field) hook_input = {"tool_name": "Agent", "tool_input": {"agentName": "dark-factory-agent", "currentPhase": 2}}
# Mutate path hook_input = {"tool_name": "Bash", "tool_input": {"command": "mark-phase-complete", "agentName": "dark-factory-agent", "phaseNumber": 1}} ```
Notes
- Use a string enum for
commandvalues (e.g.,"mark-phase-complete") rather than a boolean flag so the dispatch is extensible to more than two paths in the future. - The
commandfield is read fromtool_input.command(one level inside the outertool_inputobject), not from the top-level hook JSON. The outertool_namefield identifies the Claude tool type (e.g.,Agent,Bash) and is separate. - Missing or empty
commandalways falls through to the default (check) path. This keeps ordinary Agent/tool invocations on the safe read-only path with no additional fields required. - Both functions must be idempotent or at least safe to call multiple times, because hooks fire for every matching tool invocation — including retries.
- Do not branch on
tool_nameto distinguish the two paths.tool_namereflects the Claude tool being used (e.g.,Bash,Agent), not the intent. Thecommandfield insidetool_inputis the correct discriminator for intent.
Security
- Security scanPassed, 90 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/hook-dual-flow-command-dispatch/SKILL.md
Popularity
- Repository forks
- 1
- 7-day trend score
- 0
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/lewibs/dark-factory/hook-dual-flow-command-dispatch)