Skip to main content
hooksSource-backedReview first Safety Privacy

Documentation Generator - Hooks

Automatically generates and updates project documentation from code comments, README files, and API definitions. This PostToolUse hook provides real-time documentation generation when code files are modified, supporting multiple programming languages and documentation formats.

by JSONbored·added 2025-09-16·
HarnessClaude Code
Trigger:PostToolUse
Review first review before installing

Open the source and read safety notes before installing.

Citation facts

Source-backed facts for citing this resource, derived directly from the registry — also available as plain text for AI assistants.

Source URLs
https://jsdoc.app/, https://github.com/JSONbored/awesome-claude/blob/main/content/hooks/documentation-generator.mdx
Safety notes
Runs automatically after write/edit tool use and may invoke local documentation generators such as npx jsdoc, jsdoc2md, typedoc, pdoc, pydoc, go doc, or cargo doc., Can write generated documentation under ./docs and may be slow on large source files or projects with expensive documentation tooling.
Privacy notes
Reads modified source, README, Markdown, and package metadata files to count comments, links, functions, classes, and documentation sections., Generated documentation may include source comments, API details, project names, and README content from the local workspace.
Author
JSONbored
Claim status
unclaimed
Last verified
2025-09-16

Decision playbook

Review trust signals before you adopt

Signals are present but mixed. Use the checklist below to confirm the source and operational safety for your environment.

Compare context
Selected

0

Current score

78

Baseline

Delta

No baseline selected

No major trust-signal divergence detected in the current selection.

Source and provenance checks

Complete

Confirm ownership and provenance before trusting install instructions.

  • Source link availableRequired

    Open the canonical repository and verify ownership.

    Done
  • Source provenance statusRequired

    Marked as source-backed.

    Done
  • Metadata reviewed

    Registry metadata indicates a reviewed listing.

    Done

Safety and privacy checks

Complete

Validate risk disclosures before installation or API wiring.

  • Safety notes presentRequired

    Review the listed safety guidance before running commands.

    Done
  • Privacy notes presentRequired

    Review data handling notes before connecting accounts or secrets.

    Done
  • Trust level risk gateRequired

    Trust level does not block evaluation.

    Done

Package and install checks

Needs review

Check package metadata and artifact integrity signals.

  • Install payload available

    Install or copy payload is available for review.

    Done
  • Package verification flag

    No package verification flag provided.

    Pending
  • Checksum metadata

    No checksum provided for downloaded artifact.

    Pending

Compare-driven decision checks

Needs review

Use compare context to validate trade-offs before adoption.

  • Compare tray has multiple entries

    Add at least one more entry to compare trust differences.

    Pending
  • Baseline comparison available

    No baseline peer selected yet.

    Pending
  • Diverging trust signals identified

    No major trust-signal divergence found.

    Pending

Setup at a glance

CLI install

Copy-ready — paste the snippet to get started.

Install command

Provided

Config snippet

Provided

Copy snippet

Provided

Prerequisites

None

Platforms

1 listed

Difficulty

0/100

Adoption plan

Balanced adoption plan

Current risk score 16/100. Use staged verification before broader rollout.

Risk 16

Pre-adoption checks

Validate source and review signals before any execution.

  • Confirm source provenanceRequired

    Source URL/provenance metadata is present.

    Done
  • Confirm metadata review state

    Listing has review metadata.

    Done
  • Verify install payload

    Install/config payload exists and can be inspected.

    Done

Security checks

Confirm safety, privacy, and package integrity signals.

  • Review safety notesRequired

    Safety notes are present.

    Done
  • Review privacy notesRequired

    Privacy notes are present.

    Done
  • Verify package integrity metadata

    No package verification/checksum metadata.

    Pending

Rollout

Adopt in controlled steps based on the selected plan.

  • Run in isolated sandbox firstRequired

    Use a constrained sandbox and observe behavior across multiple tasks.

    Pending
  • Roll out graduallyRequired

    Roll out to a small cohort before wider usage.

    Pending
  • Set monitoring and fallback

    Define rollback path and monitor errors after adoption.

    Pending

Evidence readiness

Evidence readiness matrix · balanced

Required evidence gates are covered (5/6 signals complete).

Risk 15

Source provenance

Present

Source repository/provenance is listed.

Required in this preset

Metadata review

Present

Review metadata is present.

Required in this preset

Safety notes

Present

Safety notes are present.

Required in this preset

Privacy notes

Present

Privacy notes are present.

Optional in this preset

Package integrity

Missing

Package integrity metadata is missing.

Optional in this preset

Install payload

Present

Install payload is available.

Required in this preset

Required evidence gates are covered for this preset.

Decision timeline

Decision timeline · balanced

5/6 steps complete with no blocking gaps for this preset.

Risk 14

triage

Confirm source provenanceRequired

Source/provenance metadata is available.

Done

triage

Check metadata review statusRequired

Review metadata is available.

Done

verify

