Skip to main content
hook official · GitHub

fix-broken-links — GitHub Copilot hook: link checker

This hook checks links in recently edited web files after GitHub Copilot uses a tool. It helps catch dead URLs and vague link labels before they linger in the project.

Install into Claude Code · Manually: put the files in place All methods and platforms ↓
.claude/settings.json
Open on GitHub

What fix-broken-links does

After each GitHub Copilot tool use, the hook scans changed files for absolute http:// and https:// URLs. It tests address variations with www, HTTPS, and a trailing slash; when Copilot CLI is available, it can also ask the agent for replacement ideas. Vague anchor labels are flagged as an SEO issue.

For a broken link, choose a suggested replacement, enter another URL, remove the link wrapper, or skip it. Removing the wrapper preserves visible text for HTML and Markdown links. Agent suggestions are not checked live, so verify them before accepting.

The hook has Bash and PowerShell versions. The Bash version requires curl, grep, sed, jq, and Bash 4+. Copilot CLI is optional and only supplies agent suggestions. Relative URLs are outside its scope; without git, it scans the full repository instead of changed files.

What it helps with

  • find broken URLs in recently edited web files
  • test common URL variations for a working address
  • replace a dead link from an interactive menu
  • flag vague anchor labels as an SEO issue

Example prompts for the agent

  • Check links in the edited docs/guide.md and show replacement options.
  • After updating the page, check its URLs and suggest a fix for any broken link.
  • Find broken links in changed files and flag vague labels such as “click here”.

How to install fix-broken-links

Manually: put the files in place

.claude/settings.json

The hooks block: event (PreToolUse, PostToolUse, Stop…) → command. Personal ones go to ~/.claude/settings.json

Step by step, with commands for each platform: Claude Code hooks: what they are, where to configure them, how to block a risky command

Questions about fix-broken-links

How do I install fix-broken-links in GitHub Copilot?

Add the hook configuration to .claude/settings.json.

What does fix-broken-links do?

It checks absolute HTTP and HTTPS links in edited web files after GitHub Copilot tool use. The hook offers link fixes and flags vague anchor text.

What does fix-broken-links need to run?

The Bash version needs curl, grep, sed, jq, and Bash 4+. Copilot CLI is optional; without it, the hook offers only tested URL variations.

Source text

fix-broken-links · MIT
---
name: 'Fix Broken Links'
description: 'Checks changed web files for broken hyperlinks and SEO anchor issues after each Copilot tool use.'
tags: ['links', 'seo', 'html', 'markdown', 'post-tool-use']
---

# Fix Broken Links Hook

Scans recently-changed web files for broken hyperlinks after each GitHub Copilot
tool use. For each broken URL the hook tries common spelling variations, then hands
the link to the Copilot CLI agent for suggested replacements, and presents an
interactive fix menu. Generic anchor text (`click here`, `read more`, etc.) is
flagged as an SEO issue.

## Overview

Broken links accumulate silently in web projects. Running on the `postToolUse`
event, this hook checks the web files the agent just edited — and only those —
right after each change, so you can fix, replace, or remove each broken link in
the same terminal session.

The hook has two modes:

- **With file paths** (the edited files injected from the hook payload, or paths
  passed on the command line): it checks each link, looks up replacement
  candidates, and presents the interactive fix menu.
- **With no file arguments**: it simply lists the broken links it finds — no
  replacement lookups and no prompts.

## Features

- **Self-contained core**: bash and PowerShell ports — no runtime to install (the optional agent
 hand-off reuses the Copilot CLI you already have)
- **Edited-files scope**: as a `postToolUse` hook it only checks the files the agent just changed —
 never a full repo scan
- **Format-agnostic link scan**: extracts every `http(s)` URL with `grep`, covering HTML, Markdown,
 JS/TS, JSON, CSS, SQL, and templates at once
- **Automatic URL healing**: tries www, https, and trailing-slash variations
- **Agent-assisted suggestions**: hands the broken link to the Copilot CLI agent (a lightweight,
 low-token `gpt-5-mini` prompt with no tools) for replacement candidates; if the CLI is missing or
  errors, it simply offers none
- **SEO audit**: flags anchor text that is too generic to benefit search ranking
- **Large-file guard**: prompts before checking files with more than 50 links
- **Interactive fix menu**: replace with suggestion, enter custom URL, strip tag keeping text, or
 skip
- **Standard tools only**: `curl`, `grep`, `sed` — present on any POSIX system

## Installation

1. Copy the hook folder to your repository:

   ```bash
   cp -r hooks/fix-broken-links .github/hooks/
   ```

2. Make the script executable:

   ```bash
   chmod +x .github/hooks/fix-broken-links/link-fix.sh
   ```

3. Commit the hook configuration to your repository's default branch.

## Configuration

The hook is configured in `hooks.json` to run on the `postToolUse` event:

```json
{
  "version": 1,
  "hooks": {
    "postToolUse": [
      {
        "type": "command",
        "bash": ".github/hooks/fix-broken-links/link-fix.sh",
        "powershell": ".github/hooks/fix-broken-links/link-fix.ps1",
        "cwd": ".",
        "timeoutSec": 120
      }
    ]
  }
}
```

