home / skills / acking-you / myclaude-skills / gen-commit-msg

gen-commit-msg skill

/skills/gen-commit-msg

This skill generates concise commit messages from conversation context or git diff to reflect changes and intent.

npx playbooks add skill acking-you/myclaude-skills --skill gen-commit-msg

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
7.3 KB
---
name: gen-commit-msg
description: Generate concise commit messages based on conversation context and minimal git inspection.
---

# Generate Commit Message Skill

## Overview

This skill generates concise, meaningful commit messages by:
1. **First priority**: Use conversation context (files edited, changes discussed)
2. **Fallback**: Run `git diff` when context is unavailable
3. Keep messages brief and focused

## When to Use

- After implementing changes discussed in the conversation
- When you want a commit message that reflects the actual work done
- To quickly commit without manual message writing

## Usage

Simply invoke this skill after making changes. The skill will:
1. Check conversation context for what was changed
2. If no context: run `git diff --cached` to analyze changes
3. Generate a concise commit message
4. Prompt for user confirmation before committing

## Commit Message Format

```
<type>: <brief summary (<=50 chars)>

[Optional body: concise explanation of what/why, <=3 lines]

[Optional footer: Breaking changes, issue refs]
```

### Type Prefixes

- `feat`: New feature
- `fix`: Bug fix
- `refactor`: Code restructure without behavior change
- `perf`: Performance improvement
- `docs`: Documentation only
- `style`: Formatting, whitespace
- `test`: Add/update tests
- `chore`: Build, tools, dependencies
- `build`: Build system changes
- `ci`: CI/CD changes

## Implementation Guidelines

### Step 1: Check Conversation Context

**Has context if:**
- Files were edited via Write/Edit tools in this conversation
- User described what was changed
- Features/fixes were discussed

**No context if:**
- User just says "commit my changes" without prior discussion
- Changes were made outside this conversation
- Files were modified manually by user

### Step 2: Get Change Information

**If context available:**
- Use known file edits and changes
- Skip git diff entirely

**If no context:**
```bash
# Get list of changed files with status
git diff --cached --name-status

# Get file-level stats
git diff --cached --stat

# Get actual changes (for understanding what was done)
git diff --cached

# Alternative: if nothing staged, check working directory
git status --short
git diff --stat
git diff
```

### Step 3: Generate Concise Message

Principles:
- **Brevity**: Summary <=50 chars, body <=3 lines
- **What, not how**: Describe the outcome, not implementation
- **Imperative mood**: add, fix, update (not added, fixed)

**Good Examples:**
```
feat: add scroll limit config commands

Add get-scroll-settings and set-scroll-limit commands
to es_tool.sh for managing ES scroll configuration.
```

```
fix: ensure bulk requests end with newline

ES bulk API requires NDJSON format with trailing newline.
```

```
refactor: translate es_tool comments to English
```

**Bad Examples:**
```
feat: implement comprehensive elasticsearch scroll configuration management system

This commit adds a full suite of commands for managing scroll-related
settings in Elasticsearch including viewing current configuration,
modifying document count limits, enabling/disabling rejection behavior...
[TOO VERBOSE]
```

### Step 4: Present and Confirm

```bash
# Show what will be committed
git status --short

# Present message
echo "Proposed commit message:"
echo "----------------------------------------"
echo "<generated_message>"
echo "----------------------------------------"
echo ""
read -p "Commit these changes? (y/n): " response
```

### Step 5: Execute Commit

**CRITICAL**: The commit message MUST be clean and professional. DO NOT include:
- `🤖 Generated with [Claude Code]` markers
- `Co-Authored-By: Claude` attributions
- Any other tool-generated metadata or signatures

These add no value and clutter the commit history.

```bash
# Commit with generated message (NO extra metadata)
git commit -m "$(cat <<'EOF'
<generated_message>
EOF
)"

# Show result
git log -1 --oneline
```

## Decision Flow

```
START
  |
  v
Do we have conversation context about changes?
  |
  +-- YES --> Use context to generate message
  |            (Skip git diff)
  |
  +-- NO --> Run git diff to analyze changes
              |
              v
            Are changes staged?
              |
              +-- YES --> git diff --cached
              |
              +-- NO --> git diff (working directory)
  |
  v
Generate concise commit message
  |
  v
Present to user for confirmation
  |
  v
User confirms?
  |
  +-- YES --> git commit
  |
  +-- NO --> Exit (no commit)
  |
  v
END
```

## Examples

### Example 1: With Context (No Git Diff)

**Conversation:**
```
User: Add health check commands to es_tool.sh
Assistant: [edits es_tool.sh, adds check-health, check-shards, etc.]
User: Create a commit
```

