Create Selective Pre-Commit Hooks for Claude Code
This prompt generates a bash script that triggers specific tests and typechecks only for packages modified in your current git branch.
Agent prompt for Claude
Prompt
mkdir -p .agents/skills/create-selective-pre-commit-hooks-for-claude-code && curl -sL "https://prompts-gpt.com/prompts/create-selective-pre-commit-hooks-for-claude-code/raw" -o .agents/skills/create-selective-pre-commit-hooks-for-claude-code/SKILL.md---
name: create-selective-pre-commit-hooks-for-claude-code
description: "This prompt generates a bash script that triggers specific tests and typechecks only for packages modified in your current git branch."
---
# Create Selective Pre-Commit Hooks for Claude Code
This prompt generates a bash script that triggers specific tests and typechecks only for packages modified in your current git branch.
## Prompt
```
Act as a Senior DevOps Engineer. Write a bash script for a pre-commit hook that uses git diff to identify changed directories and runs specific validation commands only for those paths. Follow these rules: 1. Use git diff --name-only to detect modified files. 2. Map file paths to specific test commands like npm run test or tsc. 3. Exit with status 1 if any command fails. 4. Include a fallback to run a full suite if too many files change. Output format: Provide the bash script block followed by instructions on how to install it in the .git/hooks directory. This is for technical automation and does not replace manual code review. Ask these 3 questions first: 1. What is your primary programming language or build tool? 2. What are the specific test and lint commands for your project? 3. What is the maximum number of files that should trigger a full suite run instead of a selective one?
```
## Usage Notes
Use this to optimize your CI/CD pipeline or local development workflow. Copy the generated script into .git/hooks/pre-commit and ensure it is executable. Works with Claude Code and Claude.
Act as a Senior DevOps Engineer. Write a bash script for a pre-commit hook that uses git diff to identify changed directories and runs specific validation commands only for those paths. Follow these rules: 1. Use git diff --name-only to detect modified files. 2. Map file paths to specific test commands like npm run test or tsc. 3. Exit with status 1 if any command fails. 4. Include a fallback to run a full suite if too many files change. Output format: Provide the bash script block followed by instructions on how to install it in the .git/hooks directory. This is for technical automation and does not replace manual code review. Ask these 3 questions first: 1. What is your primary programming language or build tool? 2. What are the specific test and lint commands for your project? 3. What is the maximum number of files that should trigger a full suite run instead of a selective one?Example output
Tips and common edits
Why this works
- Uses git diff filtering to prevent unnecessary CI/CD overhead.
- Implements a file-count threshold to switch between selective and full testing.
- Maps specific directory patterns to dedicated test commands.
Use this to optimize your CI/CD pipeline or local development workflow. Copy the generated script into .git/hooks/pre-commit and ensure it is executable. Works with Claude Code and Claude.
Common edits
- Adjust the directory paths to match your specific repository structure.
- Modify the test commands if your project uses different build tools like Vitest or Bazel.
Reuse it: Use in a workflowAdapt in the builder
Prompt details
- By
- Prompts-GPT editors
- Published
Did this prompt work?
More like this
Headless Claude Code Script for CI: claude -p Task With Exit Codes and Output Checks
Writes a CI step that runs Claude Code non-interactively with claude -p, scoped tools, a turn limit and JSON output, and fails safely on errors, with a dry-run mode and secrets kept out of the repo.
Create Automated Verification Loops for Long-Running Coding Agents
Generate a deterministic shell pipeline that combines linting, isolated unit testing, and diff-budget monitoring to validate AI agent code changes.
Design a Benchmark Harness for Claude Code Agent Accuracy
Create a structured testing framework to evaluate coding agent performance on pull requests using deterministic ground-truth verification.
Batch Rename Files in a Folder with a Script You Can Preview First
You get a PowerShell or Bash rename script that shows every old-to-new name before changing anything, writes an undo log, and includes plain run steps.
Automated Dependency Upgrade and Rollback Protocol
Generate a safe, step-by-step dependency upgrade plan that includes strict semver validation, lockfile parity checks, and automated rollback triggers.
Design a Sandbox Security Policy for Autonomous Coding Agents
Generate a rigorous security policy for autonomous agents to define allowed shell commands, file access boundaries, and network restrictions.
- Automated Database Migration Safety Review for Claude Code
- Deconstruct Monolithic Pull Requests into Atomic Commit Stacks
- Draft Security Guardrails for AGENTS.md Configuration
- Generate Reproducible Bug Fix Specs for Coding Agents
- Sync Test Factories and Fixtures with Database Migrations
- Port a Function or Module to Another Language With Tests Proving Same Behavior