npx skills add ...
npx skills add brave/brave-core --skill add-best-practice
npx skills add brave/brave-core --skill add-best-practice
'Add a new best practice to the appropriate doc. Checks for duplicates, assigns stable IDs, creates new category docs if needed. Triggers on: add best practice, new best practice, add bp, new bp.'
Add a new best practice rule to the correct best-practices document. Ensures no duplicates, assigns stable IDs, and follows the exact format of existing entries.
This skill runs from the brave-core (src/brave) directory. Best practices docs
are at ./docs/best-practices/ and the index is at ./docs/best_practices.md.
Set DOCS_DIR="./docs/best-practices".
Parse the argument to understand:
If the argument is a GitHub PR comment URL, gather full context before proceeding:
Fetch the review comment text via gh api
Fetch the PR diff around the commented file/line to understand the actual code being discussed:
Read the actual source file at the commented line to understand the full
context — the diff_hunk alone is often insufficient
If the comment is part of a thread, fetch the entire thread to understand the full discussion
CRITICAL: Do NOT rely solely on the comment text. Review comments are often brief and assume the reader can see the code. You MUST read the actual code being reviewed to understand what the reviewer is flagging and why. Misunderstanding the code context leads to incorrect best practices.
If the description is vague even after gathering context, ask the user to clarify before proceeding.
Search ALL existing best-practice documents for rules that already cover this topic:
docs/best_practices.md to understand document
categories$DOCS_DIR/*.md for keywords related
to the new practiceIf a duplicate or near-duplicate is found:
<document>.md (ID: <ID>)."Discover the available documents and their categories dynamically:
This outputs JSON listing each document and its category (e.g., cpp, test,
build, frontend, always). Use the category and document name to determine
the best match for the new practice. Read the top of candidate documents if
needed to confirm the fit.
If it doesn't fit any existing document AND the topic seems like it would attract multiple related practices, create a new category document:
performance.md,
security-practices.md)script/manage-bp-ids.py in the DOC_PREFIXES dictdocs/best_practices.md index under the appropriate section# Title header and cross-reference commentIf it doesn't fit but is a one-off, find the closest existing document and add it there.
Write the entry following the exact format used in existing docs. Read a few entries from the target document first to match its style.
Required format:
Additional context, edge cases, or explanation if needed.
If validation fails, fix the issue before proceeding.
All created or modified docs MUST be formatted with pnpm run format before
being committed — unformatted docs fail CI's presubmit step. ALWAYS git add
any new (untracked) docs BEFORE calling pnpm run format — the formatter
silently skips untracked files, so missing this step means the new doc ships
unformatted and CI will reject it.
After successfully adding the best practice, commit all changes as a single
atomic commit on the current branch. Use --amend to fold the ID assignment and
any related edits into one commit (do NOT create separate commits for the entry
and the ID assignment — they are one logical unit).
Then ask the user:
"The best practice has been added to
<document>.mdwith ID<ID>and committed. Would you like me to create a branch and open a PR?"
If the user wants a PR:
Report the PR URL if created.
No Claude Code attribution — do NOT include Co-Authored-By,
Generated with Claude Code, or any other attribution in commits or PRs
Always format with pnpm run format — never hand-format markdown or use
another formatter. New (untracked) documents must be git added first, or the
formatter will skip them silently
Never reuse old IDs — the manage-bp-ids.py --assign script handles this
automatically by incrementing from the highest existing number
Never manually pick IDs — always let the script assign them
Never fill gaps in ID sequences — gaps are intentional (deleted practices)
Always check for duplicates first — adding redundant rules wastes everyone's time
Match the style of the target document exactly — read existing entries before writing
Keep entries concise — best practices should be scannable, not essays
Include code examples whenever possible — show don't tell
git add $DOCS_DIR/<document>.md
# Also add manage-bp-ids.py and docs/best_practices.md if they were modified
git commit -m "Add best practice: <short rule title>"git stash # stash the commit temporarily
git checkout -b best-practices-update-$(date +%Y%m%d-%H%M%S) HEAD~1
git stash pop
git add -A
git commit -m "Add best practice: <short rule title>"
git push -u origin HEAD
gh pr create --title "Add best practice: <short rule title>" --body "$(cat <<'EOF'
## Summary
- Adds new best practice to `<document>.md`: **<Rule Title>**
- ID: `<ID>`
EOF
)"