# Fix Bug

> Run when the user says "fix-bug" or asks Codex to automatically debug failing code. First inspect the repository, run the relevant tests, analyze errors, repair common bugs with minimal code changes, rerun verification, and produce a patch-oriented summary.

- Skill: `j945935cy/fix-bug` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds@latest add j945935cy/fix-bug`
- Raw SKILL.md: https://api.skillmd.com/api/skills/j945935cy/fix-bug/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: j945935cy (https://skillmd.com/u/j945935cy)
- Updated: 2026-09-22
- Page: https://skillmd.com/skills/j945935cy/fix-bug

---


# Fix Bug

## Workflow

1. Inspect the workspace before changing files.
   - Run `git status --short` and note existing user changes.
   - Identify the project type and available test commands from files such as `package.json`, `pyproject.toml`, `Cargo.toml`, `go.mod`, `pom.xml`, `Makefile`, or project docs.
   - Prefer the repository's documented commands over guessed commands.

2. Run tests first.
   - Start with the narrowest relevant test command when the user names a feature, file, or error.
   - Otherwise run the main test command for the project.
   - If dependencies are missing or the test command is unclear, inspect configuration and choose the least surprising command. Ask the user only when no reasonable local command exists.

3. Analyze the failure.
   - Read the first actionable error, stack trace, assertion diff, or compiler diagnostic.
   - Trace from the failing test or call site into the implementation.
   - Separate root causes from incidental noise such as formatting warnings or cascading errors.

4. Repair common problems automatically.
   - Fix syntax errors, import or export mistakes, wrong paths, stale names, simple type mismatches, broken selectors, off-by-one logic, incorrect conditionals, async timing mistakes, missing null checks, and failed assertions where the intended behavior is clear.
   - Keep changes minimal and consistent with local style.
   - Add or adjust focused tests when the bug fix changes behavior and the project already has a test pattern for that area.
   - Do not rewrite unrelated code or revert user changes.

5. Verify.
   - Rerun the failing test first.
   - Then run the broader relevant test command when practical.
   - If verification cannot run, record the exact command and blocker.

6. Produce the patch.
   - Show the changed files with `git diff --stat`.
   - Review `git diff` before the final response.
   - Summarize the root cause, the fix, and verification results.

## Command Selection

Use these as fallbacks only when the repository does not document commands:

- JavaScript or TypeScript: `npm test`, `npm run test`, `npm run lint`, or the package manager already used by the lockfile.
- Python: `pytest`, `python -m pytest`, or project-specific tox/nox commands.
- Go: `go test ./...`.
- Rust: `cargo test`.
- .NET: `dotnet test`.
- Java: `mvn test` or `gradle test`.

When a command fails because of sandboxing, network access, dependency installation, or permission limits, request escalation using the normal tool approval flow instead of silently skipping it.

## Final Response

Lead with what was fixed. Include:

- Root cause in one short sentence.
- Files changed.
- Tests or checks run, including failures or blockers.
- Any remaining risk only if it matters.

