Validate code quality and commit changes. Supports Python, Shell, and Markdown. Use for code commits.
Automatically fix code quality issues and validate changes before committing.
The script auto-fixes everything it can (formatting, fixable lint issues), then runs validators and shows you their raw output. You read the tool output directly, decide if there are problems, and proceed accordingly.
Key Philosophy: You're an intelligent agent - the script doesn't parse tool output or interpret "errors" vs "success." It just shows you what ruff, mypy, shellcheck, etc. say, and you decide.
Note on tool selection: The script prefers project-managed tools (via uv run --group dev if pyproject.toml exists) over global tools, which allows mypy to see project dependencies and validate imports properly.
IMPORTANT: Stage files before running validation:
git add <files-to-commit>
The script validates only staged changes. If you run it without staging, you'll get:
Exit code 1: No staged changes to commit
~/.claude/skills/safe-commit/safe_commit.sh
The script will:
If you see MISSING_TOOLS: - Some validators are unavailable. Validation will be limited but script continues.
Read the validator output directly and fix any problems found:
Clean output - proceed with commit:
=== Validating: script.py ===
--- ruff check (via project env) ---
All checks passed!
--- mypy (via project env) ---
Success: no issues found in 1 source file
Errors found - fix them before committing:
=== Validating: script.py ===
--- ruff check ---
script.py:10:5: F821 Undefined name `foo`
--- mypy ---
script.py:10: error: Name 'foo' is not defined
→ Undefined variable on line 10 - edit the file to fix it, then re-run validation
Important:
Special cases:
git diff --cached to see what changedfeat:, fix:, refactor:, docs:, test:)git log -5 --onelinegit commit -m "your message here"
The script uses language-specific tools for formatting, linting, and validation:
Python:
ruff format (formatter) + ruff check --fix (linter with auto-fix)ruff check (linter) + mypy (type checker)Shell:
shfmt -w (formatter)shellcheck (linter)Markdown:
markdownlint --fix + prettier --write or mdformat (formatters)markdownlint (linter)Auto-fixes (re-stages automatically):
Hard blocks (exits with error):
Shows in output (you interpret):
Warns (doesn't block):
If changes are unrelated, stage them separately:
# First commit
git add <first-group-of-files>
~/.claude/skills/safe-commit/safe_commit.sh
git commit -m "first commit"
# Second commit
git add <second-group-of-files>
~/.claude/skills/safe-commit/safe_commit.sh
git commit -m "second commit"
To unstage files already staged:
git restore --staged <unwanted-files>
If the script itself seems broken or needs improvement, see TESTING.md for how to test and validate changes to the safe-commit skill.