Files
2026-09-16 01:47:28 -07:00

31 lines
1.1 KiB
Bash
Executable File

#!/usr/bin/env bash
# PostToolUse hook for the grounding servers (sap-docs, abap-docs,
# sap-released-objects, fiori/ui5 servers, context7, capire) and
# WebSearch/WebFetch: records the time of the last successful consultation.
# The matcher in .claude/settings.json decides WHICH tools count; this script
# only stamps the marker. Drains stdin so the pipe never breaks. Always exits 0.
#
# Marker location, in priority order:
# 1. $SAP_CONSULT_MARKER (test/override hook; never set in normal use)
# 2. $CLAUDE_PROJECT_DIR/.claude/.last-mcp-consult (set by Claude Code)
# 3. <this script>/../../.claude/.last-mcp-consult (fallback)
cat > /dev/null
if [ -n "${SAP_CONSULT_MARKER:-}" ]; then
MARKER="$SAP_CONSULT_MARKER"
else
if [ -n "${CLAUDE_PROJECT_DIR:-}" ] && [ -d "$CLAUDE_PROJECT_DIR" ]; then
REPO="$CLAUDE_PROJECT_DIR"
else
REPO="$(cd "$(dirname "$0")/../.." 2>/dev/null && pwd)" || REPO=""
fi
[ -z "$REPO" ] && exit 0
MARKER="$REPO/.claude/.last-mcp-consult"
fi
mkdir -p "$(dirname "$MARKER")" 2>/dev/null
date +%s > "$MARKER" 2>/dev/null
exit 0