@smartsoft001/claude-plugins 2.108.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +14 -0
- package/README.md +8 -0
- package/package.json +13 -0
- package/plugins/smart/.claude-plugin/plugin.json +5 -0
- package/plugins/smart/hooks/CONFIG.md +228 -0
- package/plugins/smart/hooks/README.md +139 -0
- package/plugins/smart/hooks/audit_logger.py +107 -0
- package/plugins/smart/hooks/safety_validator.py +129 -0
- package/plugins/smart/hooks/skill_validator.py +220 -0
- package/src/index.d.ts +6 -0
- package/src/index.js +10 -0
- package/src/index.js.map +1 -0
package/README.md
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@smartsoft001/claude-plugins",
|
|
3
|
+
"version": "2.108.0",
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public"
|
|
6
|
+
},
|
|
7
|
+
"scripts": {
|
|
8
|
+
"postinstall": "claude plugin update smart@smartsoft --scope project || true"
|
|
9
|
+
},
|
|
10
|
+
"types": "./src/index.d.ts",
|
|
11
|
+
"main": "./src/index.js",
|
|
12
|
+
"type": "commonjs"
|
|
13
|
+
}
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
# Hooks Configuration Guide
|
|
2
|
+
|
|
3
|
+
This guide explains how to configure and customize the hooks system.
|
|
4
|
+
|
|
5
|
+
## Current Configuration
|
|
6
|
+
|
|
7
|
+
The hooks are configured in `.claude/settings.json`:
|
|
8
|
+
|
|
9
|
+
```json
|
|
10
|
+
{
|
|
11
|
+
"hooks": {
|
|
12
|
+
"PreToolUse": [
|
|
13
|
+
{
|
|
14
|
+
"_description": "Safety gate: blocks destructive bash commands",
|
|
15
|
+
"matcher": "Bash|Write|Edit",
|
|
16
|
+
"hooks": [
|
|
17
|
+
{
|
|
18
|
+
"type": "command",
|
|
19
|
+
"command": "node_modules/@smartsoft001/claude-plugins/plugins/smart/hooks/safety_validator.py"
|
|
20
|
+
}
|
|
21
|
+
]
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"_description": "Block sensitive files with detailed error message",
|
|
25
|
+
"matcher": "Read|Edit|Write",
|
|
26
|
+
"hooks": [
|
|
27
|
+
{
|
|
28
|
+
"type": "command",
|
|
29
|
+
"command": "FILE=$(jq -r '.tool_input.file_path // empty'); echo \"$FILE\" | grep -qE '(\\.env|secrets|credentials)' && { echo \"BLOCKED: Access denied to sensitive file: $FILE\" >&2; exit 2; } || exit 0"
|
|
30
|
+
}
|
|
31
|
+
]
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"_description": "Audit trail: logs all PreToolUse events",
|
|
35
|
+
"matcher": "",
|
|
36
|
+
"hooks": [
|
|
37
|
+
{
|
|
38
|
+
"type": "command",
|
|
39
|
+
"command": "node_modules/@smartsoft001/claude-plugins/plugins/smart/hooks/audit_logger.py"
|
|
40
|
+
}
|
|
41
|
+
]
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"_description": "Skill validator: soft enforcement warnings for skill files",
|
|
45
|
+
"matcher": "Write|Edit",
|
|
46
|
+
"hooks": [
|
|
47
|
+
{
|
|
48
|
+
"type": "command",
|
|
49
|
+
"command": "node_modules/@smartsoft001/claude-plugins/plugins/smart/hooks/skill_validator.py"
|
|
50
|
+
}
|
|
51
|
+
]
|
|
52
|
+
}
|
|
53
|
+
],
|
|
54
|
+
"PostToolUse": [
|
|
55
|
+
{
|
|
56
|
+
"_description": "Auto-format files after Write/Edit",
|
|
57
|
+
"matcher": "Write|Edit",
|
|
58
|
+
"hooks": [
|
|
59
|
+
{
|
|
60
|
+
"type": "command",
|
|
61
|
+
"command": "source ~/.nvm/nvm.sh && nvm use 24 && npm run format"
|
|
62
|
+
}
|
|
63
|
+
]
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"_description": "Audit trail: logs all PostToolUse events",
|
|
67
|
+
"matcher": "",
|
|
68
|
+
"hooks": [
|
|
69
|
+
{
|
|
70
|
+
"type": "command",
|
|
71
|
+
"command": "node_modules/@smartsoft001/claude-plugins/plugins/smart/hooks/audit_logger.py"
|
|
72
|
+
}
|
|
73
|
+
]
|
|
74
|
+
}
|
|
75
|
+
],
|
|
76
|
+
"UserPromptSubmit": [
|
|
77
|
+
{
|
|
78
|
+
"_description": "Audit trail: logs all user prompt submissions",
|
|
79
|
+
"hooks": [
|
|
80
|
+
{
|
|
81
|
+
"type": "command",
|
|
82
|
+
"command": "node_modules/@smartsoft001/claude-plugins/plugins/smart/hooks/audit_logger.py"
|
|
83
|
+
}
|
|
84
|
+
]
|
|
85
|
+
}
|
|
86
|
+
]
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
## Hook Customization
|
|
94
|
+
|
|
95
|
+
### safety_validator.py
|
|
96
|
+
|
|
97
|
+
**Add blocked patterns** by editing the script:
|
|
98
|
+
|
|
99
|
+
```python
|
|
100
|
+
DANGEROUS_PATTERNS = [
|
|
101
|
+
r"rm\s+-rf\s+/",
|
|
102
|
+
r"rm\s+-rf\s+~",
|
|
103
|
+
# Add your patterns here
|
|
104
|
+
]
|
|
105
|
+
|
|
106
|
+
SENSITIVE_FILES = [
|
|
107
|
+
".env",
|
|
108
|
+
"id_rsa",
|
|
109
|
+
# Add your patterns here
|
|
110
|
+
]
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
### audit_logger.py
|
|
116
|
+
|
|
117
|
+
**Change log location:**
|
|
118
|
+
|
|
119
|
+
```python
|
|
120
|
+
# Default: .claude/audit_logs/YYYYMMDD_audit.jsonl
|
|
121
|
+
LOG_DIR = Path(__file__).parent.parent / "audit_logs"
|
|
122
|
+
|
|
123
|
+
# Custom location:
|
|
124
|
+
LOG_DIR = Path("/var/log/claude-audit")
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
## Environment Variables
|
|
130
|
+
|
|
131
|
+
| Variable | Purpose | Default |
|
|
132
|
+
| -------------------- | ---------------------- | ------------- |
|
|
133
|
+
| `CLAUDE_PROJECT_DIR` | Project root directory | Auto-detected |
|
|
134
|
+
| `SKIP_AUDIT_LOG` | Disable audit logging | Not set |
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
## Hook Execution Order
|
|
139
|
+
|
|
140
|
+
Hooks run in the order specified in `settings.json`:
|
|
141
|
+
|
|
142
|
+
**PreToolUse order:**
|
|
143
|
+
|
|
144
|
+
1. safety_validator.py (can block)
|
|
145
|
+
2. sensitive file blocker (can block)
|
|
146
|
+
3. audit_logger.py (logs)
|
|
147
|
+
4. skill-validator.py (warns)
|
|
148
|
+
|
|
149
|
+
**PostToolUse order:**
|
|
150
|
+
|
|
151
|
+
1. auto-format.sh (formats)
|
|
152
|
+
2. audit_logger.py (logs)
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
## Selective Hook Enabling
|
|
157
|
+
|
|
158
|
+
### Safety Only (No Formatting)
|
|
159
|
+
|
|
160
|
+
```json
|
|
161
|
+
{
|
|
162
|
+
"hooks": {
|
|
163
|
+
"PreToolUse": [
|
|
164
|
+
{
|
|
165
|
+
"_description": "Safety gate",
|
|
166
|
+
"matcher": "Bash|Write|Edit",
|
|
167
|
+
"hooks": [
|
|
168
|
+
{
|
|
169
|
+
"type": "command",
|
|
170
|
+
"command": ".claude/hooks/safety_validator.py"
|
|
171
|
+
}
|
|
172
|
+
]
|
|
173
|
+
}
|
|
174
|
+
]
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
---
|
|
180
|
+
|
|
181
|
+
## Adding New Hooks
|
|
182
|
+
|
|
183
|
+
### Python Hook Template
|
|
184
|
+
|
|
185
|
+
```python
|
|
186
|
+
#!/usr/bin/env python3
|
|
187
|
+
"""My custom hook."""
|
|
188
|
+
|
|
189
|
+
import json
|
|
190
|
+
import sys
|
|
191
|
+
|
|
192
|
+
def main() -> None:
|
|
193
|
+
try:
|
|
194
|
+
data = json.load(sys.stdin)
|
|
195
|
+
except json.JSONDecodeError:
|
|
196
|
+
sys.exit(0)
|
|
197
|
+
|
|
198
|
+
# Your logic here
|
|
199
|
+
tool_name = data.get("tool_name", "")
|
|
200
|
+
tool_input = data.get("tool_input", {})
|
|
201
|
+
|
|
202
|
+
# Exit 0 = allow, Exit 2 = block
|
|
203
|
+
sys.exit(0)
|
|
204
|
+
|
|
205
|
+
if __name__ == "__main__":
|
|
206
|
+
main()
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### Shell Hook Template
|
|
210
|
+
|
|
211
|
+
```bash
|
|
212
|
+
#!/bin/bash
|
|
213
|
+
set -e
|
|
214
|
+
|
|
215
|
+
# Read JSON input
|
|
216
|
+
INPUT=$(cat)
|
|
217
|
+
|
|
218
|
+
# Parse with jq
|
|
219
|
+
TOOL_NAME=$(echo "$INPUT" | jq -r '.tool_name // empty')
|
|
220
|
+
FILE_PATH=$(echo "$INPUT" | jq -r '.tool_input.file_path // empty')
|
|
221
|
+
|
|
222
|
+
# Your logic here
|
|
223
|
+
|
|
224
|
+
# Exit 0 = allow, Exit 2 = block
|
|
225
|
+
exit 0
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
---
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
# Hooks
|
|
2
|
+
|
|
3
|
+
Claude Code hooks for skill activation, safety validation, formatting, and audit logging.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## What Are Hooks?
|
|
8
|
+
|
|
9
|
+
Hooks are scripts that run at specific points in Claude's workflow:
|
|
10
|
+
- **UserPromptSubmit**: When user submits a prompt
|
|
11
|
+
- **PreToolUse**: Before a tool executes
|
|
12
|
+
- **PostToolUse**: After a tool completes
|
|
13
|
+
- **Stop**: When Claude stops responding
|
|
14
|
+
|
|
15
|
+
**Key insight:** Hooks can modify prompts, block actions, and track state.
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## Current Hooks
|
|
20
|
+
|
|
21
|
+
| Hook | Event | Purpose |
|
|
22
|
+
|------|-------|---------|
|
|
23
|
+
| `skill-suggester.py` | UserPromptSubmit | Suggests relevant skills based on prompt |
|
|
24
|
+
| `safety_validator.py` | PreToolUse | Blocks destructive commands |
|
|
25
|
+
| `skill-validator.py` | PreToolUse | Validates skill file structure |
|
|
26
|
+
| `auto-format.sh` | PostToolUse | Auto-formats Python/JS/TS files |
|
|
27
|
+
| `audit_logger.py` | All events | Logs all actions for audit trail |
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## Hook Details
|
|
32
|
+
|
|
33
|
+
### skill-suggester.py (UserPromptSubmit)
|
|
34
|
+
|
|
35
|
+
**Purpose:** Automatically suggests relevant skills based on user prompts and file context.
|
|
36
|
+
|
|
37
|
+
**How it works:**
|
|
38
|
+
1. Reads `.claude/skills/skill-rules.json`
|
|
39
|
+
2. Matches prompt against keywords and intent patterns
|
|
40
|
+
3. Matches file paths against path patterns
|
|
41
|
+
4. Groups matches by priority (critical, high, medium, low)
|
|
42
|
+
5. Outputs all matching skills in a visual block
|
|
43
|
+
|
|
44
|
+
**Output example:**
|
|
45
|
+
```
|
|
46
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
47
|
+
SKILL ACTIVATION CHECK
|
|
48
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
49
|
+
|
|
50
|
+
>> RECOMMENDED SKILLS:
|
|
51
|
+
-> /python-dev (keyword: python)
|
|
52
|
+
|
|
53
|
+
ACTION: Use slash command to activate skill
|
|
54
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
### safety_validator.py (PreToolUse)
|
|
60
|
+
|
|
61
|
+
**Purpose:** Blocks destructive bash commands and sensitive file modifications.
|
|
62
|
+
|
|
63
|
+
**Blocks:**
|
|
64
|
+
- `rm -rf /`, `rm -rf ~`, `rm -rf *`
|
|
65
|
+
- Modifications to `.env`, `id_rsa`, `credentials` files
|
|
66
|
+
- Other dangerous patterns
|
|
67
|
+
|
|
68
|
+
**Exit codes:**
|
|
69
|
+
- `0` - Allow
|
|
70
|
+
- `2` - Block with message
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
### skill-validator.py (PreToolUse)
|
|
75
|
+
|
|
76
|
+
**Purpose:** Validates skill files follow correct structure.
|
|
77
|
+
|
|
78
|
+
**Checks:**
|
|
79
|
+
- YAML frontmatter (name, description)
|
|
80
|
+
- Required sections (Purpose, When to Use)
|
|
81
|
+
- File length limits
|
|
82
|
+
- Resource file references
|
|
83
|
+
|
|
84
|
+
**Enforcement:** Soft (warns but doesn't block)
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
### auto-format.sh (PostToolUse)
|
|
89
|
+
|
|
90
|
+
**Purpose:** Auto-formats files after Write/Edit operations.
|
|
91
|
+
|
|
92
|
+
**Formatters:**
|
|
93
|
+
- Python: `ruff format`
|
|
94
|
+
- JS/TS: `prettier` (if available)
|
|
95
|
+
|
|
96
|
+
**Runs on:** Files matching `*.py`, `*.js`, `*.ts`, `*.tsx`
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
### audit_logger.py (All Events)
|
|
101
|
+
|
|
102
|
+
**Purpose:** Logs all Claude actions for audit trail.
|
|
103
|
+
|
|
104
|
+
**Log location:** `.claude/audit_logs/YYYYMMDD_audit.jsonl`
|
|
105
|
+
|
|
106
|
+
**Logged events:**
|
|
107
|
+
- PreToolUse (tool name, inputs)
|
|
108
|
+
- PostToolUse (tool name, success/failure)
|
|
109
|
+
- UserPromptSubmit (prompt text)
|
|
110
|
+
- Stop (session end)
|
|
111
|
+
|
|
112
|
+
---
|
|
113
|
+
|
|
114
|
+
## Configuration
|
|
115
|
+
|
|
116
|
+
All hooks are configured in `.claude/settings.json`. See [CONFIG.md](./CONFIG.md) for customization options.
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
## Adding New Hooks
|
|
121
|
+
|
|
122
|
+
1. Create script in `.claude/hooks/`
|
|
123
|
+
2. Make executable: `chmod +x script.py`
|
|
124
|
+
3. Add to `.claude/settings.json` under appropriate event
|
|
125
|
+
4. Include `_description` for documentation
|
|
126
|
+
|
|
127
|
+
Example:
|
|
128
|
+
```json
|
|
129
|
+
{
|
|
130
|
+
"_description": "My custom hook: does something useful",
|
|
131
|
+
"matcher": "Write|Edit",
|
|
132
|
+
"hooks": [
|
|
133
|
+
{
|
|
134
|
+
"type": "command",
|
|
135
|
+
"command": ".claude/hooks/my-hook.py"
|
|
136
|
+
}
|
|
137
|
+
]
|
|
138
|
+
}
|
|
139
|
+
```
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
Claude Code Audit Logger
|
|
4
|
+
|
|
5
|
+
Comprehensive audit trail for all Claude Code hook events.
|
|
6
|
+
Logs are stored in JSONL format with ISO timestamps for easy parsing and sorting.
|
|
7
|
+
|
|
8
|
+
Features:
|
|
9
|
+
- Daily log rotation with yyyymmdd_audit.jsonl naming format
|
|
10
|
+
- ISO 8601 timestamps (UTC) for consistent sorting
|
|
11
|
+
- Automatic cleanup of logs older than 90 days
|
|
12
|
+
- Captures all hook events: PreToolUse, PostToolUse, Stop, UserPromptSubmit
|
|
13
|
+
|
|
14
|
+
Log location: .claude/audit_logs/ (local to repository)
|
|
15
|
+
Log format: JSONL (one JSON object per line)
|
|
16
|
+
|
|
17
|
+
Each log entry contains:
|
|
18
|
+
- timestamp: ISO 8601 UTC timestamp
|
|
19
|
+
- event_type: The Claude hook event type
|
|
20
|
+
- session_id: Unique session identifier
|
|
21
|
+
- event_data: Full event payload from stdin
|
|
22
|
+
|
|
23
|
+
Usage:
|
|
24
|
+
Configure in .claude/settings.json hooks section
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
import json
|
|
28
|
+
import os
|
|
29
|
+
import sys
|
|
30
|
+
import time
|
|
31
|
+
from datetime import datetime, timezone
|
|
32
|
+
from pathlib import Path
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def get_log_directory() -> Path:
|
|
36
|
+
"""Get or create the audit logs directory in the local .claude folder."""
|
|
37
|
+
# Get the directory where this script is located (.claude/hooks/)
|
|
38
|
+
script_dir = Path(__file__).resolve().parent
|
|
39
|
+
# Go up to .claude/ and then into audit_logs/
|
|
40
|
+
log_dir = script_dir.parent / "audit_logs"
|
|
41
|
+
log_dir.mkdir(parents=True, exist_ok=True)
|
|
42
|
+
return log_dir
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def get_iso_timestamp() -> str:
|
|
46
|
+
"""Get current UTC timestamp in ISO 8601 format."""
|
|
47
|
+
return datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%S.%f")[:-3] + "Z"
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def get_log_filename() -> str:
|
|
51
|
+
"""Get log filename in yyyymmdd_audit.jsonl format."""
|
|
52
|
+
return datetime.now(timezone.utc).strftime("%Y%m%d") + "_audit.jsonl"
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def parse_event_data() -> dict:
|
|
56
|
+
"""Parse event data from stdin."""
|
|
57
|
+
try:
|
|
58
|
+
return json.load(sys.stdin)
|
|
59
|
+
except json.JSONDecodeError as e:
|
|
60
|
+
return {"parse_error": str(e), "raw_input": "Could not read stdin"}
|
|
61
|
+
except Exception as e:
|
|
62
|
+
return {"error": str(e)}
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def rotate_old_logs(log_dir: Path, retention_days: int = 90) -> None:
|
|
66
|
+
"""Remove log files older than retention period."""
|
|
67
|
+
cutoff_time = time.time() - (retention_days * 24 * 60 * 60)
|
|
68
|
+
|
|
69
|
+
for old_log in log_dir.glob("*_audit.jsonl"):
|
|
70
|
+
try:
|
|
71
|
+
if old_log.stat().st_mtime < cutoff_time:
|
|
72
|
+
old_log.unlink()
|
|
73
|
+
except OSError:
|
|
74
|
+
pass # Ignore errors during cleanup
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def write_audit_entry(log_dir: Path, entry: dict) -> None:
|
|
78
|
+
"""Write audit entry to daily log file."""
|
|
79
|
+
log_file = log_dir / get_log_filename()
|
|
80
|
+
|
|
81
|
+
with open(log_file, "a", encoding="utf-8") as f:
|
|
82
|
+
f.write(json.dumps(entry, ensure_ascii=False, separators=(",", ":")) + "\n")
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def main() -> None:
|
|
86
|
+
"""Main entry point for audit logging."""
|
|
87
|
+
log_dir = get_log_directory()
|
|
88
|
+
|
|
89
|
+
# Build audit entry
|
|
90
|
+
audit_entry = {
|
|
91
|
+
"timestamp": get_iso_timestamp(),
|
|
92
|
+
"event_type": os.environ.get("CLAUDE_HOOK_EVENT", "unknown"),
|
|
93
|
+
"session_id": os.environ.get("CLAUDE_SESSION_ID", "unknown"),
|
|
94
|
+
"event_data": parse_event_data()
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
# Write to log file
|
|
98
|
+
write_audit_entry(log_dir, audit_entry)
|
|
99
|
+
|
|
100
|
+
# Rotate old logs (runs on each call, but fast due to glob)
|
|
101
|
+
rotate_old_logs(log_dir)
|
|
102
|
+
|
|
103
|
+
sys.exit(0)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
if __name__ == "__main__":
|
|
107
|
+
main()
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
Safety Validator Hook for Claude Code
|
|
4
|
+
======================================
|
|
5
|
+
|
|
6
|
+
Purpose:
|
|
7
|
+
Pre-tool-use validation layer that blocks potentially destructive operations
|
|
8
|
+
before they execute. Acts as a safety gate for Bash, Read, Write, and Edit tools.
|
|
9
|
+
|
|
10
|
+
Protected Against:
|
|
11
|
+
- Recursive deletion of root filesystem (rm -rf /)
|
|
12
|
+
- Recursive deletion of all files (rm -rf *)
|
|
13
|
+
- Recursive deletion of home directory (rm -rf ~)
|
|
14
|
+
- Disk wiping operations (dd if=/dev/zero)
|
|
15
|
+
- Access to environment files (.env, .env.local, .env.production, etc.)
|
|
16
|
+
- Access to secret files (.secret, .secret.local, etc.)
|
|
17
|
+
- Access to SSH private keys (id_rsa, id_ed25519, id_ecdsa)
|
|
18
|
+
- Access to credential files (.pem, credentials)
|
|
19
|
+
- Bash access to sensitive files (cat/head/tail/cp on .env, .secret, keys)
|
|
20
|
+
|
|
21
|
+
Exceptions:
|
|
22
|
+
- Files ending with .example are allowed (safe template files)
|
|
23
|
+
- e.g., .env.example, .secret.example can be read for structure reference
|
|
24
|
+
|
|
25
|
+
Exit Codes:
|
|
26
|
+
0 - Tool use permitted (validation passed)
|
|
27
|
+
2 - Tool use blocked (dangerous operation detected)
|
|
28
|
+
|
|
29
|
+
Integration:
|
|
30
|
+
Configured as PreToolUse hook in .claude/settings.json
|
|
31
|
+
Receives tool call JSON via stdin from Claude Code
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
import json
|
|
35
|
+
import sys
|
|
36
|
+
import re
|
|
37
|
+
|
|
38
|
+
data = json.load(sys.stdin)
|
|
39
|
+
tool_name = data.get("tool_name", "")
|
|
40
|
+
tool_input = data.get("tool_input", {})
|
|
41
|
+
|
|
42
|
+
# Block dangerous bash commands
|
|
43
|
+
if tool_name == "Bash":
|
|
44
|
+
command = tool_input.get("command", "")
|
|
45
|
+
|
|
46
|
+
dangerous_patterns = [
|
|
47
|
+
# rm -rf variations: handles -rf, -r -f, --recursive --force, etc.
|
|
48
|
+
r"rm\s+(-[a-zA-Z]*r[a-zA-Z]*\s+-[a-zA-Z]*f[a-zA-Z]*|-[a-zA-Z]*f[a-zA-Z]*\s+-[a-zA-Z]*r[a-zA-Z]*|-[a-zA-Z]*rf[a-zA-Z]*|-[a-zA-Z]*fr[a-zA-Z]*|--recursive\s+--force|--force\s+--recursive)\s+/\s*$",
|
|
49
|
+
# rm -rf /* or rm -rf *
|
|
50
|
+
r"rm\s+(-[a-zA-Z]*r[a-zA-Z]*\s+-[a-zA-Z]*f[a-zA-Z]*|-[a-zA-Z]*f[a-zA-Z]*\s+-[a-zA-Z]*r[a-zA-Z]*|-[a-zA-Z]*rf[a-zA-Z]*|-[a-zA-Z]*fr[a-zA-Z]*|--recursive\s+--force|--force\s+--recursive)\s+(/\*)?\*",
|
|
51
|
+
# rm -rf ~ (home directory)
|
|
52
|
+
r"rm\s+(-[a-zA-Z]*r[a-zA-Z]*\s+-[a-zA-Z]*f[a-zA-Z]*|-[a-zA-Z]*f[a-zA-Z]*\s+-[a-zA-Z]*r[a-zA-Z]*|-[a-zA-Z]*rf[a-zA-Z]*|-[a-zA-Z]*fr[a-zA-Z]*|--recursive\s+--force|--force\s+--recursive)\s+~",
|
|
53
|
+
# rm -rf $HOME
|
|
54
|
+
r"rm\s+(-[a-zA-Z]*r[a-zA-Z]*\s+-[a-zA-Z]*f[a-zA-Z]*|-[a-zA-Z]*f[a-zA-Z]*\s+-[a-zA-Z]*r[a-zA-Z]*|-[a-zA-Z]*rf[a-zA-Z]*|-[a-zA-Z]*fr[a-zA-Z]*|--recursive\s+--force|--force\s+--recursive)\s+\$HOME",
|
|
55
|
+
# dd disk operations
|
|
56
|
+
r"dd\s+.*if=/dev/(zero|random|urandom).*of=/dev/",
|
|
57
|
+
r"dd\s+.*of=/dev/[a-z]+\s",
|
|
58
|
+
]
|
|
59
|
+
|
|
60
|
+
for pattern in dangerous_patterns:
|
|
61
|
+
if re.search(pattern, command, re.IGNORECASE):
|
|
62
|
+
print("BLOCKED: Dangerous command pattern detected", file=sys.stderr)
|
|
63
|
+
sys.exit(2)
|
|
64
|
+
|
|
65
|
+
# Additional simple checks for common dangerous patterns
|
|
66
|
+
dangerous_simple = [
|
|
67
|
+
("rm -rf /", "recursive delete root"),
|
|
68
|
+
("rm -rf /*", "recursive delete root contents"),
|
|
69
|
+
("rm -rf ~", "recursive delete home"),
|
|
70
|
+
("rm -rf $HOME", "recursive delete home"),
|
|
71
|
+
("> /dev/sda", "overwrite disk"),
|
|
72
|
+
("mkfs.", "format filesystem"),
|
|
73
|
+
(":(){ :|:& };:", "fork bomb"),
|
|
74
|
+
]
|
|
75
|
+
|
|
76
|
+
for pattern, description in dangerous_simple:
|
|
77
|
+
if pattern in command:
|
|
78
|
+
print(f"BLOCKED: {description}", file=sys.stderr)
|
|
79
|
+
sys.exit(2)
|
|
80
|
+
|
|
81
|
+
# Block Bash access to sensitive files (but allow .example files)
|
|
82
|
+
# First check if it's an .example file - those are safe
|
|
83
|
+
if not re.search(r"\.example\b", command, re.IGNORECASE):
|
|
84
|
+
sensitive_file_patterns = [
|
|
85
|
+
r"\bcat\s+.*\.env\b",
|
|
86
|
+
r"\bhead\s+.*\.env\b",
|
|
87
|
+
r"\btail\s+.*\.env\b",
|
|
88
|
+
r"\bcp\s+.*\.env\b",
|
|
89
|
+
r"\bcat\s+.*\.secret",
|
|
90
|
+
r"\bhead\s+.*\.secret",
|
|
91
|
+
r"\btail\s+.*\.secret",
|
|
92
|
+
r"\bcp\s+.*\.secret",
|
|
93
|
+
r"\bcat\s+.*id_rsa",
|
|
94
|
+
r"\bcat\s+.*id_ed25519",
|
|
95
|
+
r"\bcat\s+.*\.pem",
|
|
96
|
+
r"\bcat\s+.*credentials",
|
|
97
|
+
]
|
|
98
|
+
|
|
99
|
+
for pattern in sensitive_file_patterns:
|
|
100
|
+
if re.search(pattern, command, re.IGNORECASE):
|
|
101
|
+
print("BLOCKED: Cannot access sensitive file via Bash", file=sys.stderr)
|
|
102
|
+
sys.exit(2)
|
|
103
|
+
|
|
104
|
+
# Block access to sensitive files
|
|
105
|
+
if tool_name in ["Read", "Write", "Edit"]:
|
|
106
|
+
file_path = tool_input.get("file_path", "")
|
|
107
|
+
|
|
108
|
+
# Allow .example files (they're safe templates without secrets)
|
|
109
|
+
if file_path.endswith(".example"):
|
|
110
|
+
sys.exit(0)
|
|
111
|
+
|
|
112
|
+
sensitive_patterns = [
|
|
113
|
+
".env",
|
|
114
|
+
".secret",
|
|
115
|
+
"id_rsa",
|
|
116
|
+
"id_ed25519",
|
|
117
|
+
"id_ecdsa",
|
|
118
|
+
".pem",
|
|
119
|
+
"credentials",
|
|
120
|
+
]
|
|
121
|
+
|
|
122
|
+
for blocked in sensitive_patterns:
|
|
123
|
+
if blocked in file_path:
|
|
124
|
+
print(
|
|
125
|
+
f"BLOCKED: Cannot modify sensitive file: {file_path}", file=sys.stderr
|
|
126
|
+
)
|
|
127
|
+
sys.exit(2)
|
|
128
|
+
|
|
129
|
+
sys.exit(0)
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
Skill Validator Hook for Claude Code
|
|
4
|
+
=====================================
|
|
5
|
+
|
|
6
|
+
Validates skill-related operations and provides warnings (not blocks).
|
|
7
|
+
Implements soft enforcement per requirements.
|
|
8
|
+
|
|
9
|
+
Exit Codes:
|
|
10
|
+
0 - Always (warnings only, never blocks)
|
|
11
|
+
|
|
12
|
+
Output:
|
|
13
|
+
Warnings to stderr when potential issues detected.
|
|
14
|
+
|
|
15
|
+
Checks:
|
|
16
|
+
- SKILL.md exceeds 500 lines
|
|
17
|
+
- Missing required sections in SKILL.md
|
|
18
|
+
- Invalid frontmatter format
|
|
19
|
+
- skill-rules.json syntax errors
|
|
20
|
+
- Missing trigger configuration
|
|
21
|
+
|
|
22
|
+
Integration:
|
|
23
|
+
Configured as PreToolUse hook in .claude/settings.json
|
|
24
|
+
|
|
25
|
+
Performance Target:
|
|
26
|
+
< 200ms execution time
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
import json
|
|
30
|
+
import re
|
|
31
|
+
import sys
|
|
32
|
+
from typing import Any
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def warn(message: str) -> None:
|
|
36
|
+
"""Output warning to stderr (does not block)."""
|
|
37
|
+
print(f"[Skill Warning] {message}", file=sys.stderr)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def check_skill_file_length(file_path: str, content: str) -> None:
|
|
41
|
+
"""Warn if SKILL.md exceeds 500 lines."""
|
|
42
|
+
if not file_path.endswith("SKILL.md"):
|
|
43
|
+
return
|
|
44
|
+
|
|
45
|
+
line_count = content.count("\n") + 1
|
|
46
|
+
|
|
47
|
+
if line_count > 500:
|
|
48
|
+
warn(
|
|
49
|
+
f"SKILL.md has {line_count} lines (exceeds 500-line guideline). "
|
|
50
|
+
"Consider moving detailed content to resource files."
|
|
51
|
+
)
|
|
52
|
+
elif line_count > 400:
|
|
53
|
+
warn(
|
|
54
|
+
f"SKILL.md has {line_count} lines (approaching 500-line limit). "
|
|
55
|
+
"Plan for resource files if adding more content."
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def check_required_sections(file_path: str, content: str) -> None:
|
|
60
|
+
"""Warn if SKILL.md missing required sections."""
|
|
61
|
+
if not file_path.endswith("SKILL.md"):
|
|
62
|
+
return
|
|
63
|
+
|
|
64
|
+
required_sections = [
|
|
65
|
+
("## Purpose", "Purpose"),
|
|
66
|
+
("## When to Use", "When to Use This Skill"),
|
|
67
|
+
]
|
|
68
|
+
|
|
69
|
+
missing = []
|
|
70
|
+
for marker, name in required_sections:
|
|
71
|
+
if marker not in content:
|
|
72
|
+
missing.append(name)
|
|
73
|
+
|
|
74
|
+
if missing:
|
|
75
|
+
warn(f"SKILL.md missing recommended sections: {', '.join(missing)}")
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def check_frontmatter(file_path: str, content: str) -> None:
|
|
79
|
+
"""Warn if SKILL.md has invalid frontmatter."""
|
|
80
|
+
if not file_path.endswith("SKILL.md"):
|
|
81
|
+
return
|
|
82
|
+
|
|
83
|
+
# Check for frontmatter presence
|
|
84
|
+
if not content.startswith("---"):
|
|
85
|
+
warn("SKILL.md should start with YAML frontmatter (---)")
|
|
86
|
+
return
|
|
87
|
+
|
|
88
|
+
# Check for closing frontmatter
|
|
89
|
+
if content.count("---") < 2:
|
|
90
|
+
warn("SKILL.md frontmatter not properly closed (needs two ---)")
|
|
91
|
+
return
|
|
92
|
+
|
|
93
|
+
# Extract and check frontmatter content
|
|
94
|
+
frontmatter_match = re.search(
|
|
95
|
+
r"^---\s*\n(.*?)\n---",
|
|
96
|
+
content,
|
|
97
|
+
re.DOTALL
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
if frontmatter_match:
|
|
101
|
+
frontmatter = frontmatter_match.group(1)
|
|
102
|
+
|
|
103
|
+
if "name:" not in frontmatter:
|
|
104
|
+
warn("SKILL.md frontmatter missing 'name' field")
|
|
105
|
+
|
|
106
|
+
if "description:" not in frontmatter:
|
|
107
|
+
warn("SKILL.md frontmatter missing 'description' field")
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def check_skill_rules_syntax(file_path: str, content: str) -> None:
|
|
111
|
+
"""Warn if skill-rules.json has syntax or structure issues."""
|
|
112
|
+
if not file_path.endswith("skill-rules.json"):
|
|
113
|
+
return
|
|
114
|
+
|
|
115
|
+
try:
|
|
116
|
+
rules = json.loads(content)
|
|
117
|
+
except json.JSONDecodeError as e:
|
|
118
|
+
warn(f"skill-rules.json has invalid JSON: {e}")
|
|
119
|
+
return
|
|
120
|
+
|
|
121
|
+
if not isinstance(rules, dict):
|
|
122
|
+
warn("skill-rules.json should be an object with skill names as keys")
|
|
123
|
+
return
|
|
124
|
+
|
|
125
|
+
for skill_name, config in rules.items():
|
|
126
|
+
if not isinstance(config, dict):
|
|
127
|
+
warn(f"Skill '{skill_name}' should be an object")
|
|
128
|
+
continue
|
|
129
|
+
|
|
130
|
+
# Check required fields
|
|
131
|
+
if "type" not in config:
|
|
132
|
+
warn(
|
|
133
|
+
f"Skill '{skill_name}' missing 'type' field "
|
|
134
|
+
"(should be 'domain', 'guardrail', or 'workflow')"
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
# Check for triggers
|
|
138
|
+
has_prompt_triggers = bool(config.get("promptTriggers"))
|
|
139
|
+
has_file_triggers = bool(config.get("fileTriggers"))
|
|
140
|
+
|
|
141
|
+
if not has_prompt_triggers and not has_file_triggers:
|
|
142
|
+
warn(
|
|
143
|
+
f"Skill '{skill_name}' has no triggers defined - "
|
|
144
|
+
"will never auto-activate"
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
# Check enforcement for guardrails
|
|
148
|
+
if config.get("type") == "guardrail":
|
|
149
|
+
enforcement = config.get("enforcement")
|
|
150
|
+
if enforcement == "block" and "blockMessage" not in config:
|
|
151
|
+
warn(
|
|
152
|
+
f"Guardrail '{skill_name}' uses 'block' enforcement "
|
|
153
|
+
"but has no 'blockMessage'"
|
|
154
|
+
)
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def check_resource_file_naming(file_path: str, content: str) -> None:
|
|
158
|
+
"""Warn if resource file doesn't follow naming convention."""
|
|
159
|
+
if "/resources/" not in file_path:
|
|
160
|
+
return
|
|
161
|
+
|
|
162
|
+
if not file_path.endswith(".md"):
|
|
163
|
+
return
|
|
164
|
+
|
|
165
|
+
# Get filename without path and extension
|
|
166
|
+
filename = file_path.split("/")[-1]
|
|
167
|
+
name_without_ext = filename.replace(".md", "")
|
|
168
|
+
|
|
169
|
+
# Check if UPPERCASE_SNAKE_CASE
|
|
170
|
+
if not re.match(r"^[A-Z][A-Z0-9_]*$", name_without_ext):
|
|
171
|
+
warn(
|
|
172
|
+
f"Resource file '{filename}' should use UPPERCASE_SNAKE_CASE "
|
|
173
|
+
"(e.g., BEST_PRACTICES.md)"
|
|
174
|
+
)
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
def main() -> None:
|
|
178
|
+
"""Main entry point."""
|
|
179
|
+
try:
|
|
180
|
+
data: dict[str, Any] = json.load(sys.stdin)
|
|
181
|
+
except json.JSONDecodeError:
|
|
182
|
+
sys.exit(0)
|
|
183
|
+
|
|
184
|
+
tool_name = data.get("tool_name", "")
|
|
185
|
+
tool_input = data.get("tool_input", {})
|
|
186
|
+
|
|
187
|
+
# Only validate Write/Edit operations on skill files
|
|
188
|
+
if tool_name not in ["Write", "Edit"]:
|
|
189
|
+
sys.exit(0)
|
|
190
|
+
|
|
191
|
+
file_path = tool_input.get("file_path", "")
|
|
192
|
+
|
|
193
|
+
# Only check files in .claude/skills/
|
|
194
|
+
if ".claude/skills/" not in file_path:
|
|
195
|
+
sys.exit(0)
|
|
196
|
+
|
|
197
|
+
# Get content based on tool type
|
|
198
|
+
if tool_name == "Write":
|
|
199
|
+
content = tool_input.get("content", "")
|
|
200
|
+
else: # Edit
|
|
201
|
+
content = tool_input.get("new_string", "")
|
|
202
|
+
# For Edit, we might not have full file content
|
|
203
|
+
# Run more limited checks
|
|
204
|
+
|
|
205
|
+
if not content:
|
|
206
|
+
sys.exit(0)
|
|
207
|
+
|
|
208
|
+
# Run checks
|
|
209
|
+
check_skill_file_length(file_path, content)
|
|
210
|
+
check_required_sections(file_path, content)
|
|
211
|
+
check_frontmatter(file_path, content)
|
|
212
|
+
check_skill_rules_syntax(file_path, content)
|
|
213
|
+
check_resource_file_naming(file_path, content)
|
|
214
|
+
|
|
215
|
+
# Always exit 0 - warnings only, never block
|
|
216
|
+
sys.exit(0)
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
if __name__ == "__main__":
|
|
220
|
+
main()
|
package/src/index.d.ts
ADDED
package/src/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @smartsoft001-mobilems/claude-plugins
|
|
4
|
+
*
|
|
5
|
+
* This library contains Claude Code plugin configuration files (MD/JSON).
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.CLAUDE_PLUGINS_VERSION = void 0;
|
|
9
|
+
exports.CLAUDE_PLUGINS_VERSION = '1.0.0';
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/shared/claude-plugins/src/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEU,QAAA,sBAAsB,GAAG,OAAO,CAAC"}
|