Repository guidance for coding agents. CLAUDE.md is a symlink to this file.
Less is more. The simplest solution is the best solution. The action hierarchy for every change: Delete > Replace > Add.
- Solve at the owner: Put behavior in the code path that owns or observes it. For fixes, never guard a symptom with a staleness check, initialization flag, skip-first-call branch, or
try/exceptaround broken logic; relocate the trigger and delete the wrong path. For features, extend the existing owner rather than creating a parallel abstraction. - Search and reuse first: Search the whole repository before creating a feature, component, helper, workflow, or utility. Reuse or adapt what exists, consolidate in-scope duplication in the shared owner, and delete duplicate paths. Three similar lines beat a helper nobody else calls.
- Delete and modify existing code before creating new code: Bugfixes are net-negative by default unless deletion and relocation are demonstrably impossible. A new file must first prove it cannot fit cleanly in an existing owner.
- Keep scope minimal: Implement only the simplest complete solution. Avoid impossible-state handling, speculative flags, compatibility shims, policy scaffolding, and unrelated cleanup. Tests are out of scope by default — rely on existing coverage and focused validation; only an uncovered, high-risk regression path justifies minimal new test code.
- Ship zero-regression, production-ready changes: Understand what you remove instead of retaining broken code as insurance. Remove unused imports, functions, types, files, and comments; run relevant cleanup checks; and thoroughly debug and validate the changed owner. Do not break existing features or workflows unless the PR intentionally removes them with evidence.
Review gate: for every addition, the reviewer decides whether deleting or changing existing code would have fixed the problem instead — if it would, that is a blocking finding. A missing or thin PR description is never itself a finding.
NEVER push to main. NEVER force push. Always start work in a new git worktree (git worktree add) on a feature branch and open a PR — never edit the primary checkout directly, it may hold in-flight work.
After opening a PR:
- Wait for the automated PR review and auto-format commit from Ultralytics Actions (
format.yml), then pull and address every finding. - Review the full diff in-session against the Core Principles, performance, and the review gate above, then batch the fixes into one commit and push. After each round of bot or human commits, pull and resume the same reviewer on
<last-reviewed-sha>..HEADplus anything that delta could have invalidated. Repeat until the local head matches the live head. - Hand off or merge only on a clean final pass: one cold full-diff review returning LGTM with no findings, on a head that is still live at merge time.
- Never fight other commits: Ultralytics Actions pushes auto-format and header commits, and multiple users may work on the same PR.
git pull --rebasebefore pushing; never reset or revert commits you did not author. - After the PR merges, clean up: remove local worktrees and branches for it, then
git checkout main && git pull.
uv venv --python 3.14
source .venv/bin/activate
uv pip install -e ".[dev]"
pytest tests -v
pytest tests/test_first_interaction.py -v
ruff format --line-length 120 .Keep Python 3.8 compatibility; CI also runs a recent Python. Formatter flags are owned by action.yml and mirrored in actions/format_code.py: update both, including codespell lists. Run pytest from the repository root; the real Markdown formatter test can rewrite files, so inspect the working tree afterward. Missing shfmt is only logged. See .github/workflows/ci.yml for the full check matrix.
- Formatting →
action.yml,actions/format_code.py. - Reviews and summaries →
actions/review_pr.py,actions/first_interaction.py. - Models and prompts →
actions/utils/openai_utils.py. - GitHub requests →
actions/utils/github_utils.py. - Headers and Markdown →
actions/update_file_headers.py,actions/update_markdown_code_blocks.py. - Release gating →
actions/utils/version_utils.py,.github/workflows/publish.yml.
- Ultralytics-owned PyPI packages use
MAJOR.MINOR.PATCHversions only; no suffixes. - License headers (
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license) are added automatically by Ultralytics Actions (ultralytics-actions-headers, extensions inCOMMENT_MAP) — don't add or revert them manually. - Bump
__version__inactions/__init__.pywhen a PR changes package behavior — publishing to PyPI is gated on the version change (publish.yml). - Google-style docstrings, single-line summaries where possible; formatting is enforced by the repo's own action (
format.yml), which auto-commits fixes to PRs. - Tests use
unittest.mock/monkeypatchto patch env vars and network calls; no test reaches the network (tests/test_urls.pypatchesis_urlwith an autouse fixture and calls it withcheck=False). Modules listed in[tool.coverage.run] omitare excluded from the coverage report. - Commits and PRs use plain git identity — no AI attribution, co-author lines, or generated-with footers.
- Env is read at import time into module constants:
OPENAI_API_KEY/ANTHROPIC_API_KEY/MODEL/REVIEW_MODEL(openai_utils.py),LABELS→AUTO_LABELS,SUMMARY→AUTO_PR_SUMMARY,REVIEW→AUTO_PR_REVIEW,BLOCK_USER(first_interaction.py),CURRENT_TAG/PREVIOUS_TAG(summarize_release.py),HEADER(update_file_headers.py). Settingos.environafter import has no effect — patch the module attribute (e.g.patch("actions.utils.openai_utils.OPENAI_API_KEY", "x"),patch("actions.first_interaction.AUTO_PR_REVIEW", False)). _verified_local_checkoutdepends only on whether the reviewed commit exists in the runner's git objects, not on the event type. The rootaction.ymlchecks out the PR head only forpull_requestevents, so underpull_request_targetthe review reads files through the GitHub API and drops thesearch_repotool unless the consumer workflow checked out that head itself.Action's session retries connection failures on every method but 5xx responses only onGET/PUT/DELETE; aPOST/PATCHthat returns 5xx is not retried by the session — callers such ascla._read/_persistandget_responseimplement their own loops.publish.yml'scheckjob gates releases with the PyPI-installedultralytics-actions(shell: pythontemp script plus theultralytics-actions-summarize-releaseconsole script, neither of which sees the checkout'sactions/), so a change toversion_utils.pyorsummarize_release.pyonly affects the next release after it is itself published.- The
Alertlabel path inapply_and_check_labelsrewrites the title/body, locks, and (for issues/discussions) closes the item for a non-org member as soon as the model returnsAlertand the repository has that label;BLOCK_USER=trueadditionally blocks the account org-wide.