Skip to content

Automations for Claude Code: hooks + plugin recipes (reference implementation) #243

Backlog

Description

@vsn411

Part of #240. Builds on #242 (secfoo hook / secfoo automations) and #241 (every run reports back). Packaging: #225 / PR #230 (Claude plugin). This is the reference implementation. Other tools copy its structure.

What Claude Code offers (checked against the docs on 2026-12-03)

Sources: Hooks reference, Plugins reference. Re-check them and record the Claude Code version you test with.

  • Hook config: ~/.claude/settings.json (user), .claude/settings.json (project, shared), .claude/settings.local.json (project, private), managed policy, plugin hooks/hooks.json, and skill/subagent frontmatter.
  • Events we need:
    • PreToolUse (matcher Bash): block with hookSpecificOutput.permissionDecision: "deny" plus a reason.
    • PostToolUse (matcher on the edit tools): informational.
    • Stop: decision: "block" + reason makes Claude keep going. The input has stop_hook_active, and Claude Code overrides the block after 8 consecutive continuations.
    • SessionStart: inject context.
    • SessionEnd: all hooks share a 1.5 s budget.
  • Timeouts: timeout in seconds, default 600 for command hooks.
  • Background: "async": true runs without blocking. asyncRewake runs in the background and wakes Claude on exit code 2, showing stderr as a reminder. That's ideal for slow reviews.
  • Env: CLAUDE_PROJECT_DIR, CLAUDE_PLUGIN_ROOT, CLAUDE_PLUGIN_DATA, CLAUDE_PLUGIN_OPTION_<KEY> (plugin userConfig).
  • Plugins: .claude-plugin/plugin.json (only name required). Components at the plugin root: skills/<name>/SKILL.md, agents/, hooks/hooks.json, .mcp.json, bin/. Validate with claude plugin validate.
  • Hooks run in claude -p and inside subagents, including plugin and user hooks. This matters for the recursion guard (see Gotchas).
  • Scheduled / cloud: Claude Code cloud scheduled tasks (/schedule), plus the existing secfoo GitHub Action for CI.

Recipe mapping

Recipe Claude Code event Behaviour
commit-guard PreToolUse, matcher Bash, command matches git commit/push, gh pr create Deny with the findings summary when at or above the threshold. Over budget → allow + background
turn-review Stop If files changed this turn, review the diff. Findings at or above the threshold → decision: "block" with the findings so Claude fixes them. Respect stop_hook_active and #242's loop guard
dependency-watch PostToolUse on edits to manifests/lockfiles, asyncRewake: true Background SCA. Wake Claude only if a reachable High+ appears
design-review, ai-feature-review PostToolUse on matching paths, async: true Background, debounced, surfaced on the next Stop / SessionStart
session-brief SessionStart Inject open High+ findings for this repo from the local DB. No run, must take under 1 s
session-flush SessionEnd Only spawn the detached outbox flush and mark pending host-mode runs not_submitted. Never push inline: the budget is 1.5 s
fix-findings Plugin skill /secfoo:fix-findings List open findings, fix them, re-run to confirm closure
scheduled-baseline Cloud scheduled task Prompt that installs secfoo and runs a full baseline with the key from the task's env (#241 item 4)

Gotchas

Install on the fly

Tasks

  • hosts/claude_code.py parse/render with recorded fixtures for PreToolUse, PostToolUse, Stop (with and without stop_hook_active), SessionStart, SessionEnd
  • enable/disable merge into the three settings files without touching other hooks
  • Plugin bundle hooks generated from recipes (Secfoo in every agent marketplace: one MCP server, local by default, optional key for the org portal #224 build step) + /secfoo:automations and /secfoo:fix-findings skills
  • Recursion guard verified with a real nested claude -p run
  • Cloud scheduled task example in docs/automations.md, using the env-var key
  • Verification row (Claude Code version, date, OS, recipes tested, portal received each run with trigger.host = "claude-code")

Done when

All recipes above work against a real Claude Code install. Every run, including blocked, skipped, failed and timed-out ones, appears in secfoo serve and, with a key, on the portal with the correct trigger. The fixtures are in CI and the docs are written.

Activity

  1. added
    enhancement
    help wanted
    difficulty: medium
    on Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    difficulty: mediumenhancementhelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions