Browse Source

experiment: Add per-project disable via .claude/agentmail.disable

Touch file to disable hook, remove to re-enable.
Only affects receiving - sending still works.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
0xDarkMatter 1 week ago
parent
commit
77c03b210f
3 changed files with 32 additions and 0 deletions
  1. 3 0
      hooks/check-mail.sh
  2. 11 0
      skills/agentmail/SKILL.md
  3. 18 0
      skills/agentmail/scripts/test-mail.sh

+ 3 - 0
hooks/check-mail.sh

@@ -18,6 +18,9 @@ MAIL_DB="$HOME/.claude/mail.db"
 COOLDOWN_FILE="/tmp/agentmail_check_$$"
 COOLDOWN_FILE="/tmp/agentmail_check_$$"
 COOLDOWN_SECONDS=10
 COOLDOWN_SECONDS=10
 
 
+# Skip if disabled for this project
+[ -f ".claude/agentmail.disable" ] && exit 0
+
 # Skip if no database exists yet
 # Skip if no database exists yet
 [ -f "$MAIL_DB" ] || exit 0
 [ -f "$MAIL_DB" ] || exit 0
 
 

+ 11 - 0
skills/agentmail/SKILL.md

@@ -163,6 +163,17 @@ CREATE TABLE messages (
 
 
 All user inputs are sanitized via SQL single-quote escaping. Numeric inputs (IDs, limits) are validated before use.
 All user inputs are sanitized via SQL single-quote escaping. Numeric inputs (IDs, limits) are validated before use.
 
 
+## Per-Project Disable
+
+To disable mail notifications for a specific project:
+
+```bash
+touch .claude/agentmail.disable    # Disable
+rm .claude/agentmail.disable       # Re-enable
+```
+
+Only the hook is disabled - you can still send messages from the project. This is useful for projects where you don't want hook overhead or notification noise.
+
 ## Troubleshooting
 ## Troubleshooting
 
 
 | Issue | Fix |
 | Issue | Fix |

+ 18 - 0
skills/agentmail/scripts/test-mail.sh

@@ -477,6 +477,24 @@ assert_contains "hook fires on first call" "MAIL" "$result1"
 bash "$MAIL_SCRIPT" read >/dev/null 2>&1
 bash "$MAIL_SCRIPT" read >/dev/null 2>&1
 
 
 echo ""
 echo ""
+echo "=== Per-Project Disable ==="
+
+# T52: Hook respects .claude/agentmail.disable
+bash "$MAIL_SCRIPT" send "claude-mods" "disable test" "should not appear" >/dev/null 2>&1
+rm -f /tmp/agentmail_check_* 2>/dev/null
+mkdir -p .claude
+touch .claude/agentmail.disable
+result=$(bash "$HOOK_SCRIPT" 2>&1)
+assert_empty "hook silent when disabled" "$result"
+
+# T53: Hook works again after removing disable file
+rm -f .claude/agentmail.disable
+rm -f /tmp/agentmail_check_* 2>/dev/null
+result=$(bash "$HOOK_SCRIPT" 2>&1)
+assert_contains "hook works after re-enable" "MAIL" "$result"
+bash "$MAIL_SCRIPT" read >/dev/null 2>&1
+
+echo ""
 echo "=== Results ==="
 echo "=== Results ==="
 echo "Passed: $PASS / $TOTAL"
 echo "Passed: $PASS / $TOTAL"
 echo "Failed: $FAIL / $TOTAL"
 echo "Failed: $FAIL / $TOTAL"