diff --git a/scripts/compile.py b/scripts/compile.py index a0787e9..5ba9b3c 100644 --- a/scripts/compile.py +++ b/scripts/compile.py @@ -13,9 +13,17 @@ Usage: from __future__ import annotations +import os + +# Recursion guard — must be set BEFORE claude_agent_sdk imports anything that +# spawns a Claude subprocess. Inner SessionEnd / PreCompact hooks check +# CLAUDE_INVOKED_BY at startup and exit if set, preventing the global hooks +# from triggering flush.py against this process's daily log (which would +# pollute the log with compile metadata and could create a recursion loop). +os.environ["CLAUDE_INVOKED_BY"] = "memoria_compile" + import argparse import asyncio -import os import re import sys from pathlib import Path diff --git a/scripts/lint.py b/scripts/lint.py index 9b6e609..bfc2dc3 100644 --- a/scripts/lint.py +++ b/scripts/lint.py @@ -11,9 +11,15 @@ Usage: from __future__ import annotations +import os + +# Recursion guard — set before any SDK import so global SessionEnd/PreCompact +# hooks see CLAUDE_INVOKED_BY in the nested Claude subprocess's env and exit +# cleanly. See compile.py for full rationale. +os.environ["CLAUDE_INVOKED_BY"] = "memoria_lint" + import argparse import asyncio -import os from pathlib import Path from config import KNOWLEDGE_DIR, REPORTS_DIR, now_iso, today_iso diff --git a/scripts/query.py b/scripts/query.py index 9e87b54..e8c83ae 100644 --- a/scripts/query.py +++ b/scripts/query.py @@ -12,9 +12,15 @@ Usage: from __future__ import annotations +import os + +# Recursion guard — see compile.py for rationale. Set before any SDK import +# so the global SessionEnd/PreCompact hooks see CLAUDE_INVOKED_BY in the +# nested Claude subprocess's env and exit cleanly. +os.environ["CLAUDE_INVOKED_BY"] = "memoria_query" + import argparse import asyncio -import os from pathlib import Path from config import KNOWLEDGE_DIR, QA_DIR, now_iso