Skip to content
Mastering Claude

Home / A structured installation

A structured installation10 minApplication

Hooks and heartbeat

Lifecycle events trigger hooks on three distinct cadences, SessionStart and SessionEnd form the natural pair for automating the memory protocol, and nightly consolidation remains an operating system scheduled task you build yourself, not a Claude Code mechanism documented under that name.

A hook is an automatic action triggered by the harness on a precise lifecycle event, never a preference the model chooses to follow or not. The table of available events has grown since mid 2026, the figure accompanying this lesson gives the exact count and its measurement date rather than repeating it here.

Three cadences, a natural pair for memory

Hook events do not all fire at the same rate. Some run once per session, SessionStart and SessionEnd. Others run once per turn, such as UserPromptSubmit or Stop. Others still run on every tool call inside the agent loop, PreToolUse and PostToolUse. For the memory protocol described in wiring file based memory to git, SessionStart and SessionEnd form exactly the pair needed: a SessionStart hook triggers the pull before the first read, a SessionEnd hook triggers the commit and the push after the last reply. SessionEnd hooks share a 1.5 second budget between all of them, a push to a remote does not fit in that: it needs an explicit timeout in the hook, which raises the shared budget up to sixty seconds, and a witness file written at the end so the next session checks that the push succeeded rather than assuming it.

{
  "hooks": {
    "SessionStart": [
      { "hooks": [{ "type": "command", "command": "cd ~/memoire && git pull", "timeout": 30 }] }
    ],
    "SessionEnd": [
      { "hooks": [{ "type": "command", "command": "cd ~/memoire && git add notes-du-jour.md && git commit -m sync && git push && date > .dernier-sync-reussi", "timeout": 55 }] }
    ]
  }
}

Two details in this example matter as much as the timeout. First, the git add names the wanted files rather than a git add -A that would sweep the whole folder with no filter, which respects the rule set by the previous lesson of grepping for a secret before any push. Second, the standard output of a SessionStart hook, like that of this git pull, enters the context Claude can read, unlike most other events: a shared folder therefore deserves watching before wiring up this kind of hook. The status line follows the same automatic trigger logic: it can refresh itself at an interval set in seconds, not in milliseconds as an older setting might suggest.

Nightly consolidation stays outside the documented product

An operating system scheduled task, which relaunches Claude in non interactive mode in the middle of the night to consolidate the day's notes, has no documented Anthropic equivalent under this exact name: what the documentation calls scheduled tasks runs inside the desktop application, not through a Windows task or a cron driving the command line tool. The gesture therefore stays to be built yourself, exactly like the previous lesson's protocol, with an explicit anti loop safeguard: the task never relaunches a new session as long as the previous one has not written its end of run witness.

Figure 1

What has measurably changed since mid 2026

33events
counted in the table of available lifecycle hook events
code.claude.com/docs/en/hooks, 2026-09-02
1second
minimum value accepted for the status line's automatic refresh
code.claude.com/docs/en/statusline, 2026-09-02
The table of hook events counted around thirty entries in mid 2026, it counts thirty three at the time of measurement, and the status line's refresh interval is set in seconds, with a minimum of one second.
Figure 2

A day with the memory protocol wired to hooks

Morning
Session opens
The SessionStart hook runs the pull on the memory folder before the first reply.
Daytime
Day's work
PreToolUse and PostToolUse events run on every tool call, without manual intervention.
Evening
Session closes
The SessionEnd hook commits and pushes the notes written since the last pull.
Night
Scheduled task
An operating system trigger, outside the documented product under this name, relaunches a non interactive session to consolidate, with a file lock that refuses any second launch as long as the first has not written its end of run witness.
The timeline shows the four moments where the memory protocol depends on an automatic trigger rather than a manual gesture, from the opening pull to the nightly task's safeguard.
Calibrate it yourself

An administrator adds a SessionEnd hook that runs git push on the memory folder, relaunches Claude Code, works for an hour, then closes the session with the normal exit command. The hook's log shows a successful run.

Write in one sentence what this situation establishes, and in one sentence what it does not establish.

What to remember
  • A hook is an action executed by the harness on a precise event, never a preference the model decides to follow or not.
  • Hook events fall into three cadences, once per session, once per turn, and once per tool call, and SessionStart together with SessionEnd form the natural pair for a memory protocol.
  • The shared 1.5 second budget of SessionEnd hooks is not enough for a remote git push: without an explicit timeout in the hook and without an end of run witness, the push can be cut off with nothing to signal it.
  • The number of available hook events has grown since mid 2026, the exact list is checked against the current documentation, and the status line's automatic refresh interval is set in seconds, not milliseconds.
  • A nightly consolidation relaunched by an operating system scheduled task remains a technique to build yourself, it has no Anthropic documented equivalent under this name.
Do this now

Write in your settings.json a SessionStart hook that runs a pull on your memory folder, a SessionEnd hook that commits and pushes, then open and close a test session to confirm both commands ran successfully.

Check the source

Every datable claim in this lesson links here to the public text behind it. A source that does not open proves nothing.