Review safety notesRequired

Safety notes are available.

Done

verify

Review privacy notes

Privacy notes are available.

Done

verify

Validate package integrity metadata

Package integrity metadata is missing.

Pending

rollout

Verify install payload and commandsRequired

Install payload is available.

Done

No required blockers for this timeline preset.

Safety & privacy surface

Safety & privacy surface

2 safety and 2 privacy notes across 3 risk areas.

3 areas
  • SafetyExecution & processesRuns automatically after write/edit tool use and may invoke local documentation generators such as npx jsdoc, jsdoc2md, typedoc, pdoc, pydoc, go doc, or cargo doc.
  • SafetyLocal filesCan write generated documentation under ./docs and may be slow on large source files or projects with expensive documentation tooling.
  • PrivacyLocal filesReads modified source, README, Markdown, and package metadata files to count comments, links, functions, classes, and documentation sections.
  • PrivacyGeneralGenerated documentation may include source comments, API details, project names, and README content from the local workspace.

Safety notes

  • Runs automatically after write/edit tool use and may invoke local documentation generators such as npx jsdoc, jsdoc2md, typedoc, pdoc, pydoc, go doc, or cargo doc.
  • Can write generated documentation under ./docs and may be slow on large source files or projects with expensive documentation tooling.

Privacy notes

  • Reads modified source, README, Markdown, and package metadata files to count comments, links, functions, classes, and documentation sections.
  • Generated documentation may include source comments, API details, project names, and README content from the local workspace.

Schema details

Install type
cli
Reading time
1 min
Difficulty score
0
Troubleshooting
Yes
Breaking changes
No
Runtime and command metadata
Trigger
PostToolUse
Script language
bash
Script body
#!/usr/bin/env bash

# Read the tool input from stdin
INPUT=$(cat)
TOOL_NAME=$(echo "$INPUT" | jq -r '.tool_name')
FILE_PATH=$(echo "$INPUT" | jq -r '.tool_input.file_path // .tool_input.path // ""')

if [ -z "$FILE_PATH" ]; then
  exit 0
fi

