Langfuse observability integration for Kiro CLI. Automatically traces AI agent activity during terminal coding sessions using Kiro CLI Hooks.
- All 5 Kiro CLI hook types supported (AgentSpawn, UserPromptSubmit, PreToolUse, PostToolUse, Stop)
- Traces grouped by conversation
- Sessions grouped by workspace (cwd)
- Dynamic tagging (tool type, model)
- Completion status scoring
- Non-blocking error handling
| Kiro CLI Hook Type | What it traces |
|---|---|
| AgentSpawn | Agent initialization |
| UserPromptSubmit | User prompts and queries |
| PreToolUse | Tool invocations before execution |
| PostToolUse | Tool results and duration |
| Stop | Agent completion with status scores |
cp -r kiro-cli-langfuse/.kiro/agents/ your-project/.kiro/agents/
cp -r kiro-cli-langfuse/hooks/ your-project/hooks/cd your-project/hooks && npm installcp .env.example .env
# Edit .env with your Langfuse keysGet your keys from Langfuse Cloud or your self-hosted instance.
The hooks are defined in .kiro/agents/langfuse-observer.json. This agent includes "tools": ["*"] so it retains access to all standard Kiro CLI tools (file read/write, bash, etc.) alongside the Langfuse hooks. Switch to this agent in Kiro CLI, or merge the hooks field into your existing agent config:
# Switch to the langfuse-observer agent
/agent swap langfuse-observer
# Or merge hooks into your default agent configKiro CLI triggers hook event
-> Pipes JSON to hook-handler.js via stdin
-> Parses hook_event_name, cwd, prompt, tool_name, etc.
-> Creates/updates Langfuse trace for the conversation
-> Routes to event-specific handler
-> Creates spans, generations, scores in Langfuse
-> Flushes data before exit
Kiro CLI hooks differ from Kiro IDE hooks:
| Kiro IDE | Kiro CLI | |
|---|---|---|
| Hook definition | .kiro/hooks/*.kiro.hook files |
hooks field in .kiro/agents/*.json |
| Hook data | Env vars + stdin | JSON via stdin only |
| Hook types | 10 types (file ops, tasks, manual, etc.) | 5 types (spawn, prompt, pre/post tool, stop) |
| Event names | prompt_submit, agent_stop, etc. |
agentSpawn, userPromptSubmit, etc. |
| Tool names | read, write, shell |
fs_read, fs_write, execute_bash |
- Trace — one per conversation
- Session — grouped by cwd
- Events — agent spawn, agent stop
- Generations — user prompts
- Spans — tool use (pre/post)
- Scores — completion status (0-1)
.kiro/
agents/
langfuse-observer.json # Agent config with hook definitions
hooks/
hook-handler.js # Main entry point
package.json
lib/
langfuse-client.js # Langfuse SDK wrapper
handlers.js # Event-specific handlers
utils.js # Shared utilities
test/
helpers.js # Mock factories
utils.test.js # Utility function tests
handlers.test.js # Hook handler tests
langfuse-client.test.js # Client wrapper tests
e2e.test.js # End-to-end flow tests
integration/
setup.js # Docker test helpers
harness.js # Shared before/after setup
trace-creation.test.js # Trace creation & session tests
hook-flow.test.js # Full hook flow & event tests
scoring.test.js # Completion & custom score tests
docker-compose.test.yml # Langfuse v3 test stack
cd hooks && npm testcp .env.test.example .env.test
docker compose --env-file .env.test -f docker-compose.test.yml up --wait
cd hooks && npm run test:integration
docker compose -f docker-compose.test.yml down -vEdit .kiro/agents/langfuse-observer.json and add a matcher to the preToolUse/postToolUse hooks:
{
"hooks": {
"preToolUse": [
{
"matcher": "fs_write",
"command": "node hooks/hook-handler.js"
}
]
}
}Supported matchers:
fs_writeorwrite— file write toolfs_readorread— file read toolexecute_bashorshell— shell commandsuse_awsoraws— AWS CLI tool@git— all tools from git MCP server@git/status— specific MCP tool*— all tools
Add the hooks field from langfuse-observer.json into your own agent config:
{
"name": "my-agent",
"hooks": {
"agentSpawn": [{ "command": "node hooks/hook-handler.js" }],
"userPromptSubmit": [{ "command": "node hooks/hook-handler.js" }],
"preToolUse": [{ "command": "node hooks/hook-handler.js" }],
"postToolUse": [{ "command": "node hooks/hook-handler.js" }],
"stop": [{ "command": "node hooks/hook-handler.js" }]
}
}