Loading...
Automatically generates or updates project documentation when session ends
{
"hookConfig": {
"hooks": {
"stop": {
"script": "./.claude/hooks/documentation-auto-generator-on-stop.sh"
}
}
},
"scriptContent": "#!/usr/bin/env bash\n\necho \"📚 Starting documentation generation...\" >&2\n\n# Create docs directory if it doesn't exist\nmkdir -p ./docs\n\n# Generate timestamp for session\nSESSION_DATE=$(date +\"%Y-%m-%d\")\nSESSION_TIME=$(date +\"%H:%M:%S\")\nTIMESTAMP=\"$SESSION_DATE $SESSION_TIME\"\n\n# Count modified files if in git repo\nMODIFIED_COUNT=0\nif command -v git &> /dev/null && git rev-parse --git-dir > /dev/null 2>&1; then\n MODIFIED_COUNT=$(git diff --name-only 2>/dev/null | wc -l | xargs)\nfi\n\necho \"📊 Session summary: $MODIFIED_COUNT files modified\" >&2\n\n# JavaScript/TypeScript projects\nif [ -f \"package.json\" ]; then\n echo \"🟡 JavaScript/TypeScript project detected\" >&2\n \n # Try TypeDoc first for TypeScript projects\n if ls *.ts src/**/*.ts 2>/dev/null | head -1 > /dev/null; then\n if command -v npx &> /dev/null && npx typedoc --version &> /dev/null 2>&1; then\n echo \"📝 Generating TypeDoc documentation...\" >&2\n npx typedoc --out ./docs/api src 2>/dev/null && echo \"✅ TypeDoc documentation generated\" >&2\n else\n echo \"💡 Install TypeDoc for better TypeScript docs: npm install -g typedoc\" >&2\n fi\n fi\n \n # Try JSDoc for JavaScript projects\n if [ -f \"jsdoc.json\" ] || [ -f \"jsdoc.conf.json\" ]; then\n if command -v npx &> /dev/null && npx jsdoc --version &> /dev/null 2>&1; then\n echo \"📝 Generating JSDoc documentation...\" >&2\n npx jsdoc -c jsdoc.json 2>/dev/null || npx jsdoc -c jsdoc.conf.json 2>/dev/null\n [ $? -eq 0 ] && echo \"✅ JSDoc documentation generated\" >&2\n fi\n fi\n \n # Try documentation.js as fallback\n if command -v npx &> /dev/null; then\n if npx documentation --version &> /dev/null 2>&1; then\n echo \"📝 Generating documentation.js docs...\" >&2\n npx documentation build './src/**/*.js' -f md -o ./docs/api.md 2>/dev/null\n [ $? -eq 0 ] && echo \"✅ Documentation.js docs generated\" >&2\n fi\n fi\nfi\n\n# Python projects\nif [ -f \"setup.py\" ] || [ -f \"pyproject.toml\" ] || [ -f \"requirements.txt\" ]; then\n echo \"🐍 Python project detected\" >&2\n \n # Try pdoc for simple API docs\n if command -v pdoc &> /dev/null; then\n echo \"📝 Generating pdoc documentation...\" >&2\n pdoc --html --output-dir ./docs . 2>/dev/null && echo \"✅ pdoc documentation generated\" >&2\n elif command -v python &> /dev/null; then\n if python -c \"import pdoc\" 2>/dev/null; then\n echo \"📝 Generating pdoc documentation...\" >&2\n python -m pdoc --html --output-dir ./docs . 2>/dev/null && echo \"✅ pdoc documentation generated\" >&2\n fi\n fi\n \n # Try Sphinx for comprehensive docs\n if [ -f \"docs/conf.py\" ]; then\n if command -v sphinx-build &> /dev/null; then\n echo \"📝 Building Sphinx documentation...\" >&2\n sphinx-build -b html docs ./docs/_build 2>/dev/null && echo \"✅ Sphinx documentation built\" >&2\n fi\n elif command -v sphinx-quickstart &> /dev/null; then\n echo \"📝 Setting up Sphinx documentation...\" >&2\n PROJECT_NAME=$(basename \"$(pwd)\")\n sphinx-quickstart -q -p \"$PROJECT_NAME\" -a \"Claude\" --ext-autodoc --makefile docs 2>/dev/null\n [ $? -eq 0 ] && echo \"✅ Sphinx project initialized in docs/\" >&2\n fi\nfi\n\n# Go projects\nif [ -f \"go.mod\" ]; then\n echo \"🐹 Go project detected\" >&2\n \n if command -v go &> /dev/null; then\n echo \"📝 Generating Go documentation...\" >&2\n go doc -all > ./docs/api.txt 2>/dev/null && echo \"✅ Go documentation generated\" >&2\n \n # Try godoc if available\n if command -v godoc &> /dev/null; then\n echo \"💡 Run 'godoc -http=:6060' to serve documentation locally\" >&2\n fi\n fi\nfi\n\n# Rust projects\nif [ -f \"Cargo.toml\" ]; then\n echo \"🦀 Rust project detected\" >&2\n \n if command -v cargo &> /dev/null; then\n echo \"📝 Generating Rust documentation...\" >&2\n cargo doc --no-deps --target-dir ./docs/rust 2>/dev/null && echo \"✅ Rust documentation generated\" >&2\n fi\nfi\n\n# Update CHANGELOG.md\necho \"📝 Updating changelog...\" >&2\nCHANGELOG_ENTRY=\"## Session $SESSION_DATE at $SESSION_TIME\\n\\n- Files modified: $MODIFIED_COUNT\\n- Documentation updated automatically\\n- Session completed\\n\\n\"\n\nif [ -f \"CHANGELOG.md\" ]; then\n # Prepend to existing changelog\n echo -e \"$CHANGELOG_ENTRY$(cat CHANGELOG.md)\" > CHANGELOG.md.tmp && mv CHANGELOG.md.tmp CHANGELOG.md\nelse\n # Create new changelog\n echo -e \"# Changelog\\n\\n$CHANGELOG_ENTRY\" > CHANGELOG.md\nfi\n\necho \"✅ Changelog updated\" >&2\n\n# Generate or update README.md if it doesn't exist\nif [ ! -f \"README.md\" ]; then\n echo \"📝 Creating basic README.md...\" >&2\n PROJECT_NAME=$(basename \"$(pwd)\")\n cat > README.md << EOF\n# $PROJECT_NAME\n\nProject documentation generated automatically.\n\n## Documentation\n\nAPI documentation can be found in the \\`docs/\\` directory.\n\n## Last Updated\n\n$TIMESTAMP\nEOF\n echo \"✅ README.md created\" >&2\nfi\n\n# Create documentation index\necho \"📋 Creating documentation index...\" >&2\ncat > ./docs/index.md << EOF\n# Project Documentation\n\nGenerated on: $TIMESTAMP\n\n## Available Documentation\n\nEOF\n\n# List available documentation files\nfind ./docs -name \"*.md\" -o -name \"*.html\" -o -name \"index.html\" 2>/dev/null | while read -r file; do\n echo \"- [$(basename \"$file\")]($(basename \"$file\"))\" >> ./docs/index.md\ndone\n\necho \"\" >&2\necho \"📚 Documentation generation completed!\" >&2\necho \"📁 Check the ./docs/ directory for generated documentation\" >&2\necho \"📋 Documentation index available at ./docs/index.md\" >&2\n\nexit 0"
}.claude/hooks/~/.claude/hooks/{
"hooks": {
"stop": {
"script": "./.claude/hooks/documentation-auto-generator-on-stop.sh"
}
}
}#!/usr/bin/env bash
echo "📚 Starting documentation generation..." >&2
# Create docs directory if it doesn't exist
mkdir -p ./docs
# Generate timestamp for session
SESSION_DATE=$(date +"%Y-%m-%d")
SESSION_TIME=$(date +"%H:%M:%S")
TIMESTAMP="$SESSION_DATE $SESSION_TIME"
# Count modified files if in git repo
MODIFIED_COUNT=0
if command -v git &> /dev/null && git rev-parse --git-dir > /dev/null 2>&1; then
MODIFIED_COUNT=$(git diff --name-only 2>/dev/null | wc -l | xargs)
fi
echo "📊 Session summary: $MODIFIED_COUNT files modified" >&2
# JavaScript/TypeScript projects
if [ -f "package.json" ]; then
echo "🟡 JavaScript/TypeScript project detected" >&2
# Try TypeDoc first for TypeScript projects
if ls *.ts src/**/*.ts 2>/dev/null | head -1 > /dev/null; then
if command -v npx &> /dev/null && npx typedoc --version &> /dev/null 2>&1; then
echo "📝 Generating TypeDoc documentation..." >&2
npx typedoc --out ./docs/api src 2>/dev/null && echo "✅ TypeDoc documentation generated" >&2
else
echo "💡 Install TypeDoc for better TypeScript docs: npm install -g typedoc" >&2
fi
fi
# Try JSDoc for JavaScript projects
if [ -f "jsdoc.json" ] || [ -f "jsdoc.conf.json" ]; then
if command -v npx &> /dev/null && npx jsdoc --version &> /dev/null 2>&1; then
echo "📝 Generating JSDoc documentation..." >&2
npx jsdoc -c jsdoc.json 2>/dev/null || npx jsdoc -c jsdoc.conf.json 2>/dev/null
[ $? -eq 0 ] && echo "✅ JSDoc documentation generated" >&2
fi
fi
# Try documentation.js as fallback
if command -v npx &> /dev/null; then
if npx documentation --version &> /dev/null 2>&1; then
echo "📝 Generating documentation.js docs..." >&2
npx documentation build './src/**/*.js' -f md -o ./docs/api.md 2>/dev/null
[ $? -eq 0 ] && echo "✅ Documentation.js docs generated" >&2
fi
fi
fi
# Python projects
if [ -f "setup.py" ] || [ -f "pyproject.toml" ] || [ -f "requirements.txt" ]; then
echo "🐍 Python project detected" >&2
# Try pdoc for simple API docs
if command -v pdoc &> /dev/null; then
echo "📝 Generating pdoc documentation..." >&2
pdoc --html --output-dir ./docs . 2>/dev/null && echo "✅ pdoc 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 . 2>/dev/null && echo "✅ pdoc documentation generated" >&2
fi
fi
# Try Sphinx for comprehensive docs
if [ -f "docs/conf.py" ]; then
if command -v sphinx-build &> /dev/null; then
echo "📝 Building Sphinx documentation..." >&2
sphinx-build -b html docs ./docs/_build 2>/dev/null && echo "✅ Sphinx documentation built" >&2
fi
elif command -v sphinx-quickstart &> /dev/null; then
echo "📝 Setting up Sphinx documentation..." >&2
PROJECT_NAME=$(basename "$(pwd)")
sphinx-quickstart -q -p "$PROJECT_NAME" -a "Claude" --ext-autodoc --makefile docs 2>/dev/null
[ $? -eq 0 ] && echo "✅ Sphinx project initialized in docs/" >&2
fi
fi
# Go projects
if [ -f "go.mod" ]; then
echo "🐹 Go project detected" >&2
if command -v go &> /dev/null; then
echo "📝 Generating Go documentation..." >&2
go doc -all > ./docs/api.txt 2>/dev/null && echo "✅ Go documentation generated" >&2
# Try godoc if available
if command -v godoc &> /dev/null; then
echo "💡 Run 'godoc -http=:6060' to serve documentation locally" >&2
fi
fi
fi
# Rust projects
if [ -f "Cargo.toml" ]; then
echo "🦀 Rust project detected" >&2
if command -v cargo &> /dev/null; then
echo "📝 Generating Rust documentation..." >&2
cargo doc --no-deps --target-dir ./docs/rust 2>/dev/null && echo "✅ Rust documentation generated" >&2
fi
fi
# Update CHANGELOG.md
echo "📝 Updating changelog..." >&2
CHANGELOG_ENTRY="## Session $SESSION_DATE at $SESSION_TIME\n\n- Files modified: $MODIFIED_COUNT\n- Documentation updated automatically\n- Session completed\n\n"
if [ -f "CHANGELOG.md" ]; then
# Prepend to existing changelog
echo -e "$CHANGELOG_ENTRY$(cat CHANGELOG.md)" > CHANGELOG.md.tmp && mv CHANGELOG.md.tmp CHANGELOG.md
else
# Create new changelog
echo -e "# Changelog\n\n$CHANGELOG_ENTRY" > CHANGELOG.md
fi
echo "✅ Changelog updated" >&2
# Generate or update README.md if it doesn't exist
if [ ! -f "README.md" ]; then
echo "📝 Creating basic README.md..." >&2
PROJECT_NAME=$(basename "$(pwd)")
cat > README.md << EOF
# $PROJECT_NAME
Project documentation generated automatically.
## Documentation
API documentation can be found in the \`docs/\` directory.
## Last Updated
$TIMESTAMP
EOF
echo "✅ README.md created" >&2
fi
# Create documentation index
echo "📋 Creating documentation index..." >&2
cat > ./docs/index.md << EOF
# Project Documentation
Generated on: $TIMESTAMP
## Available Documentation
EOF
# List available documentation files
find ./docs -name "*.md" -o -name "*.html" -o -name "index.html" 2>/dev/null | while read -r file; do
echo "- [$(basename "$file")]($(basename "$file"))" >> ./docs/index.md
done
echo "" >&2
echo "📚 Documentation generation completed!" >&2
echo "📁 Check the ./docs/ directory for generated documentation" >&2
echo "📋 Documentation index available at ./docs/index.md" >&2
exit 0TypeDoc generation fails with 'unable to resolve entry point' configuration error
Create tsconfig.json with explicit include paths or add 'entryPoints' to typedoc.json config. Use 'npx typedoc --entryPoints src/index.ts' to specify entry point directly in command.
CHANGELOG.md grows unbounded as every session appends duplicate timestamp entries
Implement changelog rotation by keeping only last 50 entries or use date-based sections. Archive old entries to CHANGELOG.archive.md when main file exceeds size threshold like 10KB.
Documentation generation completes but docs directory remains empty after stop hook
Check documentation tool exit codes and stderr output for generation failures. Ensure write permissions on docs directory and verify sufficient disk space for generated HTML and asset files.
Sphinx autodoc fails to import modules during documentation build process
Add project root to PYTHONPATH in hook script: 'export PYTHONPATH="${PYTHONPATH}:$(pwd)"'. Install project dependencies in documentation build environment before running sphinx-build command.
Hook execution timeout when building large documentation sets on session stop
Move heavy documentation builds to separate CI job instead of stop hook. Use lightweight generators like pdoc for stop hook, reserving Sphinx or comprehensive builds for scheduled documentation updates.
Loading reviews...
Join our community of Claude power users. No spam, unsubscribe anytime.
Automated accessibility testing and compliance checking for web applications following WCAG guidelines
Automatically generates or updates API documentation when endpoint files are modified
Automatically formats code files after Claude writes or edits them using Prettier, Black, or other formatters