https://github.com/shuntaka9576/blocc
Execute multiple commands and block Claude Code Hooks by returning exit 2 with stderr on failures 🛡️
https://github.com/shuntaka9576/blocc
claude claudecode hooks
Last synced: 6 months ago
JSON representation
Execute multiple commands and block Claude Code Hooks by returning exit 2 with stderr on failures 🛡️
- Host: GitHub
- URL: https://github.com/shuntaka9576/blocc
- Owner: shuntaka9576
- License: mit
- Created: 2025-07-10T00:49:16.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2025-08-05T05:37:59.000Z (11 months ago)
- Last Synced: 2026-01-13T03:42:40.678Z (6 months ago)
- Topics: claude, claudecode, hooks
- Language: Go
- Homepage:
- Size: 409 KB
- Stars: 11
- Watchers: 0
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# blocc
`blocc` is a CLI tool that executes multiple commands and blocks Claude Code hooks by returning exit code 2 when any command fails.
1. blocc executed from Hooks caught errors from the specified command, consolidated output to stderr, and returned exit code 2 to provide feedback to Claude Code.
2. Claude Code automatically fixed the clippy warnings by updating the println! syntax to the modern format. ✨

## Installation
```bash
brew install shuntaka9576/tap/blocc
```
Go install
```bash
go install github.com/shuntaka9576/blocc/cmd/blocc@latest
```
From source
```bash
git clone https://github.com/shuntaka9576/blocc.git
cd blocc
make install
```
## QuickStart
Initialize Claude Code hooks configuration with blocc.
```bash
# Initialize with interactive setup
$ blocc --init
Include stdout in error output? (y/N): y
Add stdout filter? (y/N): n
Add stderr filter? (y/N): n
Exclude stderr from error output? (y/N): n
Enter commands to run (one per line, empty line to finish):
make lint
make test
Successfully created .claude/settings.local.json
```
This creates `./.claude/settings.local.json`.
> **Note**: It's recommended to configure hooks to trigger on `Stop` events. Using `PostToolUse` hooks may cause the AI model to become distracted or consume extra context unnecessarily.
```json
{
"hooks": {
"Stop": [
{
"matcher": "",
"hooks": [
{
"type": "command",
"command": "blocc --stdout 'make lint' 'make test'"
}
]
}
]
}
}
```
## Usage
```bash
$ blocc --help
Usage: main [ ...] [flags]
Arguments:
[ ...] Commands to execute
Flags:
-h, --help Show context-sensitive help.
-v, --version Show version information
-p, --parallel Execute commands in parallel
-m, --message=STRING Custom error message
-i, --init Initialize settings.local.json
-s, --stdout Include stdout in error output
-o, --stdout-filter=STRING Filter command for stdout
-e, --stderr-filter=STRING Filter command for stderr
-n, --no-stderr Exclude stderr from error output
# Execute commands sequentially (default).
$ blocc "npm run lint" "npm run test"
{
"message": "2 command(s) failed",
"results": [
{
"command": "npm run lint",
"exitCode": 1,
"stderr": "Linting errors found..."
},
{
"command": "npm run test",
"exitCode": 1,
"stderr": "Test failures..."
}
]
}
# Execute commands in parallel(-p).
$ blocc --parallel "npm run lint" "npm run test" "npm run spell-check"
# Custom error message(-m).
$ blocc --message "Hook execution completed with errors. Please address the following issues" "npm run lint" "npm run test"
# Include stdout in error output(-s).
$ blocc --stdout "npm run lint" "npm run test"
# Filter output for context engineering(-o/-e).
$ blocc -n -s "cspell lint . --cache --gitignore" -o "perl -nle 'print \$1 if /Unknown word \((\w+)\)/' | sort | uniq"
{
"message": "1 command(s) failed",
"results": [
{
"command": "cspell lint . --cache --gitignore",
"exitCode": 1,
"stdout": "alecthomas\nBINPATH\nblocc\nBlocc\nclippy\nDISTPATH\ngofmt\ngolangci\nGOPATH\ngoreleaser\ngotextdiff\nhexops\nnonexistentcommand\nnosec\noicd\nprintln\nrepr\nshuntaka\nvxeg\n"
}
]
}
````