-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauto_save_inject.py
More file actions
47 lines (38 loc) · 1.47 KB
/
auto_save_inject.py
File metadata and controls
47 lines (38 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python3
# @bigd-hook-meta
# name: auto_save_inject
# fires_on: PreToolUse
# always_fire: true
# cost_score: 1
"""PreToolUse hook: inject auto-save when marker file exists.
Reads /tmp/claude_auto_save_needed (written by context_50_check.py).
Injects systemMessage telling Claude to run /s (background Haiku agent).
Deletes marker after injection so it only fires once per threshold crossing.
"""
import json
from pathlib import Path
MARKER = Path("/tmp/claude_auto_save_needed")
def main():
if not MARKER.exists():
print("{}")
return
try:
data = json.loads(MARKER.read_text())
pct = data.get("pct", "?")
except (json.JSONDecodeError, OSError):
pct = "?"
# Delete marker so we only inject once
MARKER.unlink(missing_ok=True)
print(json.dumps({
"systemMessage": (
f"CONTEXT AT {pct:.0f}%. Run /s NOW. "
f"1. Set tab title (bash, foreground). "
f"2. Spawn ONE background Agent (model=sonnet, run_in_background=true) to: "
f"write tight convo summary to memory (max 150 words, 3-7 bullets: what changed, decisions, pending — skip narration; do NOT add to MEMORY.md index), file atoms to ~/NardoWorld/. "
f"3. Print 'Saving... /clear' so user can /clear immediately. "
f"4. Then answer the user's message normally. "
f"Do not ask permission. Do this alongside your response."
)
}))
if __name__ == "__main__":
main()