diff --git a/config/opencode/skills/ask-claude/SKILL.md b/config/opencode/skills/ask-claude/SKILL.md index b667eee..cf5d8a1 100644 --- a/config/opencode/skills/ask-claude/SKILL.md +++ b/config/opencode/skills/ask-claude/SKILL.md @@ -42,6 +42,40 @@ cat path/to/file.rs | claude -p "Review this for race conditions; explain any yo git diff main...HEAD | claude -p "Spot bugs or risky changes in this diff." ``` +Only pipe when the context is small and self-contained. For anything that +spans multiple files, prefer giving Claude repo access (next section) so it +can read surrounding code, not just the patch. + +## Code review pattern + +For a review of the current branch / working tree, **do not** gather diffs +yourself and stuff them into the prompt. Point Claude at the directory and +let it run `git` and read files on its own — it sees more context (full +files, history, neighbouring code) than a piped diff alone can provide, +and it will only fetch what it actually needs. + +Recommended invocation, run from the repo root: + +```bash +claude -p --permission-mode dontAsk \ + --allowedTools "Read Grep Glob Bash(git diff:*) Bash(git log:*) Bash(git status:*) Bash(git show:*)" \ + "Review the changes on this branch vs main. Flag bugs, risky changes, + and anything that violates the project's conventions. Read whatever + files you need for context." +``` + +Why this is better than `git diff … | claude -p`: + +- Claude can open the *full* file around a hunk, not just the ±3 lines of + context in the patch. +- Claude can follow references — call sites, tests, related modules. +- The prompt stays small, so the model spends its tokens on reasoning + instead of re-reading a diff you already had on disk. +- Works for large diffs that would otherwise blow the context window. + +Use the piped form only for a tiny, self-contained snippet where extra +repo context genuinely adds nothing. + ## Permissions In `-p` mode there is no human to approve prompts, so anything not explicitly @@ -143,6 +177,9 @@ with `jq`. - Don't call `claude -p` in a loop or for trivial questions — it is expensive. - Don't pass the entire conversation history; distill the question first. +- Don't gather a giant `git diff` and pipe it in for code review — give + Claude read-only repo access (see "Code review pattern") and let it pull + exactly the context it needs. - Don't ask Claude to "do" multi-step refactors with file writes — collect its recommendations and apply them yourself, so you stay in control. - Don't forget that Claude has no memory between calls — every invocation