К основному содержанию
хук официальный · GitHub

fix-broken-links — хук для GitHub Copilot: проверка ссылок

Хук проверяет ссылки в изменённых веб-файлах после действий GitHub Copilot и предлагает исправления. Пригодится, чтобы находить битые URL и общие подписи вроде «нажмите здесь».

Установить в Claude Code · Вручную: положить файлы Все способы и платформы ↓
.claude/settings.json
Открыть на GitHub

Что делает fix-broken-links

После каждого использования инструмента GitHub Copilot хук проверяет изменённые файлы и ищет абсолютные URL http:// и https://. Он проверяет варианты адреса с www, https и завершающим слешем, а при наличии Copilot CLI запрашивает у агента другие варианты. Ссылки с общими подписями хук отмечает как проблему SEO.

Для найденной ссылки можно выбрать предложенную замену, ввести свой адрес, убрать ссылочную обёртку или пропустить её. Удаление обёртки сохраняет видимый текст только для ссылок HTML и Markdown. Предложения агента не проверяются в сети, поэтому их стоит подтвердить перед заменой.

Хук работает с Bash и PowerShell; Bash-версии нужны curl, grep, sed, jq и Bash 4+. Copilot CLI нужен только для вариантов от агента. Относительные пути он не проверяет, а без git вместо изменённых файлов сканирует весь репозиторий.

Какие задачи решает

  • найти битые URL в недавно изменённых веб-файлах
  • подобрать варианты адреса с www или завершающим слешем
  • заменить неработающую ссылку через интерактивное меню
  • отметить общие подписи ссылок как проблему SEO

Примеры запросов агенту

  • Проверь ссылки в изменённом docs/guide.md и покажи варианты исправления.
  • Обнови страницу, затем проверь её URL и предложи замену для неработающей ссылки.
  • Найди битые ссылки в изменённых файлах и отметь подписи вроде «нажмите здесь».

Как установить fix-broken-links

Вручную: положить файлы

.claude/settings.json

Блок hooks: событие (PreToolUse, PostToolUse, Stop…) → команда. Личные — ~/.claude/settings.json

По шагам, с командами для каждой платформы: Хуки Claude Code: что это, где настраивать и как запретить опасную команду

Вопросы о fix-broken-links

Как установить fix-broken-links в GitHub Copilot?

Добавьте настройку хука в .claude/settings.json.

Что делает fix-broken-links?

Проверяет абсолютные HTTP- и HTTPS-ссылки в изменённых веб-файлах после использования инструмента GitHub Copilot. Показывает меню исправлений и отмечает слишком общие подписи ссылок.

Что нужно для работы fix-broken-links?

Для Bash-версии нужны curl, grep, sed, jq и Bash 4+. Copilot CLI необязателен: без него хук предлагает только проверенные варианты написания адреса.

Исходный текст

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

Похожие хуки

Всё по теме «SEO и GEO» →

Из того же набора952

Весь набор →
agent-safety Правило задаёт границы доступа к инструментам, проверки политик и аудит для кода с ИИ-агентами. Пригодится при работе с вызовом инструментов и мультиагентными системами. ★ 40 451звёзд репо session-auto-commit В конце сессии GitHub Copilot хук добавляет изменения в Git, создаёт коммит с отметкой времени и отправляет его в удалённый репозиторий. Это пригодится, если вы хотите сохранять работу автоматически. ★ 40 451звёзд репо secrets-scanner Сканирует изменённые за сессию файлы на утёкшие ключи и пароли перед коммитом. Пригодится, когда агент правит код быстро и легко тащит в него токен. ★ 40 451звёзд репо governance-audit Хук перехватывает промпты к GitHub Copilot и ищет опасные команды до их запуска агентом. Записывает события в локальный JSON-лог и блокирует рискованные действия при строгих настройках. ★ 40 451звёзд репо dependency-license-checker Хук для GitHub Copilot, который в конце сессии агента сканирует новые зависимости и помечает копилефт-лицензии до коммита. ★ 40 451звёзд репо Workshop TA Координирует рабочие столы ИИ-агентов: распределяет задачи, читает журналы и сообщает о блокировках или завершённой работе. Пригодится для командной работы с долгоживущими агентами. ★ 40 451звёзд репо WG Code Sentinel Субагент для GitHub Copilot, который проверяет код и конфигурации на уязвимости и предлагает конкретные исправления. Пригодится перед мержем или релизом. ★ 40 451звёзд репо WG Code Alchemist Субагент переписывает запутанный код по правилам Clean Code и принципам SOLID. Пригодится, когда нужно устранить кодовые запахи и разбить монолитные функции без поломки логики. ★ 40 451звёзд репо

Спонсоры проекта

Компании, которые помогают держать аналитику открытой