From 9a58fe64818033f41f4372d3811c7aeaa7818177 Mon Sep 17 00:00:00 2001 From: P Date: Mon, 9 Mar 2026 16:47:36 -0400 Subject: [PATCH] feat: add SessionStart hook for config check Add a lightweight hook that runs on session start to check if any API keys are configured. Warns users if no config is found and checks file permissions on existing config files. Checks (in order): .claude/last30days.env, ~/.config/last30days/.env, OPENAI_API_KEY env var, SCRAPECREATORS_API_KEY env var. Co-Authored-By: Claude Opus 4.6 --- .claude-plugin/plugin.json | 3 ++- hooks/hooks.json | 16 +++++++++++ hooks/scripts/check-config.sh | 51 +++++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 hooks/hooks.json create mode 100755 hooks/scripts/check-config.sh diff --git a/.claude-plugin/plugin.json b/.claude-plugin/plugin.json index 9e2ecad..e3c35a2 100644 --- a/.claude-plugin/plugin.json +++ b/.claude-plugin/plugin.json @@ -21,5 +21,6 @@ "prompts", "polymarket" ], - "skills": ["./"] + "skills": ["./"], + "hooks": ["./hooks/"] } diff --git a/hooks/hooks.json b/hooks/hooks.json new file mode 100644 index 0000000..cc1220e --- /dev/null +++ b/hooks/hooks.json @@ -0,0 +1,16 @@ +{ + "hooks": { + "SessionStart": [ + { + "matcher": "", + "hooks": [ + { + "type": "command", + "command": "bash ${CLAUDE_PLUGIN_ROOT}/hooks/scripts/check-config.sh", + "timeout": 5 + } + ] + } + ] + } +} diff --git a/hooks/scripts/check-config.sh b/hooks/scripts/check-config.sh new file mode 100755 index 0000000..59ec10d --- /dev/null +++ b/hooks/scripts/check-config.sh @@ -0,0 +1,51 @@ +#!/bin/bash +set -euo pipefail + +# Check if last30days has any configuration source available. +# Priority: .claude/last30days.env > ~/.config/last30days/.env > env vars + +PROJECT_ENV=".claude/last30days.env" +GLOBAL_ENV="$HOME/.config/last30days/.env" + +# Helper: warn if file permissions are too open +check_perms() { + local file="$1" + if [[ ! -f "$file" ]]; then return; fi + local perms + perms=$(stat -f '%Lp' "$file" 2>/dev/null || stat -c '%a' "$file" 2>/dev/null || echo "") + if [[ -n "$perms" && "$perms" != "600" && "$perms" != "400" ]]; then + echo "/last30days: WARNING — $file has permissions $perms (should be 600)." + echo " Fix: chmod 600 $file" + fi +} + +# Check per-project config +if [[ -f "$PROJECT_ENV" ]]; then + check_perms "$PROJECT_ENV" + exit 0 +fi + +# Check global config +if [[ -f "$GLOBAL_ENV" ]]; then + check_perms "$GLOBAL_ENV" + exit 0 +fi + +# Check if OPENAI_API_KEY is set in environment (minimum requirement) +if [[ -n "${OPENAI_API_KEY:-}" ]]; then + exit 0 +fi + +# Check if SCRAPECREATORS_API_KEY is set (also sufficient) +if [[ -n "${SCRAPECREATORS_API_KEY:-}" ]]; then + exit 0 +fi + +# No config found — inform user +cat <<'EOF' +/last30days: No API keys configured. + +Create .claude/last30days.env with your API keys, or create +~/.config/last30days/.env globally. At minimum, SCRAPECREATORS_API_KEY +or OPENAI_API_KEY is required. See the README for setup instructions. +EOF