Phase 1: Discovery (CLI Startup)
Every time the CLI starts, it scans$PATH for binaries matching entire-agent-<name>.
info: The CLI calls this command once per discovered binary. It reads your metadata, validates the protocol version, and registers the agent. If this fails, the CLI skips the agent.
Phase 2: Enable (entire enable)
When a user enables your agent for a repository:
detect: The CLI calls this command to check whether your agent is available in the current environment.install-hooks [--local-dev] [--force]: The CLI calls this command to install your hooks into the agent, such as by writing hook configuration files. It calls this command only when you declare thehookscapability.
Phase 3: Agent Session (Hooks Firing)
After you enable the agent, its hooks fire during normal usage and the CLI processes them. This phase requires thehooks capability. Agents that don’t declare it won’t participate in the hook lifecycle.
Every hook invocation follows this flow:
parse-hook --hook <name>: The CLI calls this command on every hook invocation with the raw payload on stdin. Return a normalized Event, ornullif the hook has no lifecycle significance and the CLI should take no action.
SessionStart (Type 1)
The agent fires this event when it begins a new session.get-session-id: Extract the session ID from the hook input (stdin).get-session-dir --repo-path <path>: Return where sessions are stored.resolve-session-file --session-dir <dir> --session-id <id>: Resolve the session file path.read-session: Read existing session data (stdin: HookInput).write-session: Persist updated session data.write-hook-response --message <msg>: (optional, ifhook_response_writercapability) Write a startup message in your agent’s native format.
TurnStart (Type 2)
The agent fires this event when the user submits a new prompt.extract-modified-files --path <path> --offset <n>: (iftranscript_analyzercapability) Extract files changed since last checkpoint.- The CLI creates a git checkpoint of the current state.
TurnEnd (Type 3)
The agent fires this event when it finishes responding.prepare-transcript --session-ref <path>: (iftranscript_preparercapability) Prepare the transcript.read-transcript --session-ref <path>: Read the raw transcript bytes.chunk-transcript --max-size <n>: Split large transcripts into storable chunks.get-transcript-position --path <path>: (iftranscript_analyzercapability) Get the current byte offset.extract-modified-files --path <path> --offset <n>: (iftranscript_analyzercapability) Extract newly modified files.calculate-tokens --offset <n>: (iftoken_calculatorcapability) Calculate token usage.- The CLI stores a checkpoint in git history.
Compaction (Type 4)
The agent fires this event when it compresses its context window. The CLI follows the same flow as TurnEnd and saves the checkpoint before resetting the offset.SessionEnd (Type 5)
The agent fires this event when the session ends. The CLI creates a final checkpoint and cleans up session state.SubagentStart / SubagentEnd (Types 6 and 7)
The agent fires these events when it spawns or completes a subagent. If you declare thesubagent_aware_extractor capability, the CLI calls:
extract-all-modified-files --offset <n> --subagents-dir <dir>calculate-total-tokens --offset <n> --subagents-dir <dir>
Phase 4: User Commands
Some CLI commands invoke your integration outside the hook flow:Phase 5: Disable (entire disable --uninstall)
uninstall-hooks: The CLI calls this command to remove your installed hooks when you declare thehookscapability.
Error Handling
- Timeout: Each subcommand has a default timeout of 30 seconds.
- Output limits: The CLI caps stdout and stderr at 10 MB each. Account for this limit when you implement
read-transcriptfor large sessions. - No retries: The CLI does not retry failed subcommand calls. It treats a nonzero exit code with a message on stderr as a failure.
- Graceful degradation: If
parse-hookreturnsnull, the CLI takes no action. If the repo has Entire disabled, hooks exit silently.