Skip to content

alirezarezvani/claude-code-skill-factory / generated-skills/hook-factory

hook-factory

Flagged

Generate production-ready Claude Code hooks with interactive Q&A, automated installation, and enhanced validation. Supports 10 templates across 7 event types for comprehensive workflow automation.

examples/test-runner/README.md

View on GitHub
# test-runner

## Overview
Automatically run tests after agent completes work

**Event Type:** `SubagentStop`
**Complexity:** intermediate
**Language:** python

## How It Works
Triggers once when agent finishes its task

1. Claude Code detects the configured event
2. Hook matcher checks if conditions are met
3. Hook command executes with safety wrappers
4. Result is processed (silent failure on errors)

## Use Cases
- Run unit tests after code changes
- Run integration tests
- Quality gate before continuing

## Prerequisites
- Python 3.6+
- pytest (pip install pytest)

## Installation

### Manual Installation

1. Open your Claude Code settings file:
   - **Project-level:** `.claude/settings.json`
   - **User-level:** `~/.claude/settings.json`

2. Add this hook configuration to the `hooks` array:

```json
{
  "hooks": {
    "SubagentStop": [
      {
        "matcher": {},
        "hooks": [
          {
            "type": "command",
            "command": "# Detect test framework and run tests\nif ! command -v pytest &> /dev/null; then\n    exit 0\nfi\n\n# Run the appropriate test command\npytest -v || exit 0",
            "timeout": 120
          }
        ]
      }
    ]
  }
}
```

3. Save the file and restart Claude Code.

## Configuration

### Customize Behavior
You can modify the hook by editing `hook.json`:

**Available Customizations:**

**TEST_FRAMEWORK:** Testing framework to use
- Options: python, javascript, typescript, rust, go

**TEST_DETECTION_LOGIC:** Logic to detect which test framework to use

**TEST_COMMAND:** Command to run tests

## Safety Notes
Can be slower (tests take time). Runs once per agent completion.

**Safety Features:**
- ✅ Tool detection prevents errors if dependencies missing
- ✅ Silent failure mode (`|| exit 0`) never interrupts workflow
- ✅ Appropriate timeout settings
- ✅ No destructive operations

## Troubleshooting

### Hook Not Triggering
1. Check that the event type matches your use case
2. Verify file patterns in matcher (if applicable)
3. Check Claude Code logs: `~/.claude/logs/`

### Command Errors
1. Verify required tools are installed
2. Test command manually in terminal
3. Check timeout settings

## Advanced

### Combining with Other Hooks
You can combine this hook with others by adding them to the same event type array.

### Custom Modifications
- Customize command parameters
- Add conditional logic
- Combine with other tools

---
**Generated by hook-factory** | 2025-10-30
**Template:** subagent_stop_test_runner
**Version:** 1.0
reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.Stars: 471kUpdated Claude CodeCodexVerifiedInstall
diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.Stars: 322kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 322kUpdated Claude CodeCodexVerifiedInstall
executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is availableStars: 322kUpdated Claude CodeCodexVerifiedInstall