Loading...
Generates and sends a comprehensive summary email to the team when session ends
{
"hookConfig": {
"hooks": {
"stop": {
"script": "./.claude/hooks/team-summary-email-generator.sh",
"matchers": [
"*"
]
}
}
},
"scriptContent": "#!/bin/bash\n\necho \"๐ง Team Summary Email Generator - Preparing session summary...\"\necho \"โฐ Session ended: $(date)\"\n\n# Check if email configuration is available\nif [ -z \"$TEAM_EMAIL\" ]; then\n echo \"โน๏ธ TEAM_EMAIL not configured - skipping email summary\"\n echo \"๐ก Set TEAM_EMAIL environment variable to enable team notifications\"\n exit 0\nfi\n\necho \"๐ฌ Team email configured: $TEAM_EMAIL\"\n\n# Check for email service configuration\nEMAIL_METHOD=\"none\"\nif [ -n \"$SENDGRID_API_KEY\" ]; then\n EMAIL_METHOD=\"sendgrid\"\n echo \"๐จ Using SendGrid API for email delivery\"\nelif command -v mail >/dev/null 2>&1; then\n EMAIL_METHOD=\"mail\"\n echo \"๐ฎ Using system mail command for email delivery\"\nelif command -v sendmail >/dev/null 2>&1; then\n EMAIL_METHOD=\"sendmail\"\n echo \"๐ซ Using sendmail for email delivery\"\nelse\n echo \"โ ๏ธ No email service available - install mail command or configure SendGrid\"\n echo \"๐ก Install: apt-get install mailutils (Ubuntu) or brew install mailutils (macOS)\"\n exit 0\nfi\n\necho \"๐ Analyzing session data...\"\n\n# Session metadata\nSESSION_END=$(date)\nSESSION_ID=$(date +%Y%m%d_%H%M%S)\nUSER=$(whoami 2>/dev/null || echo \"developer\")\nHOST=$(hostname 2>/dev/null || echo \"unknown\")\nWORKDIR=$(pwd)\nPROJECT_NAME=$(basename \"$WORKDIR\" 2>/dev/null || echo \"project\")\n\n# Git analysis\nif git rev-parse --git-dir >/dev/null 2>&1; then\n echo \"๐ Analyzing git changes...\"\n \n BRANCH=$(git branch --show-current 2>/dev/null || echo \"unknown\")\n FILES_CHANGED=$(git diff --name-only 2>/dev/null | wc -l | tr -d ' ')\n FILES_LIST=$(git diff --name-only 2>/dev/null | head -10)\n \n # Get detailed diff stats\n DIFF_STATS=$(git diff --stat 2>/dev/null)\n INSERTIONS=$(echo \"$DIFF_STATS\" | tail -1 | grep -oE '[0-9]+ insertion' | grep -oE '[0-9]+' || echo \"0\")\n DELETIONS=$(echo \"$DIFF_STATS\" | tail -1 | grep -oE '[0-9]+ deletion' | grep -oE '[0-9]+' || echo \"0\")\n \n # Recent commits\n RECENT_COMMITS=$(git log --oneline -5 2>/dev/null || echo \"No recent commits\")\nelse\n echo \"โน๏ธ Not a git repository - skipping git analysis\"\n BRANCH=\"N/A\"\n FILES_CHANGED=\"0\"\n FILES_LIST=\"No git repository\"\n INSERTIONS=\"0\"\n DELETIONS=\"0\"\n RECENT_COMMITS=\"No git repository\"\nfi\n\n# Test results analysis\necho \"๐งช Checking test results...\"\nTEST_RESULTS=\"No test results available\"\nif [ -f \"package.json\" ] && grep -q '\"test\"' package.json 2>/dev/null; then\n echo \" โข Running npm test...\"\n if timeout 30 npm test -- --silent --passWithNoTests 2>/dev/null; then\n TEST_RESULTS=\"โ
All tests passed\"\n else\n TEST_RESULTS=\"โ Some tests failed - check logs\"\n fi\nelif command -v pytest >/dev/null 2>&1; then\n echo \" โข Running pytest...\"\n if timeout 30 pytest --tb=no -q 2>/dev/null; then\n TEST_RESULTS=\"โ
All Python tests passed\"\n else\n TEST_RESULTS=\"โ Some Python tests failed\"\n fi\nelif [ -f \"Cargo.toml\" ]; then\n echo \" โข Running cargo test...\"\n if timeout 30 cargo test --quiet 2>/dev/null; then\n TEST_RESULTS=\"โ
All Rust tests passed\"\n else\n TEST_RESULTS=\"โ Some Rust tests failed\"\n fi\nfi\n\n# Build status analysis\necho \"๐๏ธ Checking build status...\"\nBUILD_STATUS=\"No build configuration found\"\nif [ -f \"package.json\" ] && grep -q '\"build\"' package.json 2>/dev/null; then\n echo \" โข Running npm build...\"\n if timeout 60 npm run build >/dev/null 2>&1; then\n BUILD_STATUS=\"โ
Build successful\"\n else\n BUILD_STATUS=\"โ Build failed\"\n fi\nelif [ -f \"Cargo.toml\" ]; then\n echo \" โข Running cargo build...\"\n if timeout 60 cargo build --quiet 2>/dev/null; then\n BUILD_STATUS=\"โ
Cargo build successful\"\n else\n BUILD_STATUS=\"โ Cargo build failed\"\n fi\nfi\n\n# Generate HTML email content\necho \"๐ Generating email content...\"\n\nHTML_CONTENT=$(cat <<EOF\n<!DOCTYPE html>\n<html>\n<head>\n <style>\n body { font-family: Arial, sans-serif; line-height: 1.6; color: #333; }\n .header { background: #f4f4f4; padding: 20px; border-radius: 5px; }\n .section { margin: 20px 0; padding: 15px; border-left: 4px solid #007cba; }\n .stats { background: #f9f9f9; padding: 10px; border-radius: 3px; }\n pre { background: #f5f5f5; padding: 10px; border-radius: 3px; overflow-x: auto; }\n .success { color: #28a745; }\n .error { color: #dc3545; }\n .info { color: #17a2b8; }\n </style>\n</head>\n<body>\n <div class=\"header\">\n <h1>๐ค Claude Code Session Summary</h1>\n <p><strong>Project:</strong> $PROJECT_NAME</p>\n <p><strong>Session ID:</strong> $SESSION_ID</p>\n <p><strong>Completed:</strong> $SESSION_END</p>\n <p><strong>User:</strong> $USER@$HOST</p>\n </div>\n\n <div class=\"section\">\n <h2>๐ Development Statistics</h2>\n <div class=\"stats\">\n <ul>\n <li><strong>Branch:</strong> $BRANCH</li>\n <li><strong>Files Modified:</strong> $FILES_CHANGED</li>\n <li><strong>Lines Added:</strong> $INSERTIONS</li>\n <li><strong>Lines Removed:</strong> $DELETIONS</li>\n </ul>\n </div>\n </div>\n\n <div class=\"section\">\n <h2>๐ Modified Files</h2>\n <pre>$FILES_LIST</pre>\n </div>\n\n <div class=\"section\">\n <h2>๐งช Test Results</h2>\n <p>$TEST_RESULTS</p>\n </div>\n\n <div class=\"section\">\n <h2>๐๏ธ Build Status</h2>\n <p>$BUILD_STATUS</p>\n </div>\n\n <div class=\"section\">\n <h2>๐ Recent Commits</h2>\n <pre>$RECENT_COMMITS</pre>\n </div>\n\n <div class=\"section\">\n <h2>๐ก Next Steps</h2>\n <ul>\n <li>Review changes and test thoroughly</li>\n <li>Update documentation if needed</li>\n <li>Consider code review for significant changes</li>\n <li>Merge changes when ready</li>\n </ul>\n </div>\n\n <hr>\n <p><small>Generated automatically by Claude Code Team Summary Hook</small></p>\n</body>\n</html>\nEOF\n)\n\n# Send email based on available method\nSUBJECT=\"Claude Code Session Summary - $PROJECT_NAME ($SESSION_END)\"\n\necho \"๐ค Sending email via $EMAIL_METHOD...\"\n\ncase \"$EMAIL_METHOD\" in\n \"sendgrid\")\n SENDGRID_PAYLOAD=$(cat <<EOF\n{\n \"personalizations\": [{\n \"to\": [{\"email\": \"$TEAM_EMAIL\"}]\n }],\n \"from\": {\"email\": \"claude@yourdomain.com\", \"name\": \"Claude Code\"},\n \"subject\": \"$SUBJECT\",\n \"content\": [{\n \"type\": \"text/html\",\n \"value\": \"$(echo \"$HTML_CONTENT\" | sed 's/\"/\\\\\"'/g')\"\n }]\n}\nEOF\n )\n \n if curl -X POST \\\n -H \"Authorization: Bearer $SENDGRID_API_KEY\" \\\n -H \"Content-Type: application/json\" \\\n -d \"$SENDGRID_PAYLOAD\" \\\n \"https://api.sendgrid.com/v3/mail/send\" \\\n --silent --show-error 2>/dev/null; then\n echo \"โ
Email sent successfully via SendGrid\"\n else\n echo \"โ Failed to send email via SendGrid\"\n fi\n ;;\n \"mail\")\n echo \"$HTML_CONTENT\" | mail -s \"$SUBJECT\" -a \"Content-Type: text/html\" \"$TEAM_EMAIL\"\n echo \"โ
Email sent via system mail command\"\n ;;\n \"sendmail\")\n {\n echo \"To: $TEAM_EMAIL\"\n echo \"Subject: $SUBJECT\"\n echo \"Content-Type: text/html\"\n echo \"\"\n echo \"$HTML_CONTENT\"\n } | sendmail \"$TEAM_EMAIL\"\n echo \"โ
Email sent via sendmail\"\n ;;\nesac\n\necho \"\"\necho \"๐ก Email Configuration Tips:\"\necho \" โข Set TEAM_EMAIL environment variable\"\necho \" โข For SendGrid: Set SENDGRID_API_KEY\"\necho \" โข For system mail: Install mailutils package\"\necho \" โข Configure SMTP settings in your system\"\n\necho \"\"\necho \"๐ฏ Team summary email generation complete!\"\n\nexit 0"
}.claude/hooks/~/.claude/hooks/{
"hooks": {
"stop": {
"script": "./.claude/hooks/team-summary-email-generator.sh",
"matchers": [
"*"
]
}
}
}#!/bin/bash
echo "๐ง Team Summary Email Generator - Preparing session summary..."
echo "โฐ Session ended: $(date)"
# Check if email configuration is available
if [ -z "$TEAM_EMAIL" ]; then
echo "โน๏ธ TEAM_EMAIL not configured - skipping email summary"
echo "๐ก Set TEAM_EMAIL environment variable to enable team notifications"
exit 0
fi
echo "๐ฌ Team email configured: $TEAM_EMAIL"
# Check for email service configuration
EMAIL_METHOD="none"
if [ -n "$SENDGRID_API_KEY" ]; then
EMAIL_METHOD="sendgrid"
echo "๐จ Using SendGrid API for email delivery"
elif command -v mail >/dev/null 2>&1; then
EMAIL_METHOD="mail"
echo "๐ฎ Using system mail command for email delivery"
elif command -v sendmail >/dev/null 2>&1; then
EMAIL_METHOD="sendmail"
echo "๐ซ Using sendmail for email delivery"
else
echo "โ ๏ธ No email service available - install mail command or configure SendGrid"
echo "๐ก Install: apt-get install mailutils (Ubuntu) or brew install mailutils (macOS)"
exit 0
fi
echo "๐ Analyzing session data..."
# Session metadata
SESSION_END=$(date)
SESSION_ID=$(date +%Y%m%d_%H%M%S)
USER=$(whoami 2>/dev/null || echo "developer")
HOST=$(hostname 2>/dev/null || echo "unknown")
WORKDIR=$(pwd)
PROJECT_NAME=$(basename "$WORKDIR" 2>/dev/null || echo "project")
# Git analysis
if git rev-parse --git-dir >/dev/null 2>&1; then
echo "๐ Analyzing git changes..."
BRANCH=$(git branch --show-current 2>/dev/null || echo "unknown")
FILES_CHANGED=$(git diff --name-only 2>/dev/null | wc -l | tr -d ' ')
FILES_LIST=$(git diff --name-only 2>/dev/null | head -10)
# Get detailed diff stats
DIFF_STATS=$(git diff --stat 2>/dev/null)
INSERTIONS=$(echo "$DIFF_STATS" | tail -1 | grep -oE '[0-9]+ insertion' | grep -oE '[0-9]+' || echo "0")
DELETIONS=$(echo "$DIFF_STATS" | tail -1 | grep -oE '[0-9]+ deletion' | grep -oE '[0-9]+' || echo "0")
# Recent commits
RECENT_COMMITS=$(git log --oneline -5 2>/dev/null || echo "No recent commits")
else
echo "โน๏ธ Not a git repository - skipping git analysis"
BRANCH="N/A"
FILES_CHANGED="0"
FILES_LIST="No git repository"
INSERTIONS="0"
DELETIONS="0"
RECENT_COMMITS="No git repository"
fi
# Test results analysis
echo "๐งช Checking test results..."
TEST_RESULTS="No test results available"
if [ -f "package.json" ] && grep -q '"test"' package.json 2>/dev/null; then
echo " โข Running npm test..."
if timeout 30 npm test -- --silent --passWithNoTests 2>/dev/null; then
TEST_RESULTS="โ
All tests passed"
else
TEST_RESULTS="โ Some tests failed - check logs"
fi
elif command -v pytest >/dev/null 2>&1; then
echo " โข Running pytest..."
if timeout 30 pytest --tb=no -q 2>/dev/null; then
TEST_RESULTS="โ
All Python tests passed"
else
TEST_RESULTS="โ Some Python tests failed"
fi
elif [ -f "Cargo.toml" ]; then
echo " โข Running cargo test..."
if timeout 30 cargo test --quiet 2>/dev/null; then
TEST_RESULTS="โ
All Rust tests passed"
else
TEST_RESULTS="โ Some Rust tests failed"
fi
fi
# Build status analysis
echo "๐๏ธ Checking build status..."
BUILD_STATUS="No build configuration found"
if [ -f "package.json" ] && grep -q '"build"' package.json 2>/dev/null; then
echo " โข Running npm build..."
if timeout 60 npm run build >/dev/null 2>&1; then
BUILD_STATUS="โ
Build successful"
else
BUILD_STATUS="โ Build failed"
fi
elif [ -f "Cargo.toml" ]; then
echo " โข Running cargo build..."
if timeout 60 cargo build --quiet 2>/dev/null; then
BUILD_STATUS="โ
Cargo build successful"
else
BUILD_STATUS="โ Cargo build failed"
fi
fi
# Generate HTML email content
echo "๐ Generating email content..."
HTML_CONTENT=$(cat <<EOF
<!DOCTYPE html>
<html>
<head>
<style>
body { font-family: Arial, sans-serif; line-height: 1.6; color: #333; }
.header { background: #f4f4f4; padding: 20px; border-radius: 5px; }
.section { margin: 20px 0; padding: 15px; border-left: 4px solid #007cba; }
.stats { background: #f9f9f9; padding: 10px; border-radius: 3px; }
pre { background: #f5f5f5; padding: 10px; border-radius: 3px; overflow-x: auto; }
.success { color: #28a745; }
.error { color: #dc3545; }
.info { color: #17a2b8; }
</style>
</head>
<body>
<div class="header">
<h1>๐ค Claude Code Session Summary</h1>
<p><strong>Project:</strong> $PROJECT_NAME</p>
<p><strong>Session ID:</strong> $SESSION_ID</p>
<p><strong>Completed:</strong> $SESSION_END</p>
<p><strong>User:</strong> $USER@$HOST</p>
</div>
<div class="section">
<h2>๐ Development Statistics</h2>
<div class="stats">
<ul>
<li><strong>Branch:</strong> $BRANCH</li>
<li><strong>Files Modified:</strong> $FILES_CHANGED</li>
<li><strong>Lines Added:</strong> $INSERTIONS</li>
<li><strong>Lines Removed:</strong> $DELETIONS</li>
</ul>
</div>
</div>
<div class="section">
<h2>๐ Modified Files</h2>
<pre>$FILES_LIST</pre>
</div>
<div class="section">
<h2>๐งช Test Results</h2>
<p>$TEST_RESULTS</p>
</div>
<div class="section">
<h2>๐๏ธ Build Status</h2>
<p>$BUILD_STATUS</p>
</div>
<div class="section">
<h2>๐ Recent Commits</h2>
<pre>$RECENT_COMMITS</pre>
</div>
<div class="section">
<h2>๐ก Next Steps</h2>
<ul>
<li>Review changes and test thoroughly</li>
<li>Update documentation if needed</li>
<li>Consider code review for significant changes</li>
<li>Merge changes when ready</li>
</ul>
</div>
<hr>
<p><small>Generated automatically by Claude Code Team Summary Hook</small></p>
</body>
</html>
EOF
)
# Send email based on available method
SUBJECT="Claude Code Session Summary - $PROJECT_NAME ($SESSION_END)"
echo "๐ค Sending email via $EMAIL_METHOD..."
case "$EMAIL_METHOD" in
"sendgrid")
SENDGRID_PAYLOAD=$(cat <<EOF
{
"personalizations": [{
"to": [{"email": "$TEAM_EMAIL"}]
}],
"from": {"email": "claude@yourdomain.com", "name": "Claude Code"},
"subject": "$SUBJECT",
"content": [{
"type": "text/html",
"value": "$(echo "$HTML_CONTENT" | sed 's/"/\\"'/g')"
}]
}
EOF
)
if curl -X POST \
-H "Authorization: Bearer $SENDGRID_API_KEY" \
-H "Content-Type: application/json" \
-d "$SENDGRID_PAYLOAD" \
"https://api.sendgrid.com/v3/mail/send" \
--silent --show-error 2>/dev/null; then
echo "โ
Email sent successfully via SendGrid"
else
echo "โ Failed to send email via SendGrid"
fi
;;
"mail")
echo "$HTML_CONTENT" | mail -s "$SUBJECT" -a "Content-Type: text/html" "$TEAM_EMAIL"
echo "โ
Email sent via system mail command"
;;
"sendmail")
{
echo "To: $TEAM_EMAIL"
echo "Subject: $SUBJECT"
echo "Content-Type: text/html"
echo ""
echo "$HTML_CONTENT"
} | sendmail "$TEAM_EMAIL"
echo "โ
Email sent via sendmail"
;;
esac
echo ""
echo "๐ก Email Configuration Tips:"
echo " โข Set TEAM_EMAIL environment variable"
echo " โข For SendGrid: Set SENDGRID_API_KEY"
echo " โข For system mail: Install mailutils package"
echo " โข Configure SMTP settings in your system"
echo ""
echo "๐ฏ Team summary email generation complete!"
exit 0Hook skips email sending with TEAM_EMAIL not configured
Set the TEAM_EMAIL environment variable before starting Claude Code: 'export TEAM_EMAIL=team@example.com'. Add to .bashrc or .zshrc for persistence across sessions.
SendGrid API returns 401 unauthorized error
Verify SENDGRID_API_KEY is valid and has Mail Send permissions. Create API keys at SendGrid dashboard. Test with 'curl' command before troubleshooting hook. Check key isn't expired or revoked.
Email content shows HTML markup instead of formatted text
Your email client may not support HTML rendering. The hook sends multipart emails with HTML content. Check spam folder, or configure email client to render HTML. Use plain text fallback in email settings.
Test and build checks timeout causing incomplete reports
The hook uses 30-60 second timeouts to prevent hanging. For slower builds, adjust timeout values in the script or disable build checks. Results show 'No test results available' on timeout.
Git statistics show zero changes despite file modifications
The hook analyzes uncommitted changes using 'git diff'. Stage or commit changes to see them in git analysis. For committed work, check recent commits section which shows last 5 commits regardless of current diff.
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