Skip to content

Hooks Reference

Codebase Intelligence integrates with AI agents via hooks — events fired by the agent that the CI daemon responds to. The daemon captures agent activity, processes it to extract observations using LLM classification, and injects relevant context back into the agent’s conversation.

All hooks communicate via HTTP POST requests to the daemon’s API endpoints.

Hook EventEndpointWhen FiredPrimary Purpose
SessionStart/api/oak/ci/session-startAgent launchesCreate session, inject initial context
UserPromptSubmit/api/oak/ci/prompt-submitUser sends a promptCreate prompt batch, inject memories/code
PostToolUse/api/oak/ci/post-tool-useAfter each tool runsCapture activity, inject file memories
PostToolUseFailure/api/oak/ci/post-tool-use-failureTool execution failsCapture failed tool activity
Stop/api/oak/ci/stopAgent finishes respondingEnd prompt batch, trigger processing
SessionEnd/api/oak/ci/session-endClean exit (Ctrl+D, /exit)End session, generate summary
SubagentStart/api/oak/ci/subagent-startSubagent spawnedTrack subagent lifecycle
SubagentStop/api/oak/ci/subagent-stopSubagent completesTrack subagent completion
PreCompact/api/oak/ci/pre-compactContext compactionTrack context pressure
Gemini CLI EventOAK EventNotes
SessionStartSessionStartSame name
BeforeAgentUserPromptSubmitProvides prompt
AfterToolPostToolUseProvides tool_name, tool_input, tool_response
AfterAgentStopProvides prompt_response
PreCompressPreCompactBefore history summarization
SessionEndSessionEndSame name
Cursor EventOAK EventNotes
sessionStartSessionStartLowercase convention
beforeSubmitPromptUserPromptSubmitBefore prompt is sent
afterFileEditPostToolUseMaps to tool_name=“Edit”
afterAgentResponsePostToolUseMaps to tool_name=“agent_response”
postToolUsePostToolUseGeneral tool use
stopStopAgent finishes responding
sessionEndSessionEndSession exits
Codex OTel EventHook Action
codex.conversation_startssession-start
codex.user_promptprompt-submit
codex.tool_decisionprompt-submit
codex.tool_resultpost-tool-use

In addition to agent hooks, CI registers feature lifecycle hooks that fire during OAK operations:

Hook EventTriggerPurpose
on_feature_enabledoak feature enable codebase-intelligenceInitialize data dir, constitution, hooks, start daemon
on_feature_disabledoak feature disable codebase-intelligenceStop daemon, remove hooks, clean data
on_pre_removeoak removeCleanup before OAK removal
on_agents_changedoak init with different agentsUpdate agent hook configurations
on_pre_upgradeoak upgradeCreate backup before upgrade (if configured)

The on_pre_upgrade hook automatically creates a backup before oak upgrade applies any changes. This is controlled by the backup.on_upgrade configuration setting (enabled by default).

When triggered, the hook:

  1. Checks if backup.on_upgrade is enabled in the configuration
  2. If enabled, creates a backup using the configured defaults (including the include_activities setting)
  3. Logs success or failure — the upgrade proceeds regardless

To disable pre-upgrade backups:

# In .oak/config.yaml
codebase_intelligence:
backup:
on_upgrade: false

Context is injected into the agent’s conversation via the injected_context field in the hook response.

ConstantValueDescription
INJECTION_MAX_CODE_CHUNKS3Max code snippets per injection
INJECTION_MAX_LINES_PER_CHUNK50Max lines per code chunk
INJECTION_MAX_MEMORIES10Max memories per injection
INJECTION_MAX_SESSION_SUMMARIES5Max session summaries
ConfidenceSimilarity ScoreUsage
high>= 0.75Prompt submit, notify context
medium>= 0.60Post-tool-use file memories
low>= 0.45Not used for injection

Hooks are deduplicated to prevent duplicate processing:

EventDedupe KeyNotes
session-startagent + sourceAllows both claude and cursor calls through
prompt-submitgeneration_id + prompt_hashSecond identical prompt is dropped
post-tool-usetool_use_idExact tool invocation match
stopbatch_idPrevents double-ending the same batch
session-endsession_id onlyOnly one end per session

Hooks are configured in agent-specific settings files. Example for Claude Code:

{
"hooks": {
"SessionStart": [{
"matcher": "",
"hooks": [{
"type": "command",
"command": "/path/to/oak-ci-hook.sh session-start"
}]
}]
}
}

The hook shell script reads JSON from stdin and forwards it to the daemon’s HTTP API.

Terminal window
# Watch daemon logs for hook events
tail -f .oak/ci/daemon.log | grep -E "SESSION-START|PROMPT|TOOL|STOP|SESSION-END"
# Verify injected context
grep "INJECT:" .oak/ci/daemon.log
# Check deduplication
grep "Deduped" .oak/ci/daemon.log