Set up Olakai monitoring for local Claude Code agents. Configures hooks, creates the agent record, and explains how to enrich events with KPIs. AUTO-INVOKE when user wants to: monitor Claude Code sessions, add observability to local agents, track local AI usage, set up olakai monitoring in this workspace, observe local agent activity, or enable hooks-based monitoring. TRIGGER KEYWORDS: olakai monitor, local agent, monitor claude code, track sessions, local agent monitoring, observe local agent, olakai hooks, olakai monitor init, monitor workspace, local AI tracking, claude code monitoring. DO NOT load for: adding monitoring to custom SDK code (use olakai-integrate), creating agents from scratch with custom code (use olakai-new-project), troubleshooting existing monitoring (use olakai-troubleshoot).
This skill sets up hooks-based monitoring for Claude Code local agents. Once configured, every Claude Code session in this workspace automatically reports activity to Olakai — no SDK code required.
What you get:
What is NOT included yet:
Before starting, verify these requirements:
# 1. CLI installed?
which olakai || echo "CLI_NOT_INSTALLED"
# 2. Authenticated?
olakai whoami 2>/dev/null || echo "NOT_AUTHENTICATED"
| Result | Action |
|---|---|
CLI_NOT_INSTALLED |
Run npm install -g olakai-cli@latest, then olakai login |
NOT_AUTHENTICATED | Run olakai login |
| Shows email/account | Ready to proceed |
Not set up at all? Use
/olakai-get-startedfirst.
You must also be running inside a Claude Code session in a project directory (the workspace where .claude/ lives or will be created).
Run this single command from your project root:
olakai monitor init
What it does:
AgentSource.CLAUDE_CODE on your Olakai account.claude/settings.json.claude/olakai-monitor.json (API key, agent ID, endpoint)The command is interactive — it will prompt for an agent name if one is not provided.
olakai monitor status
Expected output confirms:
.claude/settings.json.claude/olakai-monitor.jsonUse Claude Code normally — write code, debug, refactor, research. Each session automatically sends an event when Claude Code stops (the Stop hook fires).
After completing at least one task, verify events are flowing:
# List recent events for your local agent
olakai activity list --agent-id AGENT_ID --limit 5
Replace AGENT_ID with the ID shown by olakai monitor status.
# 1. Complete a Claude Code task (generates an event via the Stop hook)
# 2. Fetch the latest event
olakai activity list --agent-id AGENT_ID --limit 1 --json
# 3. Inspect it
olakai activity get EVENT_ID --json | jq '{source, customData}'
Confirm:
source is "claude-code"prompt, response, tokens, and modelName are populated (not empty/null)customData contains session metadata (sessionId, numTurns, inputTokens, outputTokens)The Stop hook fires at the end of each Claude Code turn. It reads Claude Code's transcript JSONL file (at transcript_path from the hook event) and extracts:
| Field | Description |
|---|---|
prompt | Last non-meta user message in the session transcript |
response | Last assistant message text (tool-only turns preserve the prior text response) |
chatId | Claude Code session_id — groups all turns of a conversation |
modelName | Model from the last assistant message (e.g., claude-sonnet-4-5) |
tokens | Input (incl. cache_creation + cache_read) + output tokens from last turn's usage |
customData.inputTokens / outputTokens | Last turn's usage broken down |
customData.numTurns | Count of non-sidechain assistant messages in the session |
customData.sessionId / transcriptPath / cwd / stopHookActive / hookEvent | Raw Stop event metadata |
source | Top-level "claude-code" tag |
All of this is captured automatically by the hook. No SDK code or manual instrumentation is needed.
Notes on token counts: Token totals include cache tokens (cache_creation + cache_read) because real Claude Code sessions typically show very high cache-read volume (tens of thousands) vs tiny uncached input. Excluding cache would massively under-report billable volume.
Fields not captured: Claude Code's Stop hook does not expose duration, stop_reason, or total_cost. These are omitted rather than fabricated. If future Claude Code versions expose them via the hook event or transcript, they can be added.
Debug mode: Set OLAKAI_MONITOR_DEBUG=1 in your environment to log the raw stdin payload and constructed monitoring payload to /tmp/olakai-monitor-debug-<pid>.log. Useful when events aren't arriving or look wrong. Turn off when done (no-op by default so hooks stay fast and silent).
Local agent traffic is evaluated by the same KPI system as SDK-monitored agents. New agents automatically receive metric slot KPIs:
| Slot KPI | Output Unit | Description |
|---|---|---|
| Execution Cost | USD | Token-based cost estimate |
| Time Saved | minutes | time_saved_estimator classifier (CHAT scope) |
| Value Created | USD | Time Saved * hourly rate |
| Governance Compliance | % | Policy pass rate |
Plus the composite: ROI = Value Created / Execution Cost.
olakai kpis list --agent-id AGENT_ID
You should see the slot KPIs listed. If the Time Saved classifier is missing (can happen for CLI-created agents), add it manually:
olakai kpis create --name "Time Saved" \
--calculator-id classifier --template-id time_saved_estimator \
--scope CHAT --agent-id AGENT_ID
If you want metrics beyond the defaults, create custom formula-based KPIs. First, register any custom data fields you plan to use:
# Example: track task complexity as a custom field
olakai custom-data create --agent-id AGENT_ID --name "Complexity" --type STRING
# Then create a KPI that uses it
olakai kpis create \
--name "Complex Tasks" \
--agent-id AGENT_ID \
--calculator-id formula \
--formula "IF(Complexity = \"complex\", 1, 0)" \
--aggregation SUM
Classifier templates provide AI-evaluated KPIs without writing formulas. They analyze the full conversation at the CHAT scope:
# List available templates
olakai kpis templates
# Add a sentiment scorer
olakai kpis create --name "Session Sentiment" \
--calculator-id classifier --template-id sentiment_scorer \
--scope CHAT --agent-id AGENT_ID
Note: Classifier KPIs run at CHAT scope, meaning they evaluate the entire session, not individual turns. Results appear after chat decoration processes (there may be a short delay).
olakai monitor status
olakai activity list --agent-id AGENT_ID --limit 10
olakai activity sessions --agent-id AGENT_ID
Sessions with DECORATED status have KPI data populated.
olakai activity kpis --agent-id AGENT_ID --json
Navigate to Agent IQ > Local Agents in the Olakai web dashboard at https://app.olakai.ai to see:
To remove hooks and stop sending events:
olakai monitor disable
What this does:
.claude/settings.json.claude/olakai-monitor.jsonWhat this does NOT do:
To re-enable later, run olakai monitor init again.
olakai monitor status.claude/settings.json contains the Stop hook entry.claude/olakai-monitor.json exists and has a valid API keyexport OLAKAI_MONITOR_DEBUG=1 then do a Claude Code turn. Inspect /tmp/olakai-monitor-debug-<pid>.log to see the raw Stop event from stdin and the constructed monitoring payload.prompt, response, tokens, or modelName are empty/nullThis means the transcript file at transcript_path could not be read or parsed. Common causes:
0.1.15 — earlier versions tried to extract fields directly from the Stop event (which doesn't contain them). Upgrade: npm install -g olakai-cli@latestEnable OLAKAI_MONITOR_DEBUG=1 to see whether transcript reading succeeded. Look for transcript-read-failed or transcript-parsed entries in the debug log.
KPIs must be configured on the agent:
olakai kpis list --agent-id AGENT_ID
If empty, add at minimum the Time Saved classifier:
olakai kpis create --name "Time Saved" \
--calculator-id classifier --template-id time_saved_estimator \
--scope CHAT --agent-id AGENT_ID
The hook is designed to fail silently — errors in the monitoring hook should never interrupt your Claude Code session. If you suspect issues:
cat .claude/olakai-monitor.jsonolakai agents get AGENT_ID --json | jq '.apiKey'olakai whoamiUse /olakai-troubleshoot for comprehensive diagnostics including:
# Setup
olakai monitor init # Initialize monitoring for this workspace
olakai monitor status # Check hook and config status
olakai monitor disable # Remove hooks and config
# View activity
olakai activity list --agent-id AGENT_ID --limit 10
olakai activity get EVENT_ID --json
olakai activity sessions --agent-id AGENT_ID
# KPIs
olakai kpis list --agent-id AGENT_ID
olakai kpis create --calculator-id classifier --template-id time_saved_estimator --scope CHAT --agent-id AGENT_ID
olakai activity kpis --agent-id AGENT_ID --json
# Dashboard
# Agent IQ > Local Agents at https://app.olakai.ai