**Skill execution:**
1. Context available: Edited es_tool.sh, added health check commands
2. Skip git diff
3. Generate:
   ```
   feat: add cluster health check commands

   Implements check-health, check-shards, explain-allocation,
   and fix-red-shards for ES cluster diagnostics.
   ```

### Example 2: No Context (Use Git Diff)

**Conversation:**
```
User: Generate commit message
```

**Skill execution:**
1. No context available
2. Run git diff --cached:
   ```diff
   diff --git a/script/es_tool.sh b/script/es_tool.sh
   @@ -841,7 +841,7 @@ execute_http_request() {
   -            content_type="text/plain"
   +            content_type="application/x-ndjson"
   +            # Ensure body ends with newline
   +            if [[ "$body" != *$'\n' ]]; then
   +                body="${body}"$'\n'
   +            fi
   ```
3. Analyze: Changed content-type for bulk requests, added newline
4. Generate:
   ```
   fix: correct bulk request content-type

   Use application/x-ndjson and ensure trailing newline
   for ES bulk API NDJSON format compliance.
   ```

### Example 3: User Provides Context

**Conversation:**
```
User: Commit the fix for the bulk API newline issue
```

**Skill execution:**
1. Context from user: "fix for bulk API newline issue"
2. Quick check: `git diff --cached --name-only` (just filenames)
   ```
   script/es_tool.sh
   ```
3. Generate (minimal diff needed):
   ```
   fix: ensure bulk requests end with newline

   Add trailing newline to bulk request body for
   ES NDJSON format requirements.
   ```

## Best Practices

### DO:
- Use conversation context when available
- Run git diff when context is missing
- Keep summary under 50 characters
- Use imperative mood (add, fix, update)
- Focus on WHAT and WHY
- Confirm with user before committing

### DON'T:
- Skip git diff when you have no context
- Write verbose explanations
- Describe HOW code was implemented
- Auto-commit without confirmation
- Use past tense (added, fixed, updated)

## Git Tags

When user requests creating a tag (for CI/CD pipeline trigger, release, etc.):

1. **Check existing tag format first**:
   ```bash
   git tag --sort=-creatordate | head -5
   ```

2. **Keep format consistent** - DO NOT add 'v' prefix unless project already uses it:
   - If existing: `0.4.0`, `0.3.0` → use `0.4.1` (no 'v')
   - If existing: `v0.4.0`, `v0.3.0` → use `v0.4.1` (with 'v')

3. **Never assume tag format** - always verify from existing tags

## Notes

- Optimizes for speed by using context when available
- Falls back to git diff when needed for accuracy
- Generates concise but informative messages
- Always confirms before committing
- Works in both interactive and standalone scenarios

Overview

This skill generates concise, professional git commit messages using conversation context first and minimal git inspection as a fallback. It prioritizes brevity, imperative mood, and message templates to produce summaries under 50 characters with an optional short body. The skill presents the proposed message and asks for confirmation before committing.

How this skill works

The skill inspects the conversation for recent file edits or explicit descriptions of changes and uses that context to craft a message. If no context is available, it runs lightweight git commands (git diff --cached, git status --short, git diff --stat) to identify staged or unstaged changes and derive an appropriate commit message. It then formats the message with a type prefix, brief summary, optional body, and prompts the user to confirm before running git commit.

When to use it

  • After implementing changes discussed in the conversation
  • When you want a short, accurate commit message without hand-writing it
  • Before committing staged changes to ensure message quality
  • When you need a standard type prefix (feat, fix, docs, etc.)
  • When you want a commit message that reflects the outcome, not implementation details

Best practices

  • Prefer conversation context over running git diff for speed and accuracy
  • Keep the summary <=50 characters and body <=3 lines
  • Use imperative mood and start with a type prefix (feat, fix, refactor, etc.)
  • Describe what changed and why, not the implementation details
  • Always confirm the proposed message before committing

Example use cases

  • User and assistant edited a file in the chat: generate a commit message from that context and commit
  • No prior conversation: run git diff --cached to analyze staged changes and propose a message
  • User says “commit the bulk API newline fix”: generate a focused fix: summary + one-line body and commit after confirmation
  • Quickly produce conventional commit-style messages for documentation, tests, style, or CI changes
  • Suggest tag names consistent with existing tag format when user requests creating a tag

FAQ

What if no files are staged?

The skill will check working directory diffs (git diff, git diff --stat) and present changes; it will not auto-commit without your confirmation.

Can it include issue references or breaking-change footers?

Yes. The skill can add an optional footer for breaking changes or issue refs if relevant, keeping the footer concise and professional.