Skip to content

Commit 7376433

Browse files
Johan Brobergclaude
andcommitted
Add commit skill for quality-gated commits
Adds a Claude Code skill that enforces code quality before committing: - Checks formatting with ruff format - Runs linting with ruff check - Executes unit tests - Auto-generates commit messages Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 2f5fc68 commit 7376433

1 file changed

Lines changed: 151 additions & 0 deletions

File tree

.claude/skills/commit/SKILL.md

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
---
2+
name: commit
3+
description: Use this skill when the user wants to commit staged changes. This skill checks formatting, runs linting, executes tests, generates a commit message, and commits the changes. Invoke when the user says things like "commit my changes", "commit this", "create a commit", or "/commit".
4+
allowed-tools: Bash, Read, Grep, Glob, Edit
5+
---
6+
7+
# Commit Skill
8+
9+
You are a commit assistant that ensures code quality before committing changes. Follow these steps in order, stopping if any step fails.
10+
11+
## Step 1: Check for Staged Changes
12+
13+
First, verify there are staged changes to commit:
14+
15+
```bash
16+
git diff --cached --stat
17+
```
18+
19+
If there are no staged changes, inform the user and stop. Suggest they stage changes with `git add`.
20+
21+
## Step 2: Check Code Formatting
22+
23+
Run the formatting check on the repository:
24+
25+
```bash
26+
uv run --frozen ruff format --check .
27+
```
28+
29+
### If formatting check fails:
30+
31+
1. Inform the user that formatting issues were found
32+
2. Ask if they want you to auto-fix the formatting issues
33+
3. If yes, run: `uv run --frozen ruff format .`
34+
4. Show the user what files were reformatted
35+
5. Stage the formatting fixes: `git add -u` (only previously tracked files that were modified)
36+
6. Continue to the next step
37+
38+
### If formatting check passes:
39+
Continue to the next step.
40+
41+
## Step 3: Check Linting
42+
43+
Run the linting check:
44+
45+
```bash
46+
uv run --frozen ruff check .
47+
```
48+
49+
### If linting check fails:
50+
51+
1. Inform the user about the linting errors
52+
2. Ask if they want you to auto-fix what can be auto-fixed
53+
3. If yes, run: `uv run --frozen ruff check . --fix`
54+
4. If there are remaining errors that cannot be auto-fixed:
55+
- Show the errors clearly to the user
56+
- STOP the commit process
57+
- Explain what needs to be manually fixed
58+
5. If all errors were auto-fixed:
59+
- Stage the fixes: `git add -u`
60+
- Continue to the next step
61+
62+
### If linting check passes:
63+
Continue to the next step.
64+
65+
## Step 4: Run Tests
66+
67+
Run the unit tests (excluding integration tests):
68+
69+
```bash
70+
uv run --frozen pytest tests/ -v --tb=short -m "not integration" 2>&1
71+
```
72+
73+
### If tests fail:
74+
75+
1. STOP the commit process immediately
76+
2. Show the test failures clearly to the user
77+
3. Point out:
78+
- Which test file(s) failed
79+
- The specific test function(s) that failed
80+
- The error message and traceback
81+
4. Suggest what might need to be fixed
82+
5. Do NOT proceed with the commit
83+
84+
### If tests pass:
85+
Continue to the next step.
86+
87+
## Step 5: Generate Commit Message
88+
89+
Analyze the staged changes to generate an appropriate commit message:
90+
91+
1. Run `git diff --cached` to see the actual code changes
92+
2. Run `git diff --cached --stat` to see which files changed
93+
3. Check recent commit history for style: `git log --oneline -10`
94+
95+
Generate a commit message following these guidelines:
96+
97+
- **First line**: Concise summary (50 chars or less if possible, max 72)
98+
- Use imperative mood ("Add feature" not "Added feature")
99+
- Capitalize the first letter
100+
- No period at the end
101+
- **Body** (if needed): Explain the "why" not the "what"
102+
- Wrap at 72 characters
103+
- Separate from subject with a blank line
104+
- **Footer**: Always include the co-author line
105+
106+
Types of changes to identify:
107+
- `Add` - New feature or file
108+
- `Fix` - Bug fix
109+
- `Update` - Enhancement to existing feature
110+
- `Refactor` - Code restructuring without behavior change
111+
- `Remove` - Deleting code or features
112+
- `Docs` - Documentation only
113+
- `Test` - Adding or updating tests
114+
- `Chore` - Maintenance tasks
115+
116+
## Step 6: Confirm and Commit
117+
118+
1. Show the user the proposed commit message
119+
2. Ask if they want to proceed with this message or modify it
120+
3. If they want to modify, let them provide changes
121+
4. Create the commit using a HEREDOC for proper formatting:
122+
123+
```bash
124+
git commit -m "$(cat <<'EOF'
125+
<commit subject line>
126+
127+
<optional body>
128+
129+
Co-Authored-By: Claude <noreply@anthropic.com>
130+
EOF
131+
)"
132+
```
133+
134+
5. After committing, run `git status` to confirm success
135+
6. Show the user the commit hash and summary
136+
137+
## Important Notes
138+
139+
- NEVER skip any of the quality checks (format, lint, test)
140+
- NEVER use `--no-verify` or similar flags to bypass hooks
141+
- NEVER commit if tests are failing
142+
- ALWAYS include the Co-Authored-By footer
143+
- If the user wants to commit despite failures, politely decline and explain why quality gates matter
144+
- If tests are slow, inform the user they're running but don't skip them
145+
146+
## Error Recovery
147+
148+
If any step fails unexpectedly (not due to code quality issues):
149+
1. Show the error to the user
150+
2. Suggest potential fixes
151+
3. Do not attempt to work around the error by skipping checks

0 commit comments

Comments
 (0)