memoria/scripts
agent-admin b57ce15fff fix: prevent global hooks from firing inside SDK-spawned Claude subprocesses
Discovered during Memoria Phase 4 first compile run: when compile.py
invokes claude_agent_sdk.query(), the spawned `claude` subprocess
inherits the global ~/.claude/settings.json hook config. Its
SessionEnd hook then fires when the subprocess wraps up, triggering
flush.py against today's daily log — polluting the log with compile
metadata and creating a soft recursion (every compile call also
generates a flush call).

flush.py already had this guard (CLAUDE_INVOKED_BY=memory_flush set
at module top before any SDK import). compile.py / query.py / lint.py
did not.

Add the same guard to the other three SDK call sites with
script-specific sentinel values:
  - compile.py → memoria_compile
  - query.py   → memoria_query
  - lint.py    → memoria_lint

The sentinel value doesn't matter — both session-end.py and
pre-compact.py check `if os.environ.get("CLAUDE_INVOKED_BY"): exit(0)`,
so any non-empty value short-circuits. Using distinct sentinels makes
diagnostics clearer if a hook trace ever shows it.

Verified: imports clean, all 29 acceptance tests still pass.
2026-04-24 18:29:29 -04:00
..
compile.py fix: prevent global hooks from firing inside SDK-spawned Claude subprocesses 2026-04-24 18:29:29 -04:00
config.py config: default timezone → America/Indiana/Indianapolis 2026-04-24 17:56:32 -04:00
flush.py fork: MIT LICENSE + foundation patches (atomicity, locking, safety) 2026-04-24 17:44:07 -04:00
fs_utils.py fork: MIT LICENSE + foundation patches (atomicity, locking, safety) 2026-04-24 17:44:07 -04:00
lint.py fix: prevent global hooks from firing inside SDK-spawned Claude subprocesses 2026-04-24 18:29:29 -04:00
query.py fix: prevent global hooks from firing inside SDK-spawned Claude subprocesses 2026-04-24 18:29:29 -04:00
utils.py fork: MIT LICENSE + foundation patches (atomicity, locking, safety) 2026-04-24 17:44:07 -04:00