feat: add hooks system for CLI event interception#11029
Merged
Conversation
Adds a Claude Code-compatible hooks system that allows external handlers (shell commands, HTTP endpoints) to intercept and respond to CLI events. Supports 16 event types with regex-based matching, typed inputs/outputs, sync/async execution, and multi-source config merging. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The fireHook.ts module references services.hooks, which requires the HookService to be registered in the service container and exposed in the services object. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
3 issues found across 6 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="extensions/cli/src/hooks/hookRunner.ts">
<violation number="1" location="extensions/cli/src/hooks/hookRunner.ts:89">
P2: Using `data.toString()` per chunk corrupts multi-byte UTF-8 characters split across buffer boundaries. Set encoding on the streams so Node's internal `StringDecoder` handles this correctly.
(Based on your team's feedback about setting encoding to "utf8" on stdout/stderr streams instead of using `toString()` per 'data' event.) [FEEDBACK_USED]</violation>
<violation number="2" location="extensions/cli/src/hooks/hookRunner.ts:98">
P1: Missing error handler on `child.stdin` — if the child process closes its stdin pipe before the write completes, the unhandled `'error'` event on the stdin stream can crash the Node.js process.</violation>
<violation number="3" location="extensions/cli/src/hooks/hookRunner.ts:149">
P2: Regex `\$\{?(\w+)\}?` incorrectly matches unbalanced braces (e.g., `$FOO}` consumes the `}` even without an opening `{`). Use alternation to properly handle both `${VAR}` and `$VAR` forms.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
Fix unused imports, import ordering, and negated condition lint errors. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When a hook command exits before we finish writing to stdin, an EPIPE error is emitted. Add an error handler to suppress it gracefully. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
1 issue found across 1 file (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="extensions/cli/src/hooks/hookRunner.ts">
<violation number="1" location="extensions/cli/src/hooks/hookRunner.ts:98">
P2: The new stdin error handler ignores every error, not just EPIPE as intended; this masks unexpected write failures.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
The hookRunner tests use /bin/sh syntax (>&2, single-quote echo, sleep) that is incompatible with Windows cmd.exe. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Use setEncoding("utf8") on stdout/stderr instead of data.toString()
to prevent multi-byte character corruption at buffer boundaries
- Fix env var interpolation regex to use alternation instead of
independent optionals, preventing unbalanced brace matching
- Only suppress EPIPE errors on stdin, log other errors
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The react-hooks eslint plugin is not configured in the CLI package, so the disable comment causes an eslint error. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
.continue/and.claude/directoriesTest plan
🤖 Generated with Claude Code
Continue Tasks: ✅ 7 no changes — View all
Summary by cubic
Adds a Claude Code–compatible hooks system to the Continue CLI so external command and HTTP handlers can intercept and influence 17 CLI events. Registers HookService and tightens execution with UTF-8-safe streams, correct env var interpolation, clean EPIPE handling, and ESLint fixes.
New Features
Bug Fixes
Written for commit 8782e38. Summary will update on new commits.