agentleFS
VersoXBTVersoXBT/claude-initial-setup/skills/hooks/automation-triggers/SKILL.md

automation-triggers

Skill4 starsChanged 9 months agoMITView on GitHub

Patterns for auto-format on save, auto-lint, auto-test on file change, and CI triggers within Claude Code. Use when the user wants automated reactions to file changes, wants to set up continuous feedback loops, or asks about triggering actions automatically.

  • Commits and pushes

The file

We split this skill into the rules it gives an agent

8 rules. About 0 are common, 7 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈7

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use a PostToolUse hook to format files immediately after modification:

    line 24
  2. Distinctive:

    Run linters as PostToolUse hooks to surface issues immediately:

    line 62
  3. Distinctive:

    Run related tests when source files change.

    line 86
  4. Distinctive:

    Use Stop hooks or git push PreToolUse hooks to integrate with CI:

    line 108
  5. Very specific:

    Ignoring exit codes: When chaining commands with &&, a failure in formatting stops linting.

    line 140
  6. Distinctive:

    Auto-testing without test isolation: If tests modify shared state (database, filesystem), auto-running them in hooks can corrupt the …

    line 142
  7. Distinctive:

    Rule of thumb: If a hook takes > 5 seconds, it should be opt-in, not automatic.

    line 154
  8. Distinctive:

    Scope narrowly: Always filter by file extension and limit output.

    line 155

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Automation Triggers

Automation triggers create feedback loops that run formatting, linting, testing, or CI actions in response to file changes. They reduce manual intervention and catch issues immediately.

When to Use

  • User wants files auto-formatted after every edit
  • User asks about auto-linting or auto-testing on save
  • User needs continuous feedback during development
  • User wants to trigger CI checks or deploy previews automatically
  • User mentions "run X every time I change Y"

Core Patterns

Auto-Format on Edit

Use a PostToolUse hook to format files immediately after modification:

{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Edit|Write",
        "command": "if echo \"$CLAUDE_FILE_PATH\" | grep -qE '\\.(js|ts|jsx|tsx|css|json)$'; then npx prettier --write \"$CLAUDE_FILE_PATH\" 2>/dev/null; fi",
        "description": "Auto-format JS/TS/CSS/JSON files with Prettier"
      }
    ]
  }
}

For Python projects, use Black or Ruff:

{
  "matcher": "Edit|Write",
  "command": "if echo \"$CLAUDE_FILE_PATH\" | grep -qE '\\.py$'; then ruff format \"$CLAUDE_FILE_PATH\" 2>/dev/null && ruff check --fix \"$CLAUDE_FILE_PATH\" 2>/dev/null; fi",
  "description": "Auto-format and fix Python files with Ruff"
}

For Go projects:

{
  "matcher": "Edit|Write",
  "command": "if echo \"$CLAUDE_FILE_PATH\" | grep -qE '\\.go$'; then gofmt -w \"$CLAUDE_FILE_PATH\" && goimports -w \"$CLAUDE_FILE_PATH\" 2>/dev/null; fi",
  "description": "Auto-format Go files with gofmt and goimports"
}

Auto-Lint After Edit

Run linters as PostToolUse hooks to surface issues immediately:

{
  "matcher": "Edit|Write",
  "command": "if echo \"$CLAUDE_FILE_PATH\" | grep -qE '\\.(ts|tsx)$'; then npx eslint --no-warn-ignored \"$CLAUDE_FILE_PATH\" 2>&1 | head -30; fi",
  "description": "Auto-lint TypeScript files with ESLint"
}

Auto Type-Check

For TypeScript, run incremental type-checking after edits:

{
  "matcher": "Edit|Write",
  "command": "if echo \"$CLAUDE_FILE_PATH\" | grep -qE '\\.tsx?$'; then npx tsc --noEmit --pretty 2>&1 | tail -20; fi",
  "description": "Type-check TypeScript after edit"
}

Auto-Test on File Change

Run related tests when source files change. Keep the test scope narrow for speed:

{
  "matcher": "Edit|Write",
  "command": "if echo \"$CLAUDE_FILE_PATH\" | grep -qE '\\.(ts|tsx)$'; then TEST_FILE=$(echo \"$CLAUDE_FILE_PATH\" | sed 's/\\.ts/.test.ts/' | sed 's/\\.tsx/.test.tsx/'); if [ -f \"$TEST_FILE\" ]; then npx vitest run \"$TEST_FILE\" --reporter=verbose 2>&1 | tail -30; fi; fi",
  "description": "Run matching test file when source is edited"
}

For pytest:

{
  "matcher": "Edit|Write",
  "command": "if echo \"$CLAUDE_FILE_PATH\" | grep -qE '\\.py$'; then TEST_FILE=$(echo \"$CLAUDE_FILE_PATH\" | sed 's|/\\([^/]*\\)\\.py$|/test_\\1.py|'); if [ -f \"$TEST_FILE\" ]; then python -m pytest \"$TEST_FILE\" -x --tb=short 2>&1 | tail -20; fi; fi",
  "description": "Run matching pytest file when Python source is edited"
}

CI Trigger Patterns

Use Stop hooks or git push PreToolUse hooks to integrate with CI:

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "command": "if echo \"$CLAUDE_TOOL_INPUT\" | grep -q 'git push'; then echo 'Reminder: CI will run on push. Ensure tests pass locally first.'; fi",
        "description": "Remind about CI before git push"
      }
    ]
  }
}

Chaining Multiple Triggers

Combine format + lint + type-check in a single hook with early exit on failure:

{
  "matcher": "Edit|Write",
  "command": "if echo \"$CLAUDE_FILE_PATH\" | grep -qE '\\.tsx?$'; then npx prettier --write \"$CLAUDE_FILE_PATH\" 2>/dev/null && npx eslint --fix \"$CLAUDE_FILE_PATH\" 2>/dev/null && npx tsc --noEmit --pretty 2>&1 | tail -10; fi",
  "description": "Format, lint, and type-check TypeScript files"
}

Anti-Patterns

  • Running full test suites on every edit: This is too slow. Only run the specific test file related to the changed source file. Full suites belong in CI or explicit user commands.
  • Formatting files you did not change: Scope hooks to $CLAUDE_FILE_PATH only. Never run prettier --write . in a hook — it reformats the entire project on every edit.
  • Ignoring exit codes: When chaining commands with &&, a failure in formatting stops linting. Use ; instead of && if you want all steps to run regardless.
  • No output truncation: Linter output can be huge. Always pipe through head or tail to limit output and prevent flooding the agent context.
  • Auto-testing without test isolation: If tests modify shared state (database, filesystem), auto-running them in hooks can corrupt the development environment.

Quick Reference

TriggerTool MatcherWhenSpeed Target
FormatEdit|WritePostToolUse< 1s
LintEdit|WritePostToolUse< 3s
Type-checkEdit|WritePostToolUse< 5s
Test (single)Edit|WritePostToolUse< 10s
CI reminderBash (git push)PreToolUseinstant

Rule of thumb: If a hook takes > 5 seconds, it should be opt-in, not automatic. Scope narrowly: Always filter by file extension and limit output.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.