一键导入
precommit
Use when running quality checks before commits, validating code passes compilation/formatting/linting/tests, or when user invokes /precommit
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Use when running quality checks before commits, validating code passes compilation/formatting/linting/tests, or when user invokes /precommit
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
| name | precommit |
| description | Use when running quality checks before commits, validating code passes compilation/formatting/linting/tests, or when user invokes /precommit |
Executes the production-ready precommit workflow to ensure code quality before commits.
Invoke with /precommit when:
Skip this skill when:
/spike instead)mix test or cargo test directly)/review instead)/precommit # Run all checks
/precommit --fix # Run checks and auto-fix formatting issues
This skill typically uses:
mix, cargo, npm, pytest)--fix flag)Runs four quality checks in sequence (language-aware):
First detect project language and verify required tools.
Language Detection:
Load the language-detection skill for canonical detection logic and tooling commands.
Check Language-Specific Dependencies:
Elixir:
# Check if credo is in mix.exs
if ! grep -q ':credo' mix.exs; then
echo "Missing dependency: credo"
echo "Add to mix.exs:"
echo ' {:credo, "~> 1.7", only: [:dev, :test], runtime: false}'
exit 1
fi
Rust:
# Check rustfmt and clippy installed
if ! command -v cargo-fmt &> /dev/null; then
echo "rustfmt not installed"
echo "Run: rustup component add rustfmt"
exit 1
fi
Python:
# Check for quality tools
if ! command -v mypy &> /dev/null; then
echo "mypy not installed"
echo "Run: pip install mypy"
fi
TypeScript:
# Check for eslint
if ! npm list eslint &> /dev/null; then
echo "eslint not installed"
echo "Run: npm install --save-dev eslint"
fi
Execute checks based on detected language:
Language-Specific Commands:
| Step | Elixir | Rust | Python | TypeScript |
|---|---|---|---|---|
| 1. Compile/Check | mix compile --warnings-as-errors | cargo check | mypy src/ | tsc --noEmit |
| 2. Format | mix format --check-formatted | cargo fmt -- --check | ruff format --check . | prettier --check . |
| 3. Lint | mix credo --strict | cargo clippy -- -D warnings | ruff check . | eslint . |
| 4. Test | mix test | cargo test | pytest | npm test |
Elixir Example:
echo "Running precommit checks..."
echo ""
# 1. Compile with warnings as errors
echo "1/4 Compiling..."
if mix compile --warnings-as-errors; then
echo "Compilation passed"
else
echo "Compilation failed with warnings"
exit 1
fi
# 2. Format code
echo "2/4 Formatting..."
if mix format --check-formatted; then
echo "Formatting correct"
else
echo "Code needs formatting. Run: mix format"
exit 1
fi
# 3. Run credo
echo "3/4 Static analysis..."
if mix credo --strict; then
echo "Credo passed"
else
echo "Credo found issues"
exit 1
fi
# 4. Run tests
echo "4/4 Running tests..."
if mix test; then
echo "All tests passed"
else
echo "Tests failed"
exit 1
fi
echo "All precommit checks passed!"
Rust Example:
echo "Running precommit checks..."
# 1. Check compilation
echo "1/4 Checking..."
cargo check || exit 1
# 2. Check formatting
echo "2/4 Formatting..."
cargo fmt -- --check || exit 1
# 3. Run clippy
echo "3/4 Linting..."
cargo clippy -- -D warnings || exit 1
# 4. Run tests
echo "4/4 Testing..."
cargo test || exit 1
echo "All precommit checks passed!"
If all checks pass:
Precommit Checks Complete
All checks passed:
- Compilation (0 warnings)
- Formatting (all files formatted)
- Linting (strict mode)
- Tests (X tests, 0 failures)
Ready to commit!
If any check fails:
Precommit Checks Failed
Results:
- Compilation: passed
- Formatting: 3 files need formatting
Next steps:
1. Run formatter (see language-detection skill for command)
2. Review changes
3. Run /precommit again
With --fix flag:
Precommit with Auto-Fix
1/4 Compilation... passed
2/4 Formatting... Fixed 3 files
3/4 Static analysis... passed
4/4 Tests... passed
Auto-fixed:
- Formatted 3 files
- Run git diff to review changes
All checks passed!
Elixir:
Required dependencies not found
Missing:
- credo: Add {:credo, "~> 1.7", only: [:dev, :test], runtime: false}
After adding to mix.exs, run: mix deps.get
Rust:
Clippy not installed
Run: rustup component add clippy
Elixir:
Compilation Failed
Errors found:
lib/my_app/accounts.ex:42: warning: variable "user" is unused
Fix: Remove unused variables or prefix with underscore: _user
Run: mix compile --warnings-as-errors
Rust:
Compilation Failed
error[E0382]: borrow of moved value: `data`
Fix: Review ownership and borrowing
Run: cargo check
Elixir:
Tests Failed
Failed tests:
1) test create_user/1 creates user (MyApp.AccountsTest)
test/my_app/accounts_test.exs:42
Fix: Review test failure, fix implementation or update tests
Run: mix test test/my_app/accounts_test.exs:42
Rust:
Tests Failed
---- tests::test_create_user stdout ----
thread 'tests::test_create_user' panicked
Fix: Review test failure and fix implementation
Run: cargo test test_create_user
Configure behavior per language via environment variables or project config:
Environment Variables:
PRECOMMIT_SKIP_TESTS=1 - Skip test stepPRECOMMIT_FIX=1 - Auto-fix formatting issuesLanguage-Specific Configuration:
Elixir: .credo.exs for Credo rules
Rust: clippy.toml for Clippy settings
Python: pyproject.toml for tool configuration
TypeScript: .eslintrc.js for ESLint rules
To run automatically before each commit, add to .git/hooks/pre-commit:
#!/bin/bash
set -e
echo "Running precommit checks..."
claude-code /precommit
if [ $? -ne 0 ]; then
echo ""
echo "Precommit checks failed. Commit aborted."
echo "Fix issues and try again, or use --no-verify to skip (not recommended)."
exit 1
fi
Make executable:
chmod +x .git/hooks/pre-commit
Precommit succeeds when:
/review - Comprehensive code review beyond precommit checks/spike - Fast prototyping mode (skips some checks)/spike-migrate - Upgrade SPIKE code to pass precommitproduction-quality - Knowledge about quality standards (not a workflow)Use when researching state-of-the-art algorithms for a problem, finding academic papers, comparing algorithm approaches, needing paper citations, or user invokes /algorithm-research
Use when researching algorithms, data structures, optimization, performance, or need modern alternatives to classic algorithms
Use when creating benchmarks, measuring performance, comparing implementations, or user invokes /benchmark. Provides step-by-step workflow for benchmark creation, data generation, and results interpretation.
Use when analyzing code cognitive load, onboarding difficulty, or user invokes /cognitive-audit for complexity analysis and refactoring recommendations
Use when analyzing cognitive load, code complexity, onboarding difficulty, readability concerns, maintainability issues, or applying Ousterhout principles for deep modules, reducing complexity, and strategic programming approaches
Use when implementing concurrent operations, choosing between concurrency models, designing async workflows, or working with parallel data processing