# /commit — Safe Local Commit

Safe local git commit with auto-generated conventional commit messages. Never pushes. Refuses to commit to master/main directly.

## Usage

```
/commit                    # Auto-generate commit message
/commit "message"          # Use custom message
/commit --amend            # Amend last commit (USE WITH CAUTION)
```

**Examples:**
- `/commit`
- `/commit "feat(billing): add Stripe webhook handler"`
- `/commit --amend`

## Workflow

### Step 1: Safety Checks
1. Check current branch:
   ```bash
   git branch --show-current
   ```
2. **REFUSE to commit if on `main` or `master`** — tell user to create a feature branch first
3. Check for staged/unstaged changes:
   ```bash
   git status
   ```
4. If no changes, report "Nothing to commit" and stop

### Step 2: Review Changes
1. Show the diff:
   ```bash
   git diff --staged
   git diff
   ```
2. Check for sensitive files that should NOT be committed:
   - `.env`, `.env.local`, `.env.production`
   - `credentials.json`, `serviceAccountKey.json`
   - Any file containing API keys or secrets
3. **WARN the user** if sensitive files are staged

### Step 3: Generate Commit Message
If no custom message provided:
1. Analyze the diff to determine:
   - Type: `feat`, `fix`, `chore`, `refactor`, `test`, `docs`, `style`, `perf`
   - Scope: the area of the codebase (e.g., `billing`, `auth`, `dashboard`, `api`)
   - Description: concise summary of the "why"
2. Check recent commit messages for style consistency:
   ```bash
   git log --oneline -10
   ```
3. Generate message in format: `type(scope): description`

### Step 4: Commit
1. Stage relevant files (prefer specific files over `git add .`):
   ```bash
   git add <specific-files>
   ```
2. Create the commit:
   ```bash
   git commit -m "$(cat <<'EOF'
   type(scope): description

   Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
   EOF
   )"
   ```
3. Confirm success:
   ```bash
   git status
   git log --oneline -1
   ```

### --amend Mode
- **WARN** the user that amending rewrites history
- Only amend if the last commit hasn't been pushed yet
- Check with: `git log origin/$(git branch --show-current)..HEAD --oneline`
- If the commit has been pushed, REFUSE and suggest a new commit instead

## Key Rules
- NEVER push — this command is local-only
- NEVER commit to main/master
- NEVER commit .env files or secrets
- NEVER use `git add -A` or `git add .` — always stage specific files
- Always include `Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>`
- Prefer conventional commits format