# Check if it's a documentation-relevant file
if [[ "$FILE_PATH" == *.js ]] || [[ "$FILE_PATH" == *.jsx ]] || [[ "$FILE_PATH" == *.ts ]] || [[ "$FILE_PATH" == *.tsx ]] || [[ "$FILE_PATH" == *.py ]] || [[ "$FILE_PATH" == *.go ]] || [[ "$FILE_PATH" == *.rs ]] || [[ "$FILE_PATH" == *README* ]] || [[ "$FILE_PATH" == *.md ]]; then
  echo "📚 Documentation-relevant file detected: $FILE_PATH" >&2

  # Create docs directory if it doesn't exist
  mkdir -p ./docs

  # JavaScript/TypeScript documentation
  if [[ "$FILE_PATH" == *.js ]] || [[ "$FILE_PATH" == *.jsx ]] || [[ "$FILE_PATH" == *.ts ]] || [[ "$FILE_PATH" == *.tsx ]]; then
    echo "🟡 JavaScript/TypeScript file - checking for documentation..." >&2

    # Check for JSDoc comments
    if [ -f "$FILE_PATH" ]; then
      JSDOC_COMMENTS=$(grep -c '/\*\*' "$FILE_PATH" 2>/dev/null || echo "0")
      FUNCTIONS=$(grep -c '^\s*\(function\|const\s.*=>\|class\)' "$FILE_PATH" 2>/dev/null || echo "0")

      echo "📊 Found $JSDOC_COMMENTS JSDoc comments and $FUNCTIONS functions/classes" >&2

      if [ "$JSDOC_COMMENTS" -gt 0 ]; then
        # Try generating JSDoc documentation
        if command -v npx &> /dev/null; then
          if npx jsdoc --version &> /dev/null 2>&1; then
            echo "📝 Generating JSDoc documentation..." >&2
            npx jsdoc "$FILE_PATH" -d ./docs/jsdoc 2>/dev/null && echo "✅ JSDoc documentation generated" >&2
          fi

          # Try jsdoc2md for markdown output
          if npx jsdoc2md --version &> /dev/null 2>&1; then
            echo "📝 Generating Markdown documentation..." >&2
            npx jsdoc2md "$FILE_PATH" > "./docs/$(basename "$FILE_PATH" .js).md" 2>/dev/null && echo "✅ Markdown documentation generated" >&2
          fi
        fi
      else
        echo "💡 Consider adding JSDoc comments to improve documentation coverage" >&2
      fi

      # TypeScript-specific documentation
      if [[ "$FILE_PATH" == *.ts ]] || [[ "$FILE_PATH" == *.tsx ]]; then
        if command -v npx &> /dev/null && npx typedoc --version &> /dev/null 2>&1; then
          echo "📝 Generating TypeDoc documentation..." >&2
          npx typedoc "$FILE_PATH" --out ./docs/typedoc 2>/dev/null && echo "✅ TypeDoc documentation generated" >&2
        else
          echo "💡 Install TypeDoc for comprehensive TypeScript documentation: npm install -g typedoc" >&2
        fi
      fi
    fi

  # Python documentation
  elif [[ "$FILE_PATH" == *.py ]]; then
    echo "🐍 Python file - checking for documentation..." >&2

    if [ -f "$FILE_PATH" ]; then
      DOCSTRINGS=$(grep -c "\"\"\"\|'''" "$FILE_PATH" 2>/dev/null || echo "0")
      FUNCTIONS=$(grep -c '^def\s\|^class\s' "$FILE_PATH" 2>/dev/null || echo "0")

      echo "📊 Found $DOCSTRINGS docstrings and $FUNCTIONS functions/classes" >&2

      # Try generating Python documentation
      if command -v pdoc &> /dev/null; then
        echo "📝 Generating pdoc documentation..." >&2
        pdoc "$FILE_PATH" --html --output-dir ./docs/python 2>/dev/null && echo "✅ Python documentation generated" >&2
      elif command -v python &> /dev/null; then
        if python -c "import pydoc" 2>/dev/null; then
          echo "📝 Generating pydoc documentation..." >&2
          python -m pydoc -w "$FILE_PATH" 2>/dev/null && echo "✅ Python documentation generated" >&2
        fi
      fi

      if [ "$DOCSTRINGS" -eq 0 ] && [ "$FUNCTIONS" -gt 0 ]; then
        echo "💡 Consider adding docstrings to Python functions and classes" >&2
      fi
    fi

  # Go documentation
  elif [[ "$FILE_PATH" == *.go ]]; then
    echo "🐹 Go file - checking for documentation..." >&2

    if [ -f "$FILE_PATH" ] && command -v go &> /dev/null; then
      COMMENTS=$(grep -c '^//\s' "$FILE_PATH" 2>/dev/null || echo "0")
      echo "📊 Found $COMMENTS documentation comments" >&2

      echo "📝 Generating Go documentation..." >&2
      go doc "$FILE_PATH" > "./docs/$(basename "$FILE_PATH" .go).txt" 2>/dev/null && echo "✅ Go documentation generated" >&2
    fi

  # Rust documentation
  elif [[ "$FILE_PATH" == *.rs ]]; then
    echo "🦀 Rust file - checking for documentation..." >&2

    if [ -f "$FILE_PATH" ] && command -v cargo &> /dev/null; then
      DOC_COMMENTS=$(grep -c '^///\|^//!' "$FILE_PATH" 2>/dev/null || echo "0")
      echo "📊 Found $DOC_COMMENTS documentation comments" >&2

      if [ "$DOC_COMMENTS" -gt 0 ]; then
        echo "📝 Generating Rust documentation..." >&2
        cargo doc --no-deps --target-dir ./docs/rust 2>/dev/null && echo "✅ Rust documentation generated" >&2
      else
        echo "💡 Consider adding /// documentation comments to Rust code" >&2
      fi
    fi

  # README and markdown documentation
  elif [[ "$FILE_PATH" == *README* ]] || [[ "$FILE_PATH" == *.md ]]; then
    echo "📝 Markdown file - analyzing documentation structure..." >&2

    if [ -f "$FILE_PATH" ]; then
      HEADERS=$(grep -c '^#' "$FILE_PATH" 2>/dev/null || echo "0")
      CODE_BLOCKS=$(grep -c '^```' "$FILE_PATH" 2>/dev/null || echo "0")
      LINKS=$(grep -c '\[.*\](.*)' "$FILE_PATH" 2>/dev/null || echo "0")

      echo "📊 Document structure: $HEADERS headers, $CODE_BLOCKS code blocks, $LINKS links" >&2

      # Check for common README sections
      if [[ "$FILE_PATH" == *README* ]]; then
        echo "📋 Checking README completeness..." >&2

        REQUIRED_SECTIONS=("Installation" "Usage" "API" "Contributing" "License")
        MISSING_SECTIONS=()

        for section in "${REQUIRED_SECTIONS[@]}"; do
          if ! grep -qi "^#.*$section" "$FILE_PATH"; then
            MISSING_SECTIONS+=("$section")
          fi
        done

        if [ ${#MISSING_SECTIONS[@]} -eq 0 ]; then
          echo "✅ README contains all recommended sections" >&2
        else
          echo "💡 Consider adding these sections: ${MISSING_SECTIONS[*]}" >&2
        fi

        # Check for project metadata
        if [ -f "package.json" ]; then
          PROJECT_NAME=$(jq -r '.name // "unknown"' package.json 2>/dev/null)
          PROJECT_DESC=$(jq -r '.description // ""' package.json 2>/dev/null)

          if ! grep -q "$PROJECT_NAME" "$FILE_PATH"; then
            echo "💡 Consider mentioning project name '$PROJECT_NAME' in README" >&2
          fi
        fi
      fi

      # Check for broken links (basic check)
      if [ "$LINKS" -gt 0 ]; then
        echo "🔗 Found $LINKS links - consider running a link checker" >&2
      fi
    fi
  fi

  # General documentation quality tips
  echo "" >&2
  echo "📋 Documentation Best Practices:" >&2
  echo "   • Add clear function/method descriptions" >&2
  echo "   • Include parameter types and return values" >&2
  echo "   • Provide usage examples in documentation" >&2
  echo "   • Keep README updated with latest changes" >&2

else
  echo "File $FILE_PATH is not relevant for documentation generation, skipping" >&2
fi

exit 0
Full copyable content
{
  "hooks": {
    "postToolUse": {
      "script": "./.claude/hooks/documentation-generator.sh",
      "matchers": [
        "write",
        "edit"
      ]
    }
  }
}

About this resource

Features

  • Real-time documentation generation from code comments with automatic detection of JSDoc 4.0.0+, TSDoc, Python docstrings, Go comments, and Rust documentation comments when code files are modified
  • Multi-language support (JavaScript, TypeScript, Python, Go, Rust) with appropriate documentation generators including JSDoc 4.0.0+, TypeDoc 0.26.0+, pdoc 14.0+, Go doc, and Cargo doc
  • API documentation extraction from JSDoc, docstrings, and comments with automatic API endpoint detection and OpenAPI/Swagger documentation generation
  • README.md analysis and improvement suggestions with completeness checking, required section validation, and project metadata integration
  • Documentation quality and completeness checking with coverage metrics, missing section detection, and documentation best practices validation
  • Integration with popular documentation tools including jsdoc2md for markdown output, TypeDoc for TypeScript, pdoc for Python, and language-specific documentation generators
  • Automatic documentation format detection with intelligent selection of appropriate documentation generator based on file type and project structure
  • Incremental documentation generation with file-level processing to optimize performance and reduce generation time for large codebases

Use Cases

  • Real-time documentation updates during development providing automatic documentation generation when code files are modified, keeping documentation synchronized with code changes
  • API documentation maintenance and generation ensuring API documentation stays current with code changes and automatically extracting API documentation from code comments
  • Code quality improvement through documentation analysis providing documentation quality metrics and suggestions for improving documentation completeness
  • Multi-language project documentation consistency maintaining consistent documentation standards across multiple programming languages in the same project
  • README and project documentation enhancement providing automatic README analysis and suggestions for improving project documentation completeness
  • Development workflow integration seamlessly integrating documentation generation into development workflows without manual intervention or separate documentation steps

Installation

  1. Create hooks directory: mkdir -p .claude/hooks
  2. Create hook file: touch .claude/hooks/documentation-generator.sh
  3. Make executable: chmod +x .claude/hooks/documentation-generator.sh
  4. Add configuration from Hook Configuration section above to .claude/settings.json or ~/.claude/settings.json
  5. Alternative: Use the interactive /hooks command in Claude Code

Config paths

  • Local (not committed): .claude/settings.local.json
  • User settings (global): ~/.claude/settings.json
  • Project-wide (committed): .claude/settings.json

Requirements

  • Claude Code CLI installed
  • Project directory initialized
  • Bash shell available
  • Documentation generator: JSDoc 4.0.0+ (JavaScript), TypeDoc 0.26.0+ (TypeScript), pdoc 14.0+ (Python), Go doc (Go), Cargo doc (Rust), jsdoc2md (optional, for markdown output)
  • jq JSON processor for parsing hook input and package.json (optional but recommended)
  • Runtime environment: Node.js 18+ and npm/yarn/pnpm (for JSDoc/TypeDoc/jsdoc2md) or Python 3.8+ and pip (for pdoc) or Go toolchain (for Go doc) or Rust toolchain (for Cargo doc) depending on project language

Hook Configuration

{
  "hooks": {
    "postToolUse": {
      "script": "./.claude/hooks/documentation-generator.sh",
      "matchers": ["write", "edit"]
    }
  }
}

Hook Script

#!/usr/bin/env bash

# Read the tool input from stdin
INPUT=$(cat)
TOOL_NAME=$(echo "$INPUT" | jq -r '.tool_name')
FILE_PATH=$(echo "$INPUT" | jq -r '.tool_input.file_path // .tool_input.path // ""')

if [ -z "$FILE_PATH" ]; then
  exit 0
fi

# Check if it's a documentation-relevant file
if [[ "$FILE_PATH" == *.js ]] || [[ "$FILE_PATH" == *.jsx ]] || [[ "$FILE_PATH" == *.ts ]] || [[ "$FILE_PATH" == *.tsx ]] || [[ "$FILE_PATH" == *.py ]] || [[ "$FILE_PATH" == *.go ]] || [[ "$FILE_PATH" == *.rs ]] || [[ "$FILE_PATH" == *README* ]] || [[ "$FILE_PATH" == *.md ]]; then
  echo "📚 Documentation-relevant file detected: $FILE_PATH" >&2

  # Create docs directory if it doesn't exist
  mkdir -p ./docs

  # JavaScript/TypeScript documentation
  if [[ "$FILE_PATH" == *.js ]] || [[ "$FILE_PATH" == *.jsx ]] || [[ "$FILE_PATH" == *.ts ]] || [[ "$FILE_PATH" == *.tsx ]]; then
    echo "🟡 JavaScript/TypeScript file - checking for documentation..." >&2

    # Check for JSDoc comments
    if [ -f "$FILE_PATH" ]; then
      JSDOC_COMMENTS=$(grep -c '/\*\*' "$FILE_PATH" 2>/dev/null || echo "0")
      FUNCTIONS=$(grep -c '^\s*\(function\|const\s.*=>\|class\)' "$FILE_PATH" 2>/dev/null || echo "0")

      echo "📊 Found $JSDOC_COMMENTS JSDoc comments and $FUNCTIONS functions/classes" >&2

      if [ "$JSDOC_COMMENTS" -gt 0 ]; then
        # Try generating JSDoc documentation
        if command -v npx &> /dev/null; then
          if npx jsdoc --version &> /dev/null 2>&1; then
            echo "📝 Generating JSDoc documentation..." >&2
            npx jsdoc "$FILE_PATH" -d ./docs/jsdoc 2>/dev/null && echo "✅ JSDoc documentation generated" >&2
          fi

          # Try jsdoc2md for markdown output
          if npx jsdoc2md --version &> /dev/null 2>&1; then
            echo "📝 Generating Markdown documentation..." >&2
            npx jsdoc2md "$FILE_PATH" > "./docs/$(basename "$FILE_PATH" .js).md" 2>/dev/null && echo "✅ Markdown documentation generated" >&2
          fi
        fi
      else
        echo "💡 Consider adding JSDoc comments to improve documentation coverage" >&2
      fi

      # TypeScript-specific documentation
      if [[ "$FILE_PATH" == *.ts ]] || [[ "$FILE_PATH" == *.tsx ]]; then
        if command -v npx &> /dev/null && npx typedoc --version &> /dev/null 2>&1; then
          echo "📝 Generating TypeDoc documentation..." >&2
          npx typedoc "$FILE_PATH" --out ./docs/typedoc 2>/dev/null && echo "✅ TypeDoc documentation generated" >&2
        else
          echo "💡 Install TypeDoc for comprehensive TypeScript documentation: npm install -g typedoc" >&2
        fi
      fi
    fi

  # Python documentation
  elif [[ "$FILE_PATH" == *.py ]]; then
    echo "🐍 Python file - checking for documentation..." >&2

    if [ -f "$FILE_PATH" ]; then
      DOCSTRINGS=$(grep -c "\"\"\"\|'''" "$FILE_PATH" 2>/dev/null || echo "0")
      FUNCTIONS=$(grep -c '^def\s\|^class\s' "$FILE_PATH" 2>/dev/null || echo "0")

      echo "📊 Found $DOCSTRINGS docstrings and $FUNCTIONS functions/classes" >&2

      # Try generating Python documentation
      if command -v pdoc &> /dev/null; then
        echo "📝 Generating pdoc documentation..." >&2
        pdoc "$FILE_PATH" --html --output-dir ./docs/python 2>/dev/null && echo "✅ Python documentation generated" >&2
      elif command -v python &> /dev/null; then
        if python -c "import pydoc" 2>/dev/null; then
          echo "📝 Generating pydoc documentation..." >&2
          python -m pydoc -w "$FILE_PATH" 2>/dev/null && echo "✅ Python documentation generated" >&2
        fi
      fi

      if [ "$DOCSTRINGS" -eq 0 ] && [ "$FUNCTIONS" -gt 0 ]; then
        echo "💡 Consider adding docstrings to Python functions and classes" >&2
      fi
    fi

  # Go documentation
  elif [[ "$FILE_PATH" == *.go ]]; then
    echo "🐹 Go file - checking for documentation..." >&2

    if [ -f "$FILE_PATH" ] && command -v go &> /dev/null; then
      COMMENTS=$(grep -c '^//\s' "$FILE_PATH" 2>/dev/null || echo "0")
      echo "📊 Found $COMMENTS documentation comments" >&2

      echo "📝 Generating Go documentation..." >&2
      go doc "$FILE_PATH" > "./docs/$(basename "$FILE_PATH" .go).txt" 2>/dev/null && echo "✅ Go documentation generated" >&2
    fi

  # Rust documentation
  elif [[ "$FILE_PATH" == *.rs ]]; then
    echo "🦀 Rust file - checking for documentation..." >&2

    if [ -f "$FILE_PATH" ] && command -v cargo &> /dev/null; then
      DOC_COMMENTS=$(grep -c '^///\|^//!' "$FILE_PATH" 2>/dev/null || echo "0")
      echo "📊 Found $DOC_COMMENTS documentation comments" >&2

      if [ "$DOC_COMMENTS" -gt 0 ]; then
        echo "📝 Generating Rust documentation..." >&2
        cargo doc --no-deps --target-dir ./docs/rust 2>/dev/null && echo "✅ Rust documentation generated" >&2
      else
        echo "💡 Consider adding /// documentation comments to Rust code" >&2
      fi
    fi

  # README and markdown documentation
  elif [[ "$FILE_PATH" == *README* ]] || [[ "$FILE_PATH" == *.md ]]; then
    echo "📝 Markdown file - analyzing documentation structure..." >&2

    if [ -f "$FILE_PATH" ]; then
      HEADERS=$(grep -c '^#' "$FILE_PATH" 2>/dev/null || echo "0")
      CODE_BLOCKS=$(grep -c '^```' "$FILE_PATH" 2>/dev/null || echo "0")
      LINKS=$(grep -c '\[.*\](.*)' "$FILE_PATH" 2>/dev/null || echo "0")

      echo "📊 Document structure: $HEADERS headers, $CODE_BLOCKS code blocks, $LINKS links" >&2

      # Check for common README sections
      if [[ "$FILE_PATH" == *README* ]]; then
        echo "📋 Checking README completeness..." >&2

        REQUIRED_SECTIONS=("Installation" "Usage" "API" "Contributing" "License")
        MISSING_SECTIONS=()

        for section in "${REQUIRED_SECTIONS[@]}"; do
          if ! grep -qi "^#.*$section" "$FILE_PATH"; then
            MISSING_SECTIONS+=("$section")
          fi
        done

        if [ ${#MISSING_SECTIONS[@]} -eq 0 ]; then
          echo "✅ README contains all recommended sections" >&2
        else
          echo "💡 Consider adding these sections: ${MISSING_SECTIONS[*]}" >&2
        fi

        # Check for project metadata
        if [ -f "package.json" ]; then
          PROJECT_NAME=$(jq -r '.name // "unknown"' package.json 2>/dev/null)
          PROJECT_DESC=$(jq -r '.description // ""' package.json 2>/dev/null)

          if ! grep -q "$PROJECT_NAME" "$FILE_PATH"; then
            echo "💡 Consider mentioning project name '$PROJECT_NAME' in README" >&2
          fi
        fi
      fi

      # Check for broken links (basic check)
      if [ "$LINKS" -gt 0 ]; then
        echo "🔗 Found $LINKS links - consider running a link checker" >&2
      fi
    fi
  fi

  # General documentation quality tips
  echo "" >&2
  echo "📋 Documentation Best Practices:" >&2
  echo "   • Add clear function/method descriptions" >&2
  echo "   • Include parameter types and return values" >&2
  echo "   • Provide usage examples in documentation" >&2
  echo "   • Keep README updated with latest changes" >&2

else
  echo "File $FILE_PATH is not relevant for documentation generation, skipping" >&2
fi

exit 0

Examples

Documentation Generator Hook Script

Complete hook script that performs automatic documentation generation when code files are modified

#!/usr/bin/env bash
INPUT=$(cat)
FILE_PATH=$(echo "$INPUT" | jq -r '.tool_input.file_path // .tool_input.path // ""')
if [ -z "$FILE_PATH" ]; then
  exit 0
fi
if [[ "$FILE_PATH" == *.js ]] || [[ "$FILE_PATH" == *.ts ]]; then
  echo "JavaScript/TypeScript file detected: $FILE_PATH" >&2
  mkdir -p ./docs
  if command -v npx &> /dev/null && npx jsdoc --version &> /dev/null 2>&1; then
    echo "Generating JSDoc documentation..." >&2
    npx jsdoc "$FILE_PATH" -d ./docs/jsdoc 2>/dev/null && echo "JSDoc documentation generated" >&2
  fi
  if [[ "$FILE_PATH" == *.ts ]]; then
    if command -v npx &> /dev/null && npx typedoc --version &> /dev/null 2>&1; then
      echo "Generating TypeDoc documentation..." >&2
      npx typedoc "$FILE_PATH" --out ./docs/typedoc 2>/dev/null && echo "TypeDoc documentation generated" >&2
    fi
  fi
fi
exit 0

Hook Configuration

Complete hook configuration for .claude/settings.json to enable documentation generation

{
  "hooks": {
    "postToolUse": {
      "script": "./.claude/hooks/documentation-generator.sh",
      "matchers": ["write", "edit"]
    }
  }
}

Markdown Documentation Generation with jsdoc2md

Enhanced hook script using jsdoc2md for markdown output from JSDoc comments

#!/usr/bin/env bash
INPUT=$(cat)
FILE_PATH=$(echo "$INPUT" | jq -r '.tool_input.file_path // .tool_input.path // ""')
if [[ "$FILE_PATH" == *.js ]] || [[ "$FILE_PATH" == *.ts ]]; then
  if command -v npx &> /dev/null; then
    if npx jsdoc2md --version &> /dev/null 2>&1; then
      echo "Generating Markdown documentation..." >&2
      npx jsdoc2md "$FILE_PATH" > "./docs/$(basename "$FILE_PATH" .js).md" 2>/dev/null && echo "Markdown documentation generated" >&2
    fi
  fi
fi
exit 0

Python Documentation Generation with pdoc

Enhanced hook script using pdoc 14.0+ for Python documentation generation

#!/usr/bin/env bash
INPUT=$(cat)
FILE_PATH=$(echo "$INPUT" | jq -r '.tool_input.file_path // .tool_input.path // ""')
if [[ "$FILE_PATH" == *.py ]]; then
  if command -v pdoc &> /dev/null; then
    echo "Generating pdoc documentation..." >&2
    pdoc "$FILE_PATH" --html --output-dir ./docs/python 2>/dev/null && echo "Python documentation generated" >&2
  elif command -v python &> /dev/null; then
    if python -c "import pdoc" 2>/dev/null; then
      echo "Generating pdoc documentation..." >&2
      python -m pdoc --html --output-dir ./docs/python "$FILE_PATH" 2>/dev/null && echo "Python documentation generated" >&2
    fi
  fi
fi
exit 0

README Completeness Analysis

Enhanced hook script for README completeness checking with required section validation

#!/usr/bin/env bash
INPUT=$(cat)
FILE_PATH=$(echo "$INPUT" | jq -r '.tool_input.file_path // .tool_input.path // ""')
if [[ "$FILE_PATH" == *README* ]]; then
  echo "Analyzing README completeness..." >&2
  REQUIRED_SECTIONS=("Installation" "Usage" "API" "Contributing" "License")
  MISSING_SECTIONS=()
  for section in "${REQUIRED_SECTIONS[@]}"; do
    if ! grep -qi "^#.*$section" "$FILE_PATH"; then
      MISSING_SECTIONS+=("$section")
    fi
  done
  if [ ${#MISSING_SECTIONS[@]} -eq 0 ]; then
    echo "README contains all recommended sections" >&2
  else
    echo "Consider adding these sections: ${MISSING_SECTIONS[*]}" >&2
  fi
fi
exit 0

Troubleshooting

Hook runs on every file edit causing slow workflows

Refine matchers to specific extensions: ['write:.js', 'write:.ts', 'edit:.md', 'edit:README']. Use postToolUse with targeted matchers instead of wildcard to reduce unnecessary executions. Consider using file size thresholds to skip small files. Add conditional logic to skip test files.

JSDoc generation fails with 'npx jsdoc not found' error

Check jsdoc availability before running: npx jsdoc --version &> /dev/null before generation. Add npm install -g jsdoc to project setup or include in package.json devDependencies. Verify JSDoc version is 4.0.0+ for latest features. Use local installation: npm install --save-dev jsdoc.

Documentation tools timeout on large codebases

Add timeout limits to each tool execution: timeout 60s npx jsdoc. Process individual files instead of entire directories. Consider incremental documentation generation for changed files only. Use file-level processing to optimize performance. Set resource limits for documentation generation.

TypeDoc fails with module resolution errors in TypeScript

Ensure tsconfig.json exists with proper module settings. Run TypeDoc from project root: npx typedoc --tsconfig ./tsconfig.json. Check for conflicting TypeScript versions between project and TypeDoc. Verify TypeDoc version is 0.26.0+ for latest features. Use explicit entry points: npx typedoc --entryPoints src/index.ts.

Python pdoc generation creates no output for modules

Verify module has init.py if package. Use absolute imports and check PYTHONPATH. Run pdoc with explicit module paths: pdoc --html --output-dir ./docs mymodule rather than file paths. Verify pdoc version is 14.0+ for latest features. Check module structure and imports.

jsdoc2md generates empty markdown files

Verify JSDoc comments are properly formatted with /** */ style. Check jsdoc2md configuration and template settings. Ensure source files contain valid JSDoc comments. Use verbose mode: jsdoc2md --verbose to debug generation issues. Verify file paths and permissions.

Go doc generation fails with package import errors

Run go doc from project root with proper module context. Verify go.mod exists and module is properly configured. Use go doc with package path: go doc ./path/to/package. Check Go version compatibility. Ensure all dependencies are installed: go mod download.

Cargo doc generation takes too long for large Rust projects

Use cargo doc --no-deps to skip dependency documentation. Process only changed files instead of entire project. Set documentation generation timeout limits. Use incremental compilation: cargo doc --target-dir ./docs/rust. Consider running documentation generation in CI/CD instead of real-time.

Source citations

Add this badge to your README

Show that Documentation Generator - Hooks is listed on HeyClaude. Paste this Markdown into your README — it renders the badge and links back to this page.

Listed on HeyClaude
[![Listed on HeyClaude](https://heyclau.de/badge/hooks/documentation-generator.svg)](https://heyclau.de/entry/hooks/documentation-generator)

How it compares

Documentation Generator - Hooks side by side with 3 alternatives on trust, install, platform support, and disclosed safety notes — all from reviewed registry metadata.

Field

Automatically generates and updates project documentation from code comments, README files, and API definitions. This PostToolUse hook provides real-time documentation generation when code files are modified, supporting multiple programming languages and documentation formats.

Open dossier

PostToolUse hook that extracts JSDoc and pydoc comments from modified API endpoint files and generates OpenAPI 3.1.0-compatible YAML documentation on every save.

Open dossier

Automatically generates or updates project documentation when session ends.

Open dossier

Automated documentation coverage analysis with missing docstring detection, API documentation validation, and completeness scoring. This PostToolUse hook automatically checks documentation coverage when code files are modified, providing real-time documentation quality validation during development.

Open dossier
Next steps
Trust
Review statusReviewedMaintainer reviewedReviewedMaintainer reviewedReviewedMaintainer reviewedReviewedMaintainer reviewed
Package trustPackage not verifiedPackage not verifiedPackage not verifiedPackage not verified
Source provenanceSource-backedSource-backedSource-backedSource-backed
Submitter
Install riskReview firstReview firstReview firstReview first
Notes Safety Privacy Safety Privacy Safety Privacy Safety Privacy
Brand
Categoryhookshookshookshooks
Sourcesource-backedsource-backedsource-backedsource-backed
AuthorJSONboredJSONboredJSONboredJSONbored
Added2025-09-162025-09-192025-09-192025-10-19
Platforms
Claude Code
Claude Code
Claude Code
Claude Code
Source repo
Safety notesRuns automatically after write/edit tool use and may invoke local documentation generators such as npx jsdoc, jsdoc2md, typedoc, pdoc, pydoc, go doc, or cargo doc. Can write generated documentation under ./docs and may be slow on large source files or projects with expensive documentation tooling.Runs automatically after write or edit tool calls on route, controller, and API files. Invokes npx swagger-jsdoc or npx jsdoc to generate docs; executes python -m pydoc for Python files. Writes generated documentation files to ./docs/api/ in the project directory.Runs automatically on its configured Claude Code hook event and executes shell logic that can read, modify, or delete files in your project (and may run builds, installs, or network calls); review the script and scope it to expected paths before enabling.Runs automatically on its configured Claude Code hook event and executes shell logic that can read, modify, or delete files in your project (and may run builds, installs, or network calls); review the script and scope it to expected paths before enabling.
Privacy notesReads modified source, README, Markdown, and package metadata files to count comments, links, functions, classes, and documentation sections. Generated documentation may include source comments, API details, project names, and README content from the local workspace.Receives Claude Code hook input (session metadata, file paths, and tool output) and reads local project files; review what the script logs or forwards to external services and keep credentials out of its output.Receives Claude Code hook input (session metadata, file paths, and tool output) and reads local project files; review what the script logs or forwards to external services and keep credentials out of its output.Receives Claude Code hook input (session metadata, file paths, and tool output) and reads local project files; review what the script logs or forwards to external services and keep credentials out of its output.
Prerequisites— none listed— none listed— none listed— none listed
Install
mkdir -p .claude/hooks && touch .claude/hooks/documentation-generator.sh && chmod +x .claude/hooks/documentation-generator.sh
mkdir -p .claude/hooks && touch .claude/hooks/api-endpoint-documentation-generator.sh && chmod +x .claude/hooks/api-endpoint-documentation-generator.sh
mkdir -p .claude/hooks && touch .claude/hooks/documentation-auto-generator-on-stop.sh && chmod +x .claude/hooks/documentation-auto-generator-on-stop.sh
mkdir -p .claude/hooks && touch .claude/hooks/documentation-coverage-checker.sh && chmod +x .claude/hooks/documentation-coverage-checker.sh
Config
{
  "hooks": {
    "postToolUse": {
      "script": "./.claude/hooks/documentation-generator.sh",
      "matchers": [
        "write",
        "edit"
      ]
    }
  }
}
{
  "hooks": {
    "postToolUse": {
      "script": "./.claude/hooks/api-endpoint-documentation-generator.sh",
      "matchers": [
        "write",
        "edit"
      ]
    }
  }
}
{
  "hooks": {
    "stop": {
      "script": "./.claude/hooks/documentation-auto-generator-on-stop.sh"
    }
  }
}
{
  "hooks": {
    "postToolUse": {
      "script": "./.claude/hooks/documentation-coverage-checker.sh",
      "matchers": [
        "write",
        "edit"
      ]
    }
  }
}
Citations
ClaimUnclaimedUnclaimedUnclaimedUnclaimed
Open 4 picks in the interactive comparison tool

Related guides

Signals

Loading live community signals…

More like this, weekly

A short, calm digest of reviewed Claude resources. Unsubscribe any time.