Generate or update documentation for the current feature branch. Analyzes all changes (commits, diffs) between the feature branch and base branch, then creates or updates docs/features/<index>_<feature-name>/README.md with incremental indexing based on existing feature docs. Use when documenting a feature branch, creating feature documentation from branch changes, or updating existing feature docs after additional commits. <example> Context: User wants to document their feature branch user: "/update-feature-docs" </example> <example> Context: User wants to document changes user: "document this feature branch" </example> <example> Context: User wants to update existing feature docs user: "update the feature docs with my latest changes" </example> <example> Context: User specifies a base branch user: "/update-feature-docs develop" </example>
Generate or update documentation for the current feature branch by analyzing all changes since it diverged from the base branch.
main or master). If on main/master, inform the user and stop.docs/features/ directory should exist. If it doesn't, create it with a README.md index.CURRENT_BRANCH=$(git branch --show-current)
BASE_BRANCH="${1:-main}" # Accept base branch as argument, default to main
If on main or master, tell the user to switch to a feature branch and stop.
Gather all changes:
# All commits on this branch
git log ${BASE_BRANCH}..HEAD --oneline
# All files changed
git diff ${BASE_BRANCH}...HEAD --name-only
# Diff stats
git diff ${BASE_BRANCH}...HEAD --stat
# Full diff for understanding changes
git diff ${BASE_BRANCH}...HEAD
Read ALL changed files to understand the full scope of the feature.
Derive the feature name from the branch name:
feature/user-notifications -> user-notificationsfeat/add-payment-gateway -> add-payment-gatewayfix/login-redirect -> login-redirectmy-awesome-feature -> my-awesome-featureStrip common prefixes: feature/, feat/, fix/, bugfix/, hotfix/, chore/, refactor/.
Check existing feature directories in docs/features/ to determine the next incremental index:
# List existing feature directories
ls -d docs/features/*/ 2>/dev/null
Feature directories follow the pattern <index>_<name> (e.g., 001_user-auth, 002_payment-gateway).
001001, 002, ..., 010, ..., 100If a directory for this feature already exists (matching by feature name, ignoring index), this is an update — use the existing directory and index.
Create or update docs/features/<index>_<feature-name>/README.md with the following sections:
# Feature: <Feature Name (human-readable)>
> Branch: `<branch-name>` | Base: `<base-branch>` | Commits: <count>
## Overview
<What the feature does and why, derived from commit messages and code changes.
1-2 paragraphs maximum.>
## Architecture
<Mermaid diagram showing new/modified components and their interactions.
Use a C4 Component diagram, sequence diagram, or flowchart — whichever best
illustrates the feature.>
## Changes Summary
### New Files
| File | Purpose |
|------|---------|
| `path/to/file` | Description |
### Modified Files
| File | Changes |
|------|---------|
| `path/to/file` | What changed and why |
### Configuration Changes
| Key | Description | Default |
|-----|-------------|---------|
| `ENV_VAR` | What it controls | `value` |
## API Changes
<New or modified endpoints. Include method, path, request/response if applicable.
If no API changes, omit this section.>
| Method | Path | Description |
|--------|------|-------------|
| POST | /api/v1/resource | Creates a new resource |
## Data Model Changes
<New tables, columns, schema modifications, migrations.
If no data model changes, omit this section.>
## Dependencies
<New packages or services added.
If no new dependencies, omit this section.>
| Package | Version | Purpose |
|---------|---------|---------|
| `package-name` | `^1.0.0` | Why it was added |
## Testing
<How to test the feature — key scenarios and commands.>
For updates to existing feature docs:
Update docs/features/README.md to include the new or updated feature:
# Features
| Index | Feature | Description | Branch | Status |
|-------|---------|-------------|--------|--------|
| 001 | [User Auth](001_user-auth/README.md) | Authentication and authorization | `feature/user-auth` | Documented |
| 002 | [Payment Gateway](002_payment-gateway/README.md) | Payment processing integration | `feature/payment-gateway` | Documented |
If the feature already exists in the index, update its description if needed.
Print a summary:
Feature documented: <Feature Name>
Directory: docs/features/<index>_<feature-name>/
Branch: <branch-name> (<N> commits ahead of <base-branch>)
Files analyzed: <N> changed files
Status: [Created | Updated]
mcp__plugin_media-plugin_mermaid__*) to validate diagram syntax001, 002, etc.