Skip to content
Agent Orchestration
Hook

Hooks

What metaswarm runs automatically, and when. A hook is a command Claude Code fires at a fixed moment, without you asking for it.

From plugin
metaswarm
43714 skills23 agents16 commands2 hooks

Claude Code

$ npx -y skills add dsifry/metaswarm --agent claude-code

What fires, and when

SessionStart

Fires once when a session begins, and again after a context compaction. It is where a plugin sets up its environment, or restores state the compaction dropped.

  • Matchesstartup|resume|clear|compact"${CLAUDE_PLUGIN_ROOT}/hooks/session-start.sh"

PreCompact

  • "${CLAUDE_PLUGIN_ROOT}/hooks/session-start.sh"
Read hooks/hooks.json

Where it lives

  • hooks/session-start.shRunsGitHub
    Read the script
    #!/usr/bin/env bash
    # hooks/session-start.sh
    # SessionStart + PreCompact hook for metaswarm plugin
    # Outputs JSON with hookSpecificOutput.additionalContext
    
    set -euo pipefail
    
    # --- Phase 0: Self-locate plugin root ---
    # Works with Codex ($PLUGIN_ROOT), Claude Code ($CLAUDE_PLUGIN_ROOT),
    # Gemini CLI ($extensionPath), or direct invocation (derive from script location)
    SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
    CODEX_PLUGIN_ROOT="${PLUGIN_ROOT:-}"
    PLUGIN_ROOT="${PLUGIN_ROOT:-${CLAUDE_PLUGIN_ROOT:-${extensionPath:-$(cd "$SCRIPT_DIR/.." && pwd)}}}"
    METASWARM_PLATFORM="${METASWARM_PLATFORM:-}"
    if [ -z "$METASWARM_PLATFORM" ]; then
      if [ -n "${CLAUDE_PLUGIN_ROOT:-}" ]; then
        METASWARM_PLATFORM="claude"
      elif [ -n "${extensionPath:-}" ]; then
        METASWARM_PLATFORM="gemini"
      elif [ -n "$CODEX_PLUGIN_ROOT" ] || [ -n "${CODEX_HOME:-}" ]; then
        METASWARM_PLATFORM="codex"
      else
        METASWARM_PLATFORM="claude"
      fi
    fi
    
    # --- Phase 1: BEADS dedup check ---
    # If the standalone beads plugin is installed, it already runs `bd prime` (bd workflow
    # context) on SessionStart/PreCompact, so this hook skips its own `bd prime` call below.
    beads_standalone=false
    beads_plugin_caches=("${HOME}/.claude/plugins/cache" "${CODEX_HOME:-${HOME}/.codex}/plugins/cache")
    for beads_plugin_cache in "${beads_plugin_caches[@]}"; do
      if [ -d "$beads_plugin_cache" ]; then
        # Look for a BEADS plugin with name "beads" in plugin.json
        while IFS= read -r -d '' pjson; do
          pname=""
          if command -v jq >/dev/null 2>&1; then
            pname=$(jq -r '.name // empty' "$pjson" 2>/dev/null || true)
          elif command -v node >/dev/null 2>&1; then
            pname=$(node -e "try{console.log(JSON.parse(require('fs').readFileSync(process.argv[1],'utf-8')).name||'')}catch{console.log('')}" "$pjson" 2>/dev/null || true)
          fi
          # Neither jq nor node available — skip dedup check (safe default: allow both to prime)
          if [ "$pname" = "beads" ]; then
            beads_standalone=true
            break
          fi
        done < <(find "$beads_plugin_cache" \( -path "*/.claude-plugin/plugin.json" -o -path "*/.codex-plugin/plugin.json" \) -print0 2>/dev/null || true)
      fi
      [ "$beads_standalone" = true ] && break
    done
    
    # --- Phase 2: New project detection ---
    new_project=false
    if [ ! -f ".metaswarm/project-profile.json" ]; then
      new_project=true
    fi
    
    # --- Phase 3: Legacy install detection ---
    legacy_install=false
    if [ -f ".claude/plugins/metaswarm/.claude-plugin/plugin.json" ]; then
      legacy_install=true
    fi
    
    # --- Phase 3.5: Self-heal mandatory files ---
    # If project profile exists but mandatory files are missing, run the setup script.
    # This catches cases where the agent skipped file creation during setup.
    if [ "$new_project" = false ] && [ "$legacy_install" = false ]; then
      setup_script="${PLUGIN_ROOT}/lib/setup-mandatory-files.sh"
      needs_heal=false
    
      case "$METASWARM_PLATFORM" in
        codex) instruction_file="AGENTS.md" ;;
        gemini) instruction_file="GEMINI.md" ;;
        *) instruction_file="CLAUDE.md" ;;
      esac
    
      if ! grep -q "metaswarm" "$instruction_file" 2>/dev/null; then
        needs_heal=true
      fi
      if [ ! -f ".coverage-thresholds.json" ]; then
        needs_heal=true
      fi
      # A Go project's enforcement command runs the gate program (#87). If only the
      # gate file is gone, it is copied back below without the full setup run, so
      # customized command shims are not rewritten. A full heal writes it anyway.
      needs_gate=false
      if [ ! -f ".metaswarm/go-coverage-gate.go" ] \
        && grep -qF ".metaswarm/go-coverage-gate.go" ".coverage-thresholds.json" 2>/dev/null; then
        needs_gate=true
      fi
      if { [ "$METASWARM_PLATFORM" = "claude" ] || [ "$METASWARM_PLATFORM" = "all" ]; } \
        && { [ ! -f ".claude/commands/start-task.md" ] || ! grep -q "metaswarm" ".claude/commands/start-task.md" 2>/dev/null; }; then
        needs_heal=true
      fi
    
      if [ "$needs_heal" = true ] && [ -f "$setup_script" ]; then
        # Read coverage command from project profile
        cov_cmd=""
        cov_threshold="100"
        if command -v node >/dev/null 2>&1 && [ -f ".metaswarm/project-profile.json" ]; then
          cov_info=$(node -e "
            try {
              const p = JSON.parse(require('fs').readFileSync('.metaswarm/project-profile.json','utf-8'));
              const t = p.choices?.coverage_threshold || p.coverage?.threshold || p.thresholds?.coverage || 100;
              const c = p.commands?.coverage || 'pytest --cov --cov-fail-under=' + t;
              console.log(t + '|' + c);
            } catch { console.log('100|pytest --cov --cov-fail-under=100'); }
          " 2>/dev/null || echo "100|pytest --cov --cov-fail-under=100")
          cov_threshold="${cov_info%%|*}"
          cov_cmd="${cov_info##*|}"
        fi
        [ -z "$cov_cmd" ] && cov_cmd="pytest --cov --cov-fail-under=${cov_threshold}"
    
        # Run the setup script silently
        bash "$setup_script" "$(pwd)" "$cov_threshold" "$cov_cmd" --platform "$METASWARM_PLATFORM" >/dev/null 2>&1 || true
      elif [ "$needs_gate" = true ]; then
        gate_template="${PLUGIN_ROOT}/skills/setup/templates/go-coverage-gate.go"
        # Best-effort, like the rest of self-heal, but a failure is reported on
        # stderr (stdout carries the hook's JSON).
        if [ ! -f "$gate_template" ]; then
          echo "metaswarm: could not restore .metaswarm/go-coverage-gate.go: template not found at $gate_template" >&2
        elif ! { mkdir -p .metaswarm && cp "$gate_template" .metaswarm/go-coverage-gate.go; } 2>/dev/null; then
          echo "metaswarm: could not restore .metaswarm/go-coverage-gate.go from $gate_template (is .metaswarm/ writable?)" >&2
        fi
      fi
    fi
    
    # --- Phase 4: Build context message ---
    context_parts=()
    
    setup_cmd='$setup'
    start_cmd='$start'
    migrate_cmd='$migrate'
    case "$METASWARM_PLATFORM" in
      claude)
        setup_cmd='/setup'
        start_cmd='/start-task'
        migrate_cmd='/migrate'
        ;;
      gemini)
        setup_cmd='/metaswarm:setup'
        start_cmd='/metaswarm:start-task'
        migrate_cmd='/metaswarm:migrate'
        ;;
    esac
    
    if [ "$new_project" = true ]; then
      contex

Read the script before you install anything that runs on your machine. This is the one part of a plugin that acts without being asked.

@dsifry
Ships withmetaswarm

A self-improving multi-agent orchestration framework for Claude Code, Gemini CLI, and Codex CLI.

43714 skills23 agents
Get the whole plugin

Stars on GitHub

Momentum

stars in total
437
Star history of dsifry/metaswarm on GitHub, a chart by star-history.com

More plugins that ship hooks.

oh-my-claudecode

oh-my-claudecode

Splits a complex task across several specialized Claude Code agents working in parallel, then keeps going until the result is checked. You describe what you want in plain language instead of memorizing commands.

84 skills+441k
@yeachan-heo@yeachan-heo
Install Plugin
ouroboros

ouroboros

Turns a rough feature idea into a written spec through guided questions, then has the agent build it and checks the result against that spec. Instead of hand-checking whether the work is finished, you get an automatic evaluation gate that runs in your coding agent.

26 skills+36.4k
@q00@q00
Install Plugin
myclaude

myclaude

A plugin that runs coding tasks through multiple AI backends (Codex, Claude, Gemini, OpenCode) with a structured development workflow, parallel execution, browser automation and multi-session task checkpointing.

11 skills+32.8k
@stellarlinkco@stellarlinkco
Install Plugin
harmonist

harmonist

Coordinates AI agents with mechanical protocol enforcement, a workflow gate, memory validation and a session hook. Includes a catalog of specialist agents and has no runtime dependencies.

199 agents+12.1k
@gammalabtechnologies@gammalabtechnologies
Install Plugin
bernstein

bernstein

Bernstein is a Claude Code plugin for orchestrating AI agents. It adds skills to list and inspect agents, review and approve tasks, create tasks, track costs and budgets, and show alerts for failed or stalled work.

26 skills+41.2k
@sipyourdrink-ltd@sipyourdrink-ltd
Install Plugin
fablize

fablize

A Claude Code plugin that enforces finishing multi-step tasks with evidence and verification at each stage. It works as a procedure for Opus or any Claude model, not as chance.

1 skill+2893
@fivetaku@fivetaku
Install Plugin
super-board

super-board

Autonomous GitHub Project build → QA → review loop for Claude Code. One-line install.

10 skills7 hooks725
@erictechpro@erictechpro
Install Plugin
hello2cc

hello2cc

Adjusts how third-party models behave inside Claude Code so they run closer to a native Opus session, covering subagent lifecycle, session hooks and tool interception. It does not replace your gateway, provider mapping or account setup.

1 agent11 hooks687
@hellowind777@hellowind777
Install Plugin

Questions about the hooks in metaswarm.

Which coding agents can use the hooks in metaswarm?
The hooks in metaswarm install in Claude Code and Cursor: each runs Claude Code hooks from .claude/settings.json, so copy the hooks there.