## Supported Source Types

Links are found by scanning each file for `http(s)://` URLs, so the same logic
covers every format that embeds absolute URLs:

| Source | Examples matched |
| --- | --- |
| HTML | `<a href>`, `<img src>`, `<script src>`, `<link href>`, `<iframe src>` |
| Markdown | `[text](url)`, `[text][ref]`, bare `<url>` |
| JS / TS / Vue / Svelte | `fetch()`, `XMLHttpRequest.open()`, jQuery, axios, `href:`/`url:` props |
| JSON / JSONL | any string value that is an absolute URL |
| CSS | `url(...)` |
| SQL | URL literals in query strings |
| Templates | Jinja2, ERB, EJS, Handlebars, Pug |

The `d` (remove) action understands HTML `<a>` wrappers and Markdown `[text](url)`
links specifically, keeping the visible text. Other source types support
`r` (replace) and `c` (custom) via literal URL substitution.

## Fix Options

For each broken link:

| Key | Action |
| --- | --- |
| `r` | Replace with the suggested URL (a working variation, or an agent-proposed alternative) |
| `d` | Strip the link wrapper, keeping the visible text as plain text |
| `c` | Enter a custom replacement URL |
| `s` | Skip |

## Example Output

```text
  Checking 2 link(s) in docs/guide.md ...
    BROKEN (404) https://example.com/old-page

------------------------------------------------------------
  SEO anchor issues (consider descriptive link text)
    docs/guide.md: <a href="https://example.com/old-page">click here</a>

============================================================
  fix-broken-links report
============================================================

  [1] docs/guide.md
    URL : https://example.com/old-page
    HTTP: 404

    r  Replace -> https://example.com/docs/install
    1  Replace -> https://example.com/docs/getting-started
    d  Remove link, keep text
    c  Custom replacement URL
    s  Skip
  > r
    replaced

  1 file(s) updated:
    docs/guide.md
```

With no file arguments (or when the edited file carries no checkable links) the
hook stops after the broken-link list — the menu above is skipped.

## Requirements

- `curl` — HTTP status checks (the hook exits quietly if absent)
- `grep`, `sed` — link extraction (standard on any POSIX system)
- `jq` — required by the bash hook to parse the postToolUse JSON payload and discover edited files
- Bash 4+ (for `link-fix.sh`); on Windows use Git Bash or WSL, or run the PowerShell 7+ port
 `link-fix.ps1`
- `copilot` (GitHub Copilot CLI) — optional; powers the agent-suggested replacements. Without it,
 only verified spelling variations are offered
- `git` is used for changed-file discovery; the hook falls back to a full repo scan without it

## File Structure

```
.github/hooks/fix-broken-links/
├── hooks.json      GitHub Copilot hook configuration
├── link-fix.sh     Bash hook implementation
├── link-fix.ps1    PowerShell 7+ port
└── README.md       This file
```

## Limitations

- Only checks absolute `http://` and `https://` URLs; relative paths require a running server
- Dynamic links generated at runtime from database queries are not detectable from source alone
- When `copilot` suggestions are enabled, broken URLs are sent to the Copilot service as prompt input
- Agent-suggested replacements are model proposals and are not verified live; confirm each before
 accepting
- The `d` (remove) action targets HTML and Markdown link syntax; bare URLs in code are best handled
 with `r` or `c`


```json
{
  "version": 1,
  "hooks": {
    "postToolUse": [
      {
        "type": "command",
        "bash": ".github/hooks/fix-broken-links/link-fix.sh",
        "powershell": ".github/hooks/fix-broken-links/link-fix.ps1",
        "cwd": ".",
        "timeoutSec": 120
      }
    ]
  }
}

```

© github · MIT · github/awesome-copilot

Similar hooks

Everything for SEO and GEO →

From the same set952

The whole set →
agent-safety This rule sets access controls, policy checks, and audit guidance for code built with AI agents. Use it when implementing tool-calling or multi-agent systems. ★ 40,451repo stars session-auto-commit At the end of a GitHub Copilot session, this hook commits changed files and tries to push them to the remote repository. Use it to save session work automatically. ★ 40,451repo stars secrets-scanner Scans the files a Copilot coding agent touched during a session for leaked keys and credentials before they get committed. Useful when the agent edits code fast. ★ 40,451repo stars governance-audit Scans GitHub Copilot prompts for threat patterns before execution. It records events to a local JSON log and stops destructive actions based on governance settings. ★ 40,451repo stars dependency-license-checker A GitHub Copilot hook that scans newly added dependencies at session end and flags copyleft licenses before they get committed. ★ 40,451repo stars Workshop TA Coordinates a group of persistent AI workstreams by routing tasks, reading journals, and surfacing blocks or completed work. Use it to keep a multi-agent workshop organized. ★ 40,451repo stars WG Code Sentinel A GitHub Copilot subagent that reviews code and configs for vulnerabilities and hands you concrete fixes. Useful before a merge or a release. ★ 40,451repo stars WG Code Alchemist Subagent refactors messy code using Clean Code practices and SOLID principles. It helps eliminate code smells, decouple tightly coupled classes, and clarify obscure logic. ★ 40,451repo stars

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor