An agent lifecycle hook runs a configured action at a defined point in an agent’s execution. Unlike a Git hook, which fires on a repository event such as a commit or push, an agent lifecycle hook fires on an event inside the agent’s run, such as session start, session end, a tool call, pre-compact, or stop. section 5.6.5
Hooks provide a way to enforce an action that an instruction alone may not reliably produce. An agent can drift or skip an instruction in AGENTS.md under token pressure. A pre-compact hook addresses a particularly quiet failure: compaction can preserve conclusions while losing the reasoning behind them, leaving the agent confident but missing important context. section 5.6.5
Preserve decisions before compaction
Use a pre-compact hook to enforce a write to a running log of decisions, constraints, and changes in reasoning. Prevent the agent from rereading its own notes in the session that produced them, so it does not compound an earlier mistake. The log remains available to a person, a later session, or another agent picking up the work. section 5.6.5
Hooks can also be packaged in agentic plugins alongside skills, commands, subagent definitions, and MCP configurations. This lets a team distribute a versioned workflow as one unit. Lifecycle event names and coverage vary across agent tools, so check what the chosen tool exposes before relying on a particular hook. section 3.3.6 section 5.6.5
