Add a PreClear hook event that fires before /clear wipes context

Status Open
Maintainer reply None cached
Activity 0 comments · opened Sep 17, 2026

Title: Add a PreClear hook event that fires before /clear wipes context

Summary

/clear currently has no associated hook — it instantly wipes the conversation with no chance for
Claude to act first. PreCompact is the closest existing event, but it only fires on /compact
(manual or auto), never on /clear. SessionEnd/SessionStart don't help either: SessionEnd
fires as the old session is already terminating, and SessionStart fires on the new session after
the old context is already gone.

Use case

I keep a standing instruction in my CLAUDE.md that before clearing context, Claude should write a
short handoff note (status / found / open / next) to a project file, so returning to a topic later
doesn't mean re-deriving everything from scratch. Today this only works if I remember to ask for
the note before I type /clear myself — there's no way to make it automatic, because nothing runs
between me pressing /clear and the context actually being gone.

A PreClear hook (mirroring PreCompact's shape) would let a hook run one last action — e.g. have
Claude (or a fixed script) dump conversation state to a file — immediately before the wipe, the same
way PreCompact already does for /compact.

Proposed shape

Same event shape as PreCompact: fires right before /clear executes, with the current transcript/
session id available to the hook, non-blocking is fine (or blocking with a short timeout) — the goal
is "let something run right before the wipe," not to let the hook cancel the clear.

Alternatives considered

  • SessionEnd — too late, the point is to capture something derived from this conversation

before it's gone, and by SessionEnd the session is already tearing down.

  • SessionStart (on the next session) — also too late; the old context is unavailable by then.
  • Manual discipline (write the note, then clear) — works today but requires remembering every time,

which is exactly the kind of thing hooks exist to make durable instead of habitual.

View original on GitHub ↗