Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
185 changes: 185 additions & 0 deletions docs/cli/hooks.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
---
title: "Hooks"
---

Continue CLI supports Claude Code-compatible hooks so you can run custom logic before and after key events (tool calls, prompts, session lifecycle, and more).

Hooks are configured in settings JSON files and run automatically when matching events fire.

## Where to configure hooks

`cn` loads hooks from the same paths as Claude Code, then merges them:

1. `~/.claude/settings.json`
2. `~/.continue/settings.json`
3. `.claude/settings.json`
4. `.continue/settings.json`
5. `.claude/settings.local.json`
6. `.continue/settings.local.json`

Later files have higher precedence, but hooks from all files run.

## Basic shape

```json
{
"hooks": {
"PreToolUse": [
{
"matcher": "^Bash$",
"hooks": [
{
"type": "command",
"command": "echo 'About to run Bash tool'"
}
]
}
]
}
}
```

## Event types

Continue currently supports the following event names:

- `PreToolUse` — runs before a tool call executes.
- `PostToolUse` — runs after a tool call succeeds.
- `PostToolUseFailure` — runs after a tool call fails.
- `PermissionRequest` — runs when the agent requests approval for a gated action.
- `UserPromptSubmit` — runs after the user submits a prompt.
- `SessionStart` — runs when a session begins.
- `SessionEnd` — runs when a session ends.
- `Stop` — runs when the session is interrupted or stopped.
- `Notification` — runs when the CLI emits a notification event.
- `SubagentStart` — runs when a subagent starts.
- `SubagentStop` — runs when a subagent stops.
- `PreCompact` — runs before context compaction starts.
- `ConfigChange` — runs after configuration changes are applied.
- `TeammateIdle` — runs when the agent becomes idle while waiting for the teammate.
- `TaskCompleted` — runs after the current task is completed.
- `WorktreeCreate` — runs after a worktree is created.
- `WorktreeRemove` — runs after a worktree is removed.

## Matcher behavior

Each event can define one or more matcher groups:

```json
{
"hooks": {
"PreToolUse": [
{
"matcher": "^(Read|Glob)$",
"hooks": [{ "type": "command", "command": "echo read path" }]
},
{
"matcher": "^Bash$",
"hooks": [{ "type": "command", "command": "echo shell tool" }]
}
]
}
}
```

- `matcher` is a JavaScript regex string.
- `"*"`, `""`, or omitted matcher means “match all”.
- Invalid regexes are ignored (with a warning in logs).
- Some events do not use matchers and always fire when configured.

## Hook handler types

### Command hooks

Run a shell command and pass hook input JSON to stdin.

```json
{
"type": "command",
"command": "node .continue/hooks/pre-tool.js",
"timeout": 120,
"statusMessage": "Checking tool policy"
}
```

Optional fields:

- `async`: if `true`, runs in the background (fire-and-forget)
- `timeout`: seconds before cancellation (default 600 for command hooks)
- `statusMessage`: custom spinner message

### HTTP hooks

Send hook input as a JSON POST request.

```json
{
"type": "http",
"url": "https://example.com/hooks/pretool",
"headers": {
"Authorization": "Bearer ${HOOKS_TOKEN}"
},
"allowedEnvVars": ["HOOKS_TOKEN"],
"timeout": 30
}
```

Notes:

- Hook input is sent as request body.
- Non-2xx responses are treated as non-blocking hook errors.
- `headers` support env interpolation only for names listed in `allowedEnvVars`.

### Prompt and Agent handlers

You can include `prompt` and `agent` handler types in config for schema compatibility, but Continue CLI currently skips them.

## Exit code and blocking semantics

For **command hooks**:

- Exit code `0`: success, continue execution
- Exit code `2`: block the action (`stderr` becomes block reason)
- Any other non-zero code: treated as hook failure, does not block by itself

For **JSON hook output** (command or http):

- `{"decision":"block","reason":"..."}` blocks the action
- `hookSpecificOutput` can provide event-specific controls (for example `permissionDecision` in `PreToolUse`)

## Sync vs async

- Sync hooks are awaited before the CLI continues.
- Command hooks with `"async": true` are started and not awaited.
- Multiple sync hooks for the same event can run in parallel.
- Async hooks are useful for telemetry or background notifications where you do not want to delay the main action.
- `SessionStart` is mode-dependent: interactive startup does not wait on it, while headless startup can await it before the main task begins.

## Environment variables for command hooks

Command hooks receive:

- `CONTINUE_PROJECT_DIR`
- `CLAUDE_PROJECT_DIR`

Both are set to the current project directory so shared hook scripts work across `cn` and Claude Code.

## Disable all hooks

To disable hooks globally for a config file:

```json
{
"disableAllHooks": true
}
```

If any loaded settings file sets `disableAllHooks`, hooks are disabled.

## Example use cases

- Block dangerous tool calls (for example deny `Bash` commands matching `rm -rf`)
- Add context before each user prompt (`UserPromptSubmit`)
- Forward tool telemetry to internal observability services via HTTP hooks
- Trigger notifications on session lifecycle events
- Enforce org policies on permission requests
2 changes: 1 addition & 1 deletion docs/cli/tool-permissions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Every tool has one of three permission levels:

## Defaults

Read-only tools (`Read`, `List`, `Search`, `Fetch`, `Diff`) default to `allow`. Write tools (`Edit`, `MultiEdit`, `Write`) and `Bash` default to `ask`. In [headless mode](/cli/headless-mode), `ask` tools are excluded since there's no one to approve them.
Read-only tools (`Read`, `List`, `Search`, `Fetch`, `Diff`, `AskQuestion`, `Checklist`, `Status`, `CheckBackgroundJob`, `ReportFailure`, `UploadArtifact`) default to `allow`. `AskQuestion` is a built-in read-only tool that lets the agent pause and ask for clarification before continuing. Write tools (`Edit`, `MultiEdit`, `Write`) and `Bash` default to `ask`. In [headless mode](/cli/headless-mode), `ask` tools are excluded since there's no one to approve them.

## Overriding with flags

Expand Down
35 changes: 29 additions & 6 deletions docs/cli/tui-mode.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,26 @@ Type `/` to see available commands. Run `/help` for the full list.

| Command | What it does |
|---------|-------------|
| `/help` | Show the help message and keyboard shortcuts |
| `/clear` | Clear the chat history |
| `/login` | Authenticate with your account |
| `/logout` | Sign out of your current session |
| `/update` | Update the Continue CLI |
| `/whoami` | Check who you're currently logged in as |
| `/info` | Show session information, including token usage and cost |
| `/model` | Switch between configured chat models |
| `/config` | Switch configuration or organization |
| `/compact` | Summarize chat history to free up context |
| `/fork` | Branch the conversation from the current point |
| `/resume` | Pick up a previous session |
| `/info` | Show token usage and cost for this session |
| `/init` | Create an `AGENTS.md` file for the current project |
| `/mcp` | Manage MCP server connections |
| `/init` | Create an `AGENTS.md` file for the current project |
| `/compact` | Summarize chat history into a compact form |
| `/resume` | Resume a previous chat session |
| `/fork` | Start a forked chat session from the current history |
| `/title` | Set the title for the current session |
| `/rename` | Rename the current session (alias for `/title`) |
| `/exit` | Exit the chat |
| `/jobs` | List background jobs |

When you're connected to a remote environment, Continue also adds remote-only slash commands such as `/diff` and `/apply`.

## Resume previous sessions

Expand All @@ -49,6 +61,17 @@ cn --resume

This restores the full conversation history, so the agent remembers prior context.

## Interactive questions in TUI mode

The agent can use the `AskQuestion` tool to gather clarifications before it continues. You will see a quiz-style prompt directly in the terminal.

- Use <kbd>↑</kbd>/<kbd>↓</kbd> to highlight an option
- Press <kbd>Enter</kbd> to submit the highlighted option
- Start typing to send a custom answer (even when options are shown)
- If a default answer is provided, pressing <kbd>Enter</kbd> on an empty input submits that default

This is useful when the agent needs decisions like scope, preferences, or environment details before making edits.

## Tool Permissions

Tools that can modify your system (file writes, terminal commands) prompt for approval before executing. You get three options:
Expand All @@ -57,4 +80,4 @@ Tools that can modify your system (file writes, terminal commands) prompt for ap
- **Continue + don't ask again** — approve and save a policy rule to `~/.continue/permissions.yaml`
- **No** — reject the call and give the agent new instructions

Read-only tools (`Read`, `List`, `Search`, `Fetch`) run automatically. See [tool permissions](/cli/tool-permissions) for the full policy system.
Read-only tools (`Read`, `List`, `Search`, `Fetch`, `Diff`, `AskQuestion`) run automatically. See [tool permissions](/cli/tool-permissions) for the full policy system.
Loading