# Cline

> Set up Comity's file hooks for Cline and connect its MCP server.

Cline runs executable hook files from `.clinerules/hooks/` (the VS Code/JetBrains extension, the Cline CLI and the SDK all read this folder). `comity init` writes one small script per hook; Cline keeps MCP servers only in user settings, so you add the Comity server once per machine.

## Set up

```sh
cd your-repo
comity init --tools cline
git add .clinerules/hooks
git update-index --chmod=+x .clinerules/hooks/*   # keep the scripts executable for teammates
git commit -m "Set up Comity for Cline"
```

Then:

1. **IDE extension**: open Cline's settings and check **Enable Hooks**.
2. **MCP** (once per machine):

   ```sh
   cline mcp add comity --yes -- node -e "const c=require('child_process').spawn('comity '+process.argv.slice(1).join(' '),{stdio:'inherit',shell:true});c.on('error',()=>process.exit(1));c.on('exit',(k)=>process.exit(k===null?1:k))" mcp
   ```

   In the IDE, open **MCP Servers → Configure → Configure MCP Servers** and add:

   ```json
   "comity": { "command": "node", "args": ["-e","const c=require('child_process').spawn('comity '+process.argv.slice(1).join(' '),{stdio:'inherit',shell:true});c.on('error',()=>process.exit(1));c.on('exit',(k)=>process.exit(k===null?1:k))","mcp"] }
   ```

   The same command works on every OS (Node must be on `PATH`). `comity mcp` is a local proxy that authenticates with your `comity login`, so no token is stored anywhere in Cline.

## What init writes

### `.clinerules/hooks/<Hook>`

Eight bash scripts without a file extension, named after Cline's hooks: `TaskStart`, `TaskResume`, `UserPromptSubmit`, `PreToolUse`, `PostToolUse`, `TaskComplete`, `TaskCancel` and `SessionShutdown`. Each one is:

```bash
#!/usr/bin/env bash
# Generated by `comity init`; re-running init rewrites this file.
command -v comity >/dev/null 2>&1 || { cat >/dev/null; echo '{"cancel":false}'; exit 0; }
exec comity hook --tool cline --event PreToolUse
```

On a machine without the CLI the hook answers `{"cancel":false}`, so Cline keeps working. On macOS and Linux init marks the files executable.

Comity reads both payload dialects (the extension's `preToolUse`/`postToolUse` objects and the CLI's `tool_call`/`tool_result`) and answers in Cline's format: `cancel` + `errorMessage` to block, `contextModification`/`context` to add context.

## What your agent sees

- **Task start and each prompt**: the Comity briefing and prompt context.
- **Before a tool call** (`write_to_file`, `replace_in_file`, `editor`, `apply_patch`, `execute_command`, `run_commands`): a block cancels the call with Comity's reason; warnings are added as context.
- **After a tool call**: new conflicts, messages and answers.

Cline adds hook context to the conversation for the *next* model request; it cannot change the call that triggered it.

## Verify

```sh
comity doctor
```

Expect `cline hooks  all hook files present in .clinerules/hooks` and `cline mcp  comity server in ~/.cline/data/settings/cline_mcp_settings.json`. The Cline checks appear once the hook files exist.

## Limits

- The Cline IDE extension does not run hooks on Windows; use the Cline CLI or WSL there.
- Hooks are skipped in `--yolo` mode.
- The IDE extension keeps its own MCP settings file; `comity doctor` checks the CLI's.
