Skip to content
Back to skills

Focused Fix

ASecurity

Constrain a bugfix to the smallest reviewable change: reproduce, patch, add a regression test, check the diff for scope creep. Use when asked for a minimal fix, hotfix or release-blocker; diagnose unknown causes with bug-diagnosis.

  • 1,271 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added May 27, 2026
data-aipythongobashdebugginggitdocumentation

Security analysis

A100/100

Pro scans all 7 files and shows the line behind each finding

Scanned December 4, 2026

npx -y skills add borghei/Claude-Skills --skill focused-fix --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Focused Fix?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Focused Fix
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/borghei-focused-fix/badge)](https://www.skillsdirectory.com/skills/borghei-focused-fix)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: focused-fix
description: >
  Constrain a bugfix to the smallest reviewable change: reproduce, patch, add a regression
  test, check the diff for scope creep. Use when asked for a minimal fix, hotfix or
  release-blocker; diagnose unknown causes with bug-diagnosis.
license: MIT + Commons Clause
metadata:
  version: 1.0.0
  author: borghei
  category: engineering
  domain: debugging
  updated: 2026-11-08
  tags: [bugfix, minimal-change, scope-analysis, debugging, focused-fix]
---

# Focused Fix

The agent fixes the reported bug and nothing else: a reproduction, the smallest change that makes it pass, a regression test, and a diff that a reviewer can read in a minute. Small fixes are easier to review, safer to roll back and less likely to hide a second regression.

This skill starts once the cause is known or close to known. When the cause is still a mystery (intermittent failures, no stack trace), run `engineering/bug-diagnosis` first and come back with a confirmed cause.

## When to Use

- "Fix this bug with minimal changes", "do a focused fix", "what is the smallest change for X?"
- A hotfix or release-blocker that must be low-risk and quick to review.
- A fix PR at risk of scope creep (refactors, style changes, "nearby" fixes).

## Clarify First

Before scoping the fix, settle the inputs below. When one is missing or vague and would change the result, ask about it; when it wouldn't, use a sensible default and say which one you used.

- **Observable failure:** exact symptom, repro steps, expected vs actual behaviour. This is what the fix must resolve, not a guess at the cause.
- **Expected scope:** which files or module the fix should touch, if known (becomes `--allow` for the scope check).
- **Minimal vs structural:** confirm a focused fix is wanted. If the honest fix spans several modules, stop and say so instead of forcing it into a "minimal" patch.

Ask about the two or three inputs that matter most for this request, not the whole list. If the user wants a result straight away, produce it and state your assumptions at the top.

## Workflow

1. **Reproduce.** Write the failing test first, from the bug report's inputs. It must fail for the reported reason before you change any code.
2. **Locate.** Use the stack trace, `grep` for the failing function and its callers, and `git log -p` on the suspect file. `change_scope_analyzer.py` can suggest candidate files from the bug text when there is nothing better to go on; treat its list as a hint.
3. **Patch** the root layer with the smallest change that makes the test pass. No renames, reformatting, or "while I'm here" edits.
4. **Check the diff** with `diff_scope_check.py`: file and line budget, files outside the expected scope, whitespace-only hunks, bundled dependency changes, and whether a test changed.
5. **Verify** that the new test passes and the existing suite still passes; both must pass before the PR opens. The scope check exits 0, or every finding has a one-line justification in the PR. The commit message names the bug and why the fix works.
6. **Stop and escalate** if the fix needs more than the budget (default 3 files / 60 lines outside tests) or crosses module boundaries: propose a separate, scoped refactor instead.

## Quick Start

Check a fix before opening the PR, from a saved diff:

```bash
python3 scripts/diff_scope_check.py --diff assets/sample_focused.diff --allow 'src/auth/*'     # focused (exit 0)
python3 scripts/diff_scope_check.py --diff assets/sample_sprawling.diff --allow 'src/auth/*'   # 5 findings (exit 1)
```

Real output of the second command (trimmed):

```
Read 5 file(s). Total: +7 -6; tests touched: 0

FIX 5 issue(s):
  - 5 non-test files changed (budget 3): src/auth/email.py, ... Fix: keep only the root-cause file(s); ...
  - src/auth/session.py: 1 whitespace/formatting-only hunk(s). Fix: revert them (git checkout -p src/auth/session.py)
  - dependency change bundled with code change: requirements.txt. Fix: land the dependency change in its own PR
```

Straight from git, as a pre-PR checklist step:

```bash
git diff main...HEAD | python3 scripts/diff_scope_check.py --diff - --format json
```

Optional, when there is no stack trace to start from (a sample codebase ships in `assets/sample_repo`):

```bash
python3 scripts/change_scope_analyzer.py --bug "Login fails when email has + character" --path assets/sample_repo
```

## Exit Codes

| Code | `diff_scope_check.py` | `change_scope_analyzer.py` |
|------|-----------------------|----------------------------|
| 0 | focused: `PASS` | at least one candidate file: `PASS` |
| 1 | scope findings: `FIX n issue(s)` | no file matched the keywords: `BLOCKED` |
| 2 | unreadable input, not a unified diff, negative budget | empty `--bug`, missing path, no source files under it |

Both accept `--format text|json` (`--json` is an alias). JSON output carries a `verdict` field.

## Tools Overview

| Tool | What it does | Key flags |
|------|--------------|-----------|
| `diff_scope_check.py` | Reads a unified diff; flags non-test files over budget, lines over budget, files outside `--allow`, whitespace-only hunks, lockfile/manifest changes bundled with code, and a missing test change. Each finding names the files and gives a fix. | `--diff <file or ->`, `--allow <globs>`, `--max-files` (default 3), `--max-lines` (default 60), `--no-test-required` |
| `change_scope_analyzer.py` | Keyword heuristic: ranks files whose name or content matches words in the bug text. A file is listed only if a keyword matches its name or content. It does not estimate lines or risk. | `--bug`, `--path`, `--extensions` |

The budgets (3 files, 60 lines) are team heuristics, not measured thresholds; set them per repo. `change_scope_analyzer.py` misses dynamic dispatch, reflection and config-driven paths. Prefer evidence (traces, tests, git history) over its ranking.

## Anti-Patterns

**Mistake:** "While I'm here" refactors in the bugfix PR.
**Why it happens:** The surrounding code is in view and looks improvable.
**Instead:** Note it and open a separate `refactor:` PR. Mixed PRs multiply review time and mask regressions behind the real fix.

**Mistake:** Reformatting the files you touch.
**Why it happens:** Format-on-save or habit.
**Instead:** Revert formatting-only hunks before committing; `diff_scope_check.py` lists them.

**Mistake:** Skipping the regression test because the fix is obvious.
**Why it happens:** A one-line change feels self-evidently right.
**Instead:** Every fix ships a test that failed before it. Obvious bugs come back during later refactors.

**Mistake:** Fixing the symptom in the wrong layer.
**Why it happens:** The first place the error shows is the easiest to patch.
**Instead:** Trace to where the bad value is produced and fix it there; otherwise the bug returns in a new form.

**Mistake:** Bundling the fix with a dependency upgrade.
**Why it happens:** The upgrade seemed related.
**Instead:** Land the upgrade separately so either change can be rolled back alone.

## Files

- `scripts/diff_scope_check.py`, `scripts/change_scope_analyzer.py` — the tools above.
- `assets/sample_focused.diff` (one source file plus a test), `assets/sample_sprawling.diff` (five files, formatting noise, a dependency bump, no test), `assets/malformed.diff` (not a diff, exit 2), `assets/sample_repo/` (tiny codebase for the analyzer), `assets/contract.json`.
- `evals/` — prompt cases and a grader for this skill's behaviour.

## Reference Documentation

- [references/focused-fix-methodology.md](references/focused-fix-methodology.md) — principles, decision framework for minimal vs structural fixes, and more anti-patterns.

Files in this skill

  • SKILL.md5.3 KB
  • evals/README.md1 KB
  • evals/grader.py5.9 KB
  • evals/runner.py7.7 KB
  • evals/test_cases.json3.1 KB
  • references/focused-fix-methodology.md3 KB
  • scripts/change_scope_analyzer.py15.6 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in data-ai →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.