Przejdź do głównej zawartości

Automatyczne przeglądy kodu

Zaległości przeglądowe twojego zespołu mają 15 PR-ów w kolejce. Trzy są otwarte od czterech dni. Twoi starsi deweloperzy spędzają 30% czasu na przeglądaniu kodu, a połowa komentarzy to te same powtarzające się problemy: brakująca obsługa błędów, niezwalidowane dane wejściowe, testy pokrywające tylko szczęśliwą ścieżkę. Claude Code może załatwić mechaniczną część przeglądu, uwalniając ludzkich recenzentów do ocen wymagających doświadczenia.

  • Workflow przeglądu oparty na CLI, który wyłapuje typowe problemy przed przeglądem ludzkim
  • Hooki pre-commit i pre-push do przeglądów
  • Ustrukturyzowane prompty do przeglądów bezpieczeństwa, wydajności i poprawności
  • Niestandardowa komenda /review, której może używać cały zespół

Najprostszy przegląd to analiza bieżącego diffa:

Okno terminala
git diff | claude -p "Review this diff. Focus on: error handling, type safety, and security. Skip style issues. For each finding, state the file, line, severity (CRITICAL/HIGH/MEDIUM/LOW), and a specific fix."

Przed commitowaniem przejrzyj tylko zmiany staged:

Okno terminala
git diff --cached | claude -p "Review these staged changes for issues that should be fixed before committing. Only flag issues that are CRITICAL or HIGH severity."

Do przeglądu całego PR-a z pełnym kontekstem:

Okno terminala
# Review PR changes against main branch
git diff main...HEAD | claude -p "Review this PR. The changes implement [feature description]. Check that the implementation is correct, complete, and does not introduce regressions."

Utwórz dedykowanego subagenta przeglądu do głębszej analizy:

---
description: "Senior code reviewer. Use after code changes or when review is explicitly requested."
tools:
- Read
- Grep
- Glob
- Bash
model: sonnet
---
You are a senior code reviewer. When reviewing:
1. Start with git diff to understand the scope
2. Read each modified file in full (not just the diff) to understand context
3. Check the test files for adequate coverage
4. Run the linter and type checker to catch mechanical issues
Review criteria:
- Correctness over cleverness
- Error handling at every boundary
- Types that prevent bugs at compile time
- Tests that would catch regressions
Be specific. Reference exact file paths and line numbers.
Acknowledge good patterns alongside issues.
.git/hooks/pre-push
#!/bin/bash
# Runs a quick review before pushing
DIFF=$(git diff origin/main...HEAD --no-color)
if [ -z "$DIFF" ]; then
exit 0
fi
RESULT=$(echo "$DIFF" | claude -p "Quick review of changes about to be pushed. \
Only flag CRITICAL issues that MUST be fixed before this code reaches the remote. \
Output 'PASS' if safe to push. Output 'BLOCK: [reason]' if there are critical issues." \
--max-turns 3 --output-format text 2>&1)
if echo "$RESULT" | grep -q "BLOCK:"; then
echo "Push blocked by review:"
echo "$RESULT"
echo ""
echo "Fix the issues or use 'git push --no-verify' to bypass."
exit 1
fi
Okno terminala
# Review dependency changes in a PR
git diff main...HEAD -- package.json package-lock.json | \
claude -p "Review these dependency changes: \
1. Are any new dependencies unnecessary (could we use existing tools)? \
2. Check bundle size impact of new dependencies \
3. Are any dependencies deprecated or unmaintained? \
4. Are version ranges appropriate (too broad = risk, too narrow = maintenance)?"

Przeglądy są zbyt zaszumione: Jeśli Claude flaguje zbyt wiele problemów o niskiej wadze, dostosuj prompt, aby skupiał się tylko na CRITICAL i HIGH. Dodaj “Skip style issues, formatting, and naming conventions — our linter handles those”, aby zmniejszyć szum.

Przeglądy pomijają wzorce specyficzne dla projektu: Claude nie zna konwencji twojego projektu, dopóki mu ich nie powiesz. Dodaj kryteria przeglądu do pliku CLAUDE.md, aby każda sesja przeglądu miała kontekst projektowy.

Przegląd trwa za długo w pre-commit: Ogranicz zakres przeglądu. Użyj --max-turns 3 i skoncentruj prompt na krytycznych problemach. Przegląd pre-commit powinien trwać 10-15 sekund, nie 2 minuty.

False positive na celowych wzorcach: Jeśli Claude ciągle flaguje wzorce, które są celowe w twojej bazie kodu, dodaj wyjątki do CLAUDE.md: “The any type in src/legacy/ is intentional and should not be flagged in reviews.”