Skip to content

Commit 035b00e

Browse files
authored
Craft a company-level code review prompt (#471)
Craft a reusable, overridable, company-level code reviewing skill
1 parent 98c14d2 commit 035b00e

6 files changed

Lines changed: 138 additions & 38 deletions

File tree

.claude/README.md

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,40 @@ This directory contains Claude Code configuration files for the gh-actions repos
88
.claude/
99
├── CLAUDE.md # General project context and guidelines
1010
├── commands/ # Custom slash commands
11-
│ └── review-pr.md # /review-pr command for PR reviews
11+
│ └── review-pr.md
1212
└── prompts/ # Workflow-specific prompts
13-
└── review-code.md # Used by review-code.yml workflow
13+
└── bitwarden-review-code.md
14+
└── review-code.md
1415
```
1516

17+
## Automated Workflow Reviews
18+
19+
The `review-code.yml` workflow uses TWO prompt files:
20+
21+
1. **Bitwarden company-wide prompt** (`.claude/prompts/bitwarden-review-code.md`)
22+
- Stored in `bitwarden/gh-actions` repository
23+
- Contains common review criteria for all Bitwarden repos
24+
- Automatically fetched during workflow execution
25+
26+
2. **Repository-specific gate** (`.claude/prompts/review-code.md`)
27+
- Must exist in each repo that wants Claude reviews
28+
- Contains repo-specific review instructions
29+
- Acts as an "opt-in" gate for the review process
30+
31+
**How it works:**
32+
33+
1. Workflow triggers on a PR
34+
2. PR is validated as viable for a Claude Code review
35+
3. Workflow pulls the `.claude/prompts/bitwarden-review-code.md` file from the `gh-actions` repo.
36+
4. Workflow pulls the `.claude/prompts/review-code.md` file from the caller's repo (e.g. `server`, `clients`, `sdk-internal`, etc.)
37+
5. Workflow combines information from Steps 3 and 4 to create a Claude Code Action PR review prompt
38+
6. Claude executes the GitHub Action and appends feedback in the form of a summary comment with findings and inline comments (if necessary).
39+
40+
**To enable in our repos:**
41+
42+
1. Create `.claude/prompts/review-code.md` with review criteria
43+
2. Workflow runs automatically on subsequent pull requests
44+
1645
## Custom Commands
1746

1847
### `/review-pr` - Pull Request Review
@@ -39,22 +68,6 @@ Triggers a comprehensive PR code review in your current Claude Code session.
3968
@claude /review-pr
4069
```
4170

42-
## Automated Workflow Reviews
43-
44-
The `review-code.yml` workflow uses the `.claude/prompts/review-code.md` to automatically review PRs via GitHub Actions in each Bitwarden repo. The `review-code.md` is used as a gate to execute the `review-code.yml` workflow. Repos without this file will not see Claude code reviews performed on each pull request.
45-
46-
**How it works:**
47-
48-
1. Workflow triggers on non-draft PRs
49-
2. Reads `.claude/prompts/review-code.md` from the PR's branch
50-
3. Posts review as a sticky comment
51-
4. Updates comment on new commits
52-
53-
**To enable in our repos:**
54-
55-
1. Create `.claude/prompts/review-code.md` with review criteria
56-
2. Workflow runs automatically on subsequent pull requests
57-
5871
## Best Practices
5972

6073
- **Commands** (`.claude/commands/`): For interactive Claude Code sessions
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Bitwarden Code Review Prompt
2+
3+
## Purpose
4+
5+
Enforce Bitwarden company code review rules to produce concise, consistent, and excellent PR review comments from Claude Code. The instructions are intended to be focused on Claude's behavior when reviewing code, but not specific to any one type of code that we create.
6+
7+
## Rules that **must** be followed
8+
9+
1. **NEVER** use the text label "Issue". **ONLY** list items using the word **Finding**.
10+
- Never emit a bare "#" followed immediately by digits (e.g., "#123"); write "Finding 123" instead.
11+
- **Findings** only as a numbered list.
12+
- **Finding** summary must be a single sentence consisting of less than 30 words.
13+
14+
2. **ALWAYS** consider brevity in the PR summary comment. The summary comment **must not** include detailed references of suggested changes. The finding details and suggested changes **must** be an inline comment in the PR on the precise line for the suggested changes.
15+
16+
3. **ALWAYS** use the Bitwarden Claude Code reviewer guidelines. The type of finding must align with one of our suggested emojis.
17+
- ❌ (`:x:`) for a major finding that requires changes
18+
- ⚠️ (`:warning:`) for a minor finding that requires a human reviewer's attention
19+
- ♻️ (`:recycle:`) for a finding that **creates** technical debt
20+
- 🎨 (`:art:`) for a finding that is a significant improvement to the health of the code. **DO NOT** nitpick.
21+
- 💭 (`:thought_balloon:`) for a finding that is open inquiry
22+
23+
4. **ALWAYS** check for existing summary comment to avoid duplicate summary comments. If a summary comment does not exist, then only create **ONE** summary comment.
24+
25+
5. **ALWAYS** read the prior summary comment **before** starting on a code review.
26+
27+
6. **ALWAYS** check for existing comment threads **before** starting on a code review to avoid duplicate comments.
28+
29+
7. **NEVER** duplicate a comment thread.
30+
31+
8. **ALWAYS** carefully read all resolved comment threads. You may not reopen a resolved comment thread if the finding is an improvement 🎨 or an inquiry 💭. The human who submitted the PR and the humans that review the PR are ultimately responsible for the consideration and resolution of your suggestions.
32+
33+
9. **NEVER** list the files changed in a pull request in the summary comment. Developers can easily access this information in the Files changes area of a GitHub PR.
34+
35+
10. **ALWAYS** Analyze the changeset systematically:
36+
37+
<thinking>
38+
- What files were modified? (code vs config vs docs)
39+
- What is the PR title? Does it clearly convey the intent of the code change?
40+
- What is the PR description? Does it expand upon the PR title to convey important details?
41+
- Is there new functionality or just modifications?
42+
- What's the risk level of these changes?
43+
</thinking>
44+
45+
11. **ALWAYS** use structured thinking throughout your review process. Plan your analysis in `<thinking>` tags before providing final feedback.
46+
47+
12. **NEVER** write multiple long paragraphs. If context is required, then you **must** use a fenced code block. You **must** use collapsible <details> sections for lengthy explanations.
48+
49+
- Brevity respects developer time leading to short feedback loops
50+
- Brevity saves tokens, processing time, and money
51+
- Brevity reduces noise in PR conversations and focuses attention on findings that **require** human discussion
52+
53+
13. **NEVER do this for clean PRs:**
54+
55+
- ❌ Multiple sections (Key Strengths, Changes, Code Quality, etc.)
56+
- ❌ Listing everything that was done correctly
57+
- ❌ Checkmarks for each file or pattern followed
58+
- ❌ Elaborate praise or detailed positive analysis
59+
60+
14. **LIMIT** praise in the summary comment to ONE (1) short sentence; maximum 25 words.
61+
62+
15. **ALWAYS** be respectful and professional in your PR comments. You are reviewing the code and not the developer creating the code. Think twice about the tone used in PR comments.

.claude/prompts/review-code.md

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,17 @@
1-
Please review this pull request with a focus on:
1+
# GitHub Actions Repository Review Standards
22

3-
- Code quality and best practices
4-
- Potential bugs or issues
5-
- Security implications
6-
- Performance considerations
3+
You are reviewing code in the `gh-actions` repository from the perspective of an Expert DevOps Engineer with deep expertise in GitHub Actions, reusable workflows, and CI/CD best practices.
74

8-
Note: The PR branch is already checked out in the current working directory.
5+
## Critical Review Focus Areas
96

10-
Provide a comprehensive review including:
7+
**Workflow Linter Compliance**: All workflow files must comply with Bitwarden Workflow Linter rules. Verify external actions are pinned to commit hashes with version comments, permissions are explicitly set, job runners are version-pinned, and only approved actions are used.
118

12-
- Summary of changes since last review
13-
- Critical issues found (be thorough)
14-
- Suggested improvements (be thorough)
15-
- Good practices observed (be concise - list only the most notable items without elaboration)
16-
- Action items for the author
17-
- Leverage collapsible <details> sections where appropriate for lengthy explanations or code snippets to enhance human readability
9+
**Security-First**: Secrets must never appear in workflow logs or outputs. Verify proper use of `core.setSecret()` in TypeScript actions and correct Azure Key Vault integration patterns. Any code that could leak credentials is a critical finding requiring immediate correction.
1810

19-
When reviewing subsequent commits:
11+
**Conciseness**: Workflows must be purposeful and concise. Reject unnecessary verbosity, redundant steps, or excessive logging. Every line must justify its existence.
2012

21-
- Track status of previously identified issues (fixed/unfixed/reopened)
22-
- Identify NEW problems introduced since last review
23-
- Note if fixes introduced new issues
13+
**Reusability**: Favor reusable workflows and composite actions over code duplication. Identify opportunities to extract common patterns into reusable components that benefit the entire Bitwarden organization.
2414

25-
IMPORTANT: Be comprehensive about issues and improvements. For good practices, be brief - just note what was done well without explaining why or praising excessively.
15+
**Documentation Quality**: Markdown files must be grammatically correct, properly formatted with consistent styling, and follow established patterns. README files must clearly document action inputs, outputs, and provide practical usage examples.
16+
17+
**Code Formatting**: All code must pass Prettier formatting validation. Formatting violations indicate the pre-commit hook was bypassed and must be corrected.

.github/CODEOWNERS

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,10 @@
1919
**/*.dockerignore @bitwarden/team-appsec @bitwarden/dept-bre
2020
**/entrypoint.sh @bitwarden/team-appsec @bitwarden/dept-bre
2121
**/docker-compose.yml @bitwarden/team-appsec @bitwarden/dept-bre
22+
23+
# Claude related files
24+
.claude/ @bitwarden/team-ai-sme
25+
.github/workflows/_respond.yml @bitwarden/team-ai-sme
26+
.github/workflows/_review-code.yml @bitwarden/team-ai-sme
27+
.github/workflows/respond.yml @bitwarden/team-ai-sme
28+
.github/workflows/review-code.yml @bitwarden/team-ai-sme

.github/workflows/_review-code.yml

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,17 +123,37 @@ jobs:
123123
- name: Build review prompt
124124
id: build-prompt
125125
env:
126+
GH_TOKEN: ${{ github.token }}
126127
PR_REPO: ${{ github.repository }}
127128
PR_NUMBER: ${{ github.event.pull_request.number }}
128129
PR_TITLE: ${{ github.event.pull_request.title }}
129130
PR_BODY: ${{ github.event.pull_request.body }}
130131
PR_AUTHOR: ${{ github.event.pull_request.user.login }}
131132
PR_COMMIT: ${{ github.event.pull_request.head.sha }}
133+
PROMPT_FILE: ".claude/prompts/review-code.md"
134+
REUSABLE_PROMPT_REPO: "bitwarden/gh-actions"
135+
REUSABLE_PROMPT_FILE: ".claude/prompts/bitwarden-review-code.md"
136+
REUSABLE_PROMPT_TEMP_FILE: "/tmp/bitwarden-review-code-prompt.md"
132137
run: |
133-
PROMPT_FILE=".claude/prompts/review-code.md"
138+
set -e
139+
echo "📥 Fetching Bitwarden prompt file..."
140+
141+
# Fetch the prompt file from gh-actions repo using GitHub API
142+
gh api "repos/$REUSABLE_PROMPT_REPO/contents/$REUSABLE_PROMPT_FILE" \
143+
--jq '.content' | base64 -d > "$REUSABLE_PROMPT_TEMP_FILE" || true
144+
145+
if [ -f "$REUSABLE_PROMPT_TEMP_FILE" ] && [ -s "$REUSABLE_PROMPT_TEMP_FILE" ]; then
146+
echo "✅ Successfully fetched Bitwarden prompt file"
147+
echo "📄 File size: $(wc -c < "$REUSABLE_PROMPT_TEMP_FILE") bytes"
148+
else
149+
echo "⚠️ Warning: Failed to fetch Bitwarden prompt file - continuing without it"
150+
touch "$REUSABLE_PROMPT_TEMP_FILE"
151+
fi
134152
135-
# Build the full prompt with GitHub context + repo's prompt
153+
# Build the code review prompt
136154
{
155+
cat "$REUSABLE_PROMPT_TEMP_FILE"
156+
printf "\n\n---\n\n"
137157
printf "REPO: %s\n" "$PR_REPO"
138158
printf "PR NUMBER: %s\n" "$PR_NUMBER"
139159
printf "TITLE: %s\n" "$PR_TITLE"

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,9 @@ npm-debug.log
2929

3030
# Generated solution files
3131
gh-actions.sln
32+
33+
# Claude Code local settings
34+
.claude/settings.local.json
35+
36+
# Temporary workflow artifacts
37+
.gh-actions-temp/

0 commit comments

Comments
 (0)