lewibs/dark-factory/hook-dual-flow-command-dispatch

Claude Code and agent skill by lewibs/dark-factory

Trust tier 3
  • community
Source check pending

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-dispatch

SKILL.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

  1. In the hook's main(), read the command field from tool_input:

``bash command_field=$(printf '%s' "$tool_input" | jq -r '.tool_input.command // ""') ``

  1. 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" ```

  1. 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 calls markPhaseComplete; the guard function calls checkPhaseOrder or equivalent.
  1. 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.

  1. In tests, exercise each path by setting or omitting the command field 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 command values (e.g., "mark-phase-complete") rather than a boolean flag so the dispatch is extensible to more than two paths in the future.
  • The command field is read from tool_input.command (one level inside the outer tool_input object), not from the top-level hook JSON. The outer tool_name field identifies the Claude tool type (e.g., Agent, Bash) and is separate.
  • Missing or empty command always 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_name to distinguish the two paths. tool_name reflects the Claude tool being used (e.g., Bash, Agent), not the intent. The command field inside tool_input is 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

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
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/lewibs/dark-factory/hook-dual-flow-command-dispatch/badge)](https://verified-skill.com/skills/lewibs/dark-factory/hook-dual-flow-command-dispatch)

Something wrong with this skill or its page? Tell us.