0
prompt 1
claude tarafında özellikle sıkıştırma sonrası oluşan ani tüketim ve benzer memory durumları için nette gezinirken denk geldiğim kodu deneyebilirsiniz:
Add a Claude Code hook that tells me when to /clear vs /compact.
Create ~/.claude/hooks/context-pressure. sh as a UserPromptSubmit hook:
- Read "transcript_path" from stdin JSON, find the last usage record in
that JSONL file (input_tokens + cache_read + cache_creation tokens).
- If the total is over 300K, output:
{"hookSpecificOutput": {"hookEventName": "UserPromptSubmit",
"additionalContext": "<note>"}}
- Note text: tell Claude to, only at a natural stopping point (a verified
unit of work just finished, not mid-task), end its reply with:
1. **CLEAR** or **COMPACT** + one-line why
2. instructions to run that command and paste the note back
3. a handoff note in a code block: goal, what's done, key decisions,
what's ruled out, next step, file paths — written so a Claude with
zero memory of this chat can pick it up cold.
Default to CLEAR (cheaper, sharper than a long summary) unless something
can't be written down (live reasoning chain, unsaved pasted material).
- Fail silently (exit 0) on any error, never block the turn.
Register it in ~/.claude/settings.json under hooks.UserPromptSubmit, 5s
timeout. Make the script executable and test it before confirming done.
Bu promptu denedin mi?
işe yaradı 0
yaramadı 0
-