* feat: add hooks system for CLI event interception
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>
* fix: register HookService in service container
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>
* fix: resolve eslint errors in hooks files and services/index.ts
Fix unused imports, import ordering, and negated condition lint errors.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix: handle EPIPE errors on hook stdin writes
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>
* fix: skip hookRunner tests on Windows
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>
* fix: address cubic review - utf8 encoding, regex, EPIPE handling
- 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>
* Remove AI slop from hookRunner.ts
* Update AGENTS.md to document hooks system
* Fix React hooks best practices in useService.ts
* fix: correct indentation in useService.ts for prettier
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix: remove invalid eslint-disable for react-hooks/exhaustive-deps
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>
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: continue[bot] <230936708+continue[bot]@users.noreply.github.com>
4.2 KiB
4.2 KiB
AGENTS.md
This file provides guidance to AI coding agents when working with code in this repository.
Development Commands
- Build:
npm run build- Compiles TypeScript to JavaScript in dist/ - Test:
npm test- Runs Vitest tests with ESM support - Type Check:
npm run lint- Runs TypeScript compiler without emitting files for type checking - Format:
npm run format- Runs Prettier with --write flag to check + fix formatting - Start:
npm start- Runs the built CLI from dist/index.js - Development: After building, test locally with
node dist/index.js
Architecture Overview
This is a CLI tool for Continue Dev that provides an interactive AI-assisted development experience. The architecture consists of:
Core Components
-
Entry Point (
src/index.ts): Main CLI logic with two modes:- Headless mode: Non-interactive mode for automation/CI
- TUI mode: Terminal User Interface using Ink/React
- Standard mode: Traditional readline-based chat interface
-
Authentication (
src/auth/): WorkOS-based authentication systemensureAuth.ts: Handles authentication flowworkos.ts: WorkOS configuration and token management
-
Continue SDK Integration (
src/continueSDK.ts): Initializes the Continue SDK client with:- API key authentication
- Assistant configuration (slug-based)
- Organization support
-
Terminal UI (
src/ui/): React/Ink-based TUI componentsTUIChat.tsx: Main chat interface componentUserInput.tsx: Input handling with multi-line supportTextBuffer.ts: Text display utilities
-
Tools System (
src/tools/): Built-in development tools including:- File operations (read, write, list)
- Code search functionality
- Terminal command execution
- Diff viewing
- Exit tool (headless mode only)
-
MCP Integration (
src/mcp.ts): Model Context Protocol service for extended tool capabilities -
Hooks System (
src/hooks/): Event interception system for extending CLI behaviorHookService.ts: Service container integration, loads config and fires eventshookConfig.ts: Loads hooks from settings files, merges configs from multiple sourceshookRunner.ts: Executes hook handlers (command, HTTP) with exit code semanticsfireHook.ts: Convenience functions for firing events from integration pointstypes.ts: Claude Code-compatible type definitions for hook inputs/outputs- Config locations (lowest to highest precedence):
~/.claude/settings.json,~/.continue/settings.json(user-global).claude/settings.json,.continue/settings.json(project).claude/settings.local.json,.continue/settings.local.json(project-local)
- Exit code semantics: 0 = proceed, 2 = block (stderr becomes feedback), other = non-blocking error
- JSON output: Optional structured output with
hookSpecificOutputfor fine-grained control - Hook types:
command(shell),http(POST request),prompt/agent(not yet implemented)
Key Features
- Streaming Responses: Real-time AI response streaming (
streamChatResponse.ts) - Slash Commands: Built-in commands like
/help,/exit(slashCommands.ts) - Multi-mode Operation: Supports TUI, headless, and standard chat modes
- Tool Integration: Extensible tool system for development tasks
Testing Setup
- Uses Vitest with TypeScript and ESM support
- Configuration in
vitest.config.ts - Tests should be written with
.test.tsextension - No existing test files found - tests should be added when writing new functionality
- Run tests using
npm run test path/or/pattern
Build System
- TypeScript compilation with declaration files
- ESNext target with NodeNext module resolution
- Outputs to
dist/directory - Source maps and inline sources enabled
- JSX support for React components
- Relative import paths require explicit file extensions, e.g. 'from "./test.js"' instead of 'from "./test"'
Important rules
- Whenever you create / update a test, you should run the test to be certain that it passes
- If you ever create a PR, you should be sure to check the formatting and linting first with
npm run formatandnpm run lint/npm run lint:fix.