Kaizen Plugin — Reference Materials
Date fetched: 2026-02-17
User-Provided Analysis Dimensions (beyond original scope)
- Shortest path to outcome — where is energy and steps being wasted?
- Red herrings — distractions that get chased often but are always just a distraction from the actual solution
- System process interruptions — what system processes interrupted correct paths?
- Missing hooks — what hooks could mould behavior and remove AI overhead by providing details automatically and automating correction?
- MCP-based DuckDB for transcript querying — MotherDuck MCP server provides SQL analytics directly to AI assistants
Claude Code Hooks — Key Facts for Kaizen Analysis
Source: https://code.claude.com/docs/en/hooks-guide.md, https://code.claude.com/docs/en/hooks.md (accessed 2026-02-17)
Hook Events (Full List)
SessionStart— session begins or resumes (matchers: startup, resume, clear, compact)UserPromptSubmit— user submits prompt, before processingPreToolUse— before tool call executes (can block, allow, deny, modify input)PermissionRequest— permission dialog appearsPostToolUse— after tool call succeedsPostToolUseFailure— after tool call failsNotification— Claude sends notification (matchers: permission_prompt, idle_prompt, auth_success, elicitation_dialog)SubagentStart— subagent spawnedSubagentStop— subagent finishesStop— Claude finishes respondingTeammateIdle— agent team teammate about to go idleTaskCompleted— task being marked completedPreCompact— before context compaction (matchers: manual, auto)SessionEnd— session terminates
Hook Types
command— shell command (receives JSON stdin, returns via exit code + stdout/stderr)prompt— single-turn LLM evaluation (Haiku default, returns{ok: true/false, reason})agent— multi-turn subagent with tool access (up to 50 turns, returns same format)
Hook Input (Common Fields)
{
"session_id": "abc123",
"transcript_path": "/path/to/transcript.jsonl",
"cwd": "/path/to/project",
"permission_mode": "default",
"hook_event_name": "PreToolUse",
"tool_name": "Bash",
"tool_input": { "command": "..." }
}
PreToolUse Decision Control
{
"hookSpecificOutput": {
"hookEventName": "PreToolUse",
"permissionDecision": "deny",
"permissionDecisionReason": "Use Glob instead of Bash ls",
"updatedInput": { "command": "modified command" },
"additionalContext": "extra info for Claude"
}
}
Decisions: allow (bypass permission), deny (block + reason to Claude), ask (prompt user)
Key Capabilities for Kaizen
- PreToolUse hooks can deny and redirect — when analysis identifies anti-patterns (e.g., Bash ls), a hook can deny and tell Claude to use the correct tool
- PostToolUseFailure hooks — can inject corrective context after failures
- SubagentStart hooks — can inject context into subagents (e.g., "write research to files, not messages")
- SubagentStop hooks — can validate subagent output quality before accepting
- Stop hooks — can verify completeness before allowing Claude to stop
- SessionStart (compact matcher) — can re-inject critical context lost during compaction
- TeammateIdle hooks — can enforce quality gates before teammates go idle
- TaskCompleted hooks — can enforce completion criteria
- PreCompact hooks — can save state before compaction
Hooks in Skills and Agents (Frontmatter)
Hooks can be defined in skill/agent YAML frontmatter — scoped to component lifecycle:
---
name: secure-operations
hooks:
PreToolUse:
- matcher: "Bash"
hooks:
- type: command
command: "./scripts/security-check.sh"
---
Headless Mode / Agent SDK
Source: https://code.claude.com/docs/en/headless.md (accessed 2026-02-17)
claude -p "prompt"runs non-interactively--output-format jsonreturns structured JSON with session ID--output-format stream-jsonfor real-time streaming--allowedToolsfor auto-approving specific tools--json-schemafor structured output conforming to schema- Can continue conversations with
--continueor--resume <session_id> --append-system-promptadds instructions while keeping defaults
Relevance to Kaizen
Headless mode enables automated transcript analysis pipelines:
# Analyze a transcript with Claude itself
claude -p "Analyze this session for anti-patterns" \
--allowedTools "Read,Grep,Glob" \
--output-format json \
--json-schema '{"type":"object","properties":{"anti_patterns":{"type":"array"}}}'
MotherDuck MCP Server for DuckDB
Source: https://github.com/motherduckdb/mcp-server-motherduck (accessed 2026-02-17)
What It Is
MCP server that gives AI assistants direct SQL access to DuckDB databases. Supports local files, in-memory, S3, and MotherDuck cloud.
Tools Provided
execute_query— execute SQL (DuckDB dialect)list_databases— list all databaseslist_tables— list tables and viewslist_columns— list columns of a table/viewswitch_database_connection— switch to different database (requires --allow-switch-databases)
Claude Code Integration
claude mcp add --scope user duckdb --transport stdio -- \
uvx mcp-server-motherduck --db-path :memory: --read-write --allow-switch-databases
Relevance to Kaizen
Instead of writing custom Python scripts for DuckDB queries, the kaizen plugin could include an MCP server configuration that lets Claude query transcript data directly via SQL during analysis:
SELECT
json_extract_string(line, '$.type') as event_type,
json_extract_string(line, '$.message.content[0].name') as tool_name,
COUNT(*) as frequency
FROM read_ndjson_auto('/path/to/transcripts/*.jsonl')
WHERE json_extract_string(line, '$.type') = 'assistant'
GROUP BY event_type, tool_name
ORDER BY frequency DESC;
This gives the analysis agent SQL querying as a native tool rather than requiring custom scripts.