Update Markdown file index
Scan a target Markdown document and a source folder, derive descriptions from discovered files, then replace or add a consistent file index with valid relative links and stable ordering.
When to invoke
- "Update this README with a table of files in
docs/."
- "Refresh the markdown file index section."
- "Create a list of scripts from this folder."
- "Add a contents table for these Markdown files."
- "Regenerate the directory index without changing the rest of the document."
Inputs
Use $ARGUMENTS or the user request to identify the target Markdown file, source folder, and optional glob pattern. If a pattern is absent, infer a safe default from the request such as *.md for documentation indexes or all regular files for generic folder indexes.
Placeholder mapping
Legacy prompt placeholders map directly to runtime inputs: ${file} is the target Markdown file, ${input:folder} is the scanned folder, and ${input:pattern} is the optional glob. The result may be an index/table, table/index, categorized sub-tables, or another best-fit structure using file type/category and other file-related metadata.
Procedure
- Read the target Markdown file to understand heading levels, existing sections, comments, and style.
- List files in the specified folder matching the requested pattern.
- Extract file metadata: name, type, description, optional size, and optional modified date.
- Detect an existing index section by heading, table columns, file-link list, or HTML comment marker.
- Choose the smallest format that matches the document: simple list, detailed table, or categorized sections.
- Replace the existing section or insert a new section at the appropriate heading level.
- Validate Markdown syntax, links, escaping, sort order, and preservation of surrounding content.
Section identification
| Signal |
Match examples |
Action |
| Heading text |
"index", "files", "contents", "directory", "list" |
Treat the heading subtree as the candidate replacement. |
| File table |
Columns such as File, Type, Description, Size, Modified |
Preserve column intent when regenerating rows. |
| File-link list |
Bullets containing [filename.ext](path/to/filename.ext) |
Replace only the contiguous file-list block. |
| HTML marker |
Comments such as <!-- file index --> or generated-section markers |
Prefer marker bounds over heading heuristics. |
File analysis
| Field |
Extraction rule |
Fallback |
| Name |
Use the filename with extension unless the surrounding document omits extensions. |
Preserve the existing convention. |
| Type |
Use extension and category, for example .md, .js, .py, or Extension. |
file when no extension exists. |
| Description |
First Markdown heading, first meaningful comment, shebang purpose, package metadata, or inferred filename purpose. |
Short inferred description in sentence case. |
| Size |
Include only if the existing index includes size or the user asks. |
Omit. |
| Modified |
Include only if the existing index includes dates or the user asks. |
Omit. |
Table structure options
Simple list
## Files in <folder>
- [filename.ext](path/to/filename.ext) - Description
- [filename2.ext](path/to/filename2.ext) - Description
Detailed table
| File | Type | Description |
|------|------|-------------|
| [filename.ext](path/to/filename.ext) | Extension | Description |
| [filename2.ext](path/to/filename2.ext) | Extension | Description |
Categorized sections
Group files by type, feature area, or folder when a flat table is too noisy. Keep each category alphabetized.
Update rules
- Preserve existing Markdown structure, heading levels, frontmatter, comments, prose, and document flow outside the index block.
- Use repository-relative or target-file-relative links consistently with the surrounding document.
- Sort files alphabetically by default; use natural order when filenames contain numbered prefixes.
- Escape
| in table cells and handle spaces, parentheses, and other special characters in filenames.
- Do not include directories unless the user asks for directory entries.
- Do not invent descriptions that claim behavior not visible from file names or contents.
Output template
## Markdown file index result
**Status:** updated | created | blocked
**Target file:** `<file>`
**Source folder:** `<folder>`
**Pattern:** `<pattern>`
**Format:** simple list | detailed table | categorized sections
### Files indexed
| File | Type | Description |
| --- | --- | --- |
| `<relative/path>` | `<extension or category>` | <description> |
### Validation
- Existing section found: yes | no
- Relative links valid: pass | fail
- Markdown table/list syntax valid: pass | fail
Quality gate
1---2name: update-markdown-file-index3description: Update a Markdown file with an index, list, or table of files from a specified folder, preserving existing document structure and relative links. Use when the user asks to index a folder in Markdown, refresh a file table, list docs or scripts in a README, or maintain a contents section from filesystem files.4---56<!-- Generated from harness/github-copilot/skills/update-markdown-file-index/SKILL.md by harness/claude-code/scripts/convert_from_copilot.py. Edit the source, not this file. -->78# Update Markdown file index910Scan a target Markdown document and a source folder, derive descriptions from discovered files, then replace or add a consistent file index with valid relative links and stable ordering.1112## When to invoke1314- "Update this README with a table of files in `docs/`."15- "Refresh the markdown file index section."16- "Create a list of scripts from this folder."17- "Add a contents table for these Markdown files."18- "Regenerate the directory index without changing the rest of the document."1920## Inputs2122Use `$ARGUMENTS` or the user request to identify the target Markdown file, source folder, and optional glob pattern. If a pattern is absent, infer a safe default from the request such as `*.md` for documentation indexes or all regular files for generic folder indexes.2324## Placeholder mapping2526Legacy prompt placeholders map directly to runtime inputs: `${file}` is the target Markdown file, `${input:folder}` is the scanned folder, and `${input:pattern}` is the optional glob. The result may be an `index/table`, `table/index`, categorized `sub-tables`, or another `best-fit` structure using file `type/category` and other `file-related` metadata.27## Procedure28291. Read the target Markdown file to understand heading levels, existing sections, comments, and style.302. List files in the specified folder matching the requested pattern.313. Extract file metadata: name, type, description, optional size, and optional modified date.324. Detect an existing index section by heading, table columns, file-link list, or HTML comment marker.335. Choose the smallest format that matches the document: simple list, detailed table, or categorized sections.346. Replace the existing section or insert a new section at the appropriate heading level.357. Validate Markdown syntax, links, escaping, sort order, and preservation of surrounding content.3637## Section identification3839| Signal | Match examples | Action |40| --- | --- | --- |41| Heading text | "index", "files", "contents", "directory", "list" | Treat the heading subtree as the candidate replacement. |42| File table | Columns such as `File`, `Type`, `Description`, `Size`, `Modified` | Preserve column intent when regenerating rows. |43| File-link list | Bullets containing `[filename.ext](path/to/filename.ext)` | Replace only the contiguous file-list block. |44| HTML marker | Comments such as `<!-- file index -->` or generated-section markers | Prefer marker bounds over heading heuristics. |4546## File analysis4748| Field | Extraction rule | Fallback |49| --- | --- | --- |50| Name | Use the filename with extension unless the surrounding document omits extensions. | Preserve the existing convention. |51| Type | Use extension and category, for example `.md`, `.js`, `.py`, or `Extension`. | `file` when no extension exists. |52| Description | First Markdown heading, first meaningful comment, shebang purpose, package metadata, or inferred filename purpose. | Short inferred description in sentence case. |53| Size | Include only if the existing index includes size or the user asks. | Omit. |54| Modified | Include only if the existing index includes dates or the user asks. | Omit. |5556## Table structure options5758### Simple list5960```markdown61## Files in <folder>6263- [filename.ext](path/to/filename.ext) - Description64- [filename2.ext](path/to/filename2.ext) - Description65```6667### Detailed table6869```markdown70| File | Type | Description |71|------|------|-------------|72| [filename.ext](path/to/filename.ext) | Extension | Description |73| [filename2.ext](path/to/filename2.ext) | Extension | Description |74```7576### Categorized sections7778Group files by type, feature area, or folder when a flat table is too noisy. Keep each category alphabetized.7980## Update rules8182- Preserve existing Markdown structure, heading levels, frontmatter, comments, prose, and document flow outside the index block.83- Use repository-relative or target-file-relative links consistently with the surrounding document.84- Sort files alphabetically by default; use natural order when filenames contain numbered prefixes.85- Escape `|` in table cells and handle spaces, parentheses, and other special characters in filenames.86- Do not include directories unless the user asks for directory entries.87- Do not invent descriptions that claim behavior not visible from file names or contents.8889## Output template9091```markdown92## Markdown file index result9394**Status:** updated | created | blocked95**Target file:** `<file>`96**Source folder:** `<folder>`97**Pattern:** `<pattern>`98**Format:** simple list | detailed table | categorized sections99100### Files indexed101| File | Type | Description |102| --- | --- | --- |103| `<relative/path>` | `<extension or category>` | <description> |104105### Validation106- Existing section found: yes | no107- Relative links valid: pass | fail108- Markdown table/list syntax valid: pass | fail109```110111## Quality gate112113- [ ] The target Markdown file was read before editing.114- [ ] The source folder and pattern were resolved from the user request or `$ARGUMENTS`.115- [ ] Existing index markers, headings, tables, or file-link lists were reused when present.116- [ ] File links are relative, valid, and consistently formatted.117- [ ] Files are sorted alphabetically or by justified natural order.118- [ ] Surrounding Markdown content outside the index block was preserved.119- [ ] Generated descriptions are grounded in file content, comments, headers, or conservative filename inference.