Skip to content

Conversation

@aravhawk
Copy link

Context

Add Claude Code–style lifecycle hooks to the CLI so users can automate actions around key events (session start/end, prompt submit, stop, pre‑compact), plus document the configuration format and add tests.

Implementation

  • Introduced hook types and defaults in CLI config (hooks field), with schema‑safe typing and persistence updates.
  • Added hook config loading/merging so global config and workspace config are combined (project hooks appended after global).
  • Implemented a hook runner that executes command hooks with JSON stdin, respects timeouts, and supports “block” decisions.
  • Wired hooks into the CLI lifecycle:
    • SessionStart/SessionEnd in cli.ts
    • UserPromptSubmit in the message handler
    • PreCompact before condense
    • Stop when completion is detected
  • Added tests for config parsing/merging and runner behavior; updated persistence expectations.

Note: PreToolUse, PostToolUse, PermissionRequest, and Notification are supported in config but intentionally not wired yet.

Screenshots

before after
N/A N/A

How to Test

  • cd cli && pnpm test src/hooks/__tests__/config.test.ts src/hooks/__tests__/runner.test.ts src/config/__tests__/persistence.test.ts
  • Manual sanity check:
    • Add a hook to ~/.kilocode/cli/config.json (or <workspace>/.kilocode/cli/config.json):
      {
        "hooks": {
          "Stop": [
            {
              "matcher": "",
              "hooks": [{ "type": "command", "command": "afplay /System/Library/Sounds/Glass.aiff" }]
            }
          ]
        }
      }
    • Run a short CLI task and confirm the command fires on completion.

Get in Touch

Discord: aravhawk

Enable lifecycle hook configuration and execution so users can automate CLI workflows.
Build SessionEnd hook input without undefined optional values to satisfy exact optional types.
@changeset-bot
Copy link

changeset-bot bot commented Jan 23, 2026

🦋 Changeset detected

Latest commit: d5baa08

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@kilocode/cli Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@Coldaine
Copy link

Picking this up for a bit of review as I am very much interested in the same area. I will follow up with my comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants