Skip to content

[Opportunity] Kimi CLI — Hooks & Lifecycle Events System #5

@howardpen9

Description

@howardpen9

Target Project

Kimi CLI (MoonshotAI/kimi-cli)

Related Issue(s)

  • Kimi #1313 — Feature Request: Add Hooks System

What

Implement a hooks system allowing users to run custom scripts at key lifecycle points:

  • PreToolUse / PostToolUse (before/after tool execution)
  • PreMessage / PostMessage (before/after sending to LLM)
  • Notification (task completion, errors)
  • Session lifecycle (start, resume, end)

Why

  • Explicit user request in Kimi #1313
  • Enables: desktop notifications, logging, safety checks, custom integrations
  • Claude Code has hooks but with many bugs (#31469, #31440) — we can learn from their mistakes

Prior Art

Claude Code Hooks (Lessons Learned)

What works:

  • JSON config in settings files
  • Pattern matching on tool names
  • Shell command execution with JSON context on stdin

What breaks (avoid these):

  • Hooks not propagated to subagents (#31469)
  • Non-deterministic execution order (#31440)
  • No timeout on hook scripts (can hang the agent)

Implementation Plan

  1. Define hook points enum (PRE_TOOL, POST_TOOL, NOTIFICATION, etc.)
  2. Add hooks config in kimi config file (YAML/JSON)
  3. Hook runner: spawn subprocess with context on stdin, capture stdout
  4. Hook result handling: allow hooks to block/modify/log
  5. Add timeout per hook (default 10s)
  6. Propagate hooks to subagents
  7. Built-in hooks: desktop notification on task complete

Estimated Effort

Medium (1-2 weeks)

Status

  • Research complete
  • Implementation started
  • PR submitted
  • PR merged

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions