Cline

Make the Cline CLI wait for a person's yes before every shell command, file change, web fetch and MCP tool call: a PreToolUse hook file set up in one command, verified in Cline CLI 3.0.75.

The Cline CLI runs a prompt you pass it in yolo mode unless you say otherwise: it runs commands and edits files without asking anyone. That is what you want in a script, and it is also when an approval matters most. Cline runs a PreToolUse hook before every tool call. With the VariantGate hook there, every shell command, file change, web fetch and MCP tool call waits for a person, who answers from the inbox, a phone notification, Slack or email. Rules answer the routine ones, and every answer lands on the same record as your other agents.

The quick way: one command

With Node.js on the computer it runs on, this does both steps for you. It opens the browser to sign in (or to make your free account), saves an agent key on this computer, and adds the approval hook to ~/.cline/hooks/PreToolUse, keeping the old file beside it:

npx -y https://variantgate.com/sdk/variantgate-agent-0.5.0.tgz setup cline

Start a new Cline task and ask it to run echo hello: the command waits until you approve it in the inbox, and so does every file change, web fetch and MCP tool call. A no stops the task. A file it cannot change safely, such as one with comments or one that links elsewhere, is left alone, and the command prints the entry to add yourself. The steps below do the same by hand.

1. Create a key

Sign in, open Agents and create a key for Cline. Copy it: it is shown once. Put it in your shell profile, such as ~/.zshrc, as export VARIANTGATE_KEY=….

2. Add the hook file

Install the variantgate command (more on the SDK page):

npm install -g https://variantgate.com/sdk/variantgate-agent-latest.tgz

The hook reads VARIANTGATE_KEY from the environment Cline starts in, or a key saved on this computer:

Or run variantgate login once on this computer instead. It opens the browser, you check a code and press Connect, and it saves a new agent key in ~/.config/variantgate/credentials.json, readable only by you. The hook uses that key, with the API address it was made for, whenever VARIANTGATE_KEY is not set. The MCP server still needs the key from step 1.

Cline hooks are files, not settings. Cline runs every file named PreToolUse (with no extension, or one such as .sh) in its hook folders before each tool call, with the interpreter its first line names. Save this as ~/.cline/hooks/PreToolUse (under $CLINE_DIR when that is set):

#!/bin/bash
# VariantGate: a person approves each command, file change, web fetch and
# MCP tool call Cline makes. Added by `variantgate setup cline`; delete
# this file to stop asking.
export VARIANTGATE_CLINE_HOOK_WAIT="${VARIANTGATE_CLINE_HOOK_WAIT:-90}"
exec variantgate hook cline

Cline has no matcher: it runs the hook for every tool, and the hook lets the ones that only look or talk to you go ahead at once, without a request: read_files, search_codebase, ask_question, submit_and_exit. Any other tool, including one a later version adds, waits for a yes. Cline hands the hook the call on stdin:

{
  "hookName": "tool_call",
  "tool_call": {
    "id": "call_0",
    "name": "run_commands",
    "input": { "commands": ["npm test"] }
  },
  "workspaceRoots": ["/home/ada/shop"]
}

Each call becomes a request with an action name that rules can match. A run_commands call can hold several commands; the request lists all of them, and one answer covers the call:

shell.run
One run_commands call, with every command in it and the workspace folder. The same name the Claude Code, Codex, Gemini CLI, Cursor and Copilot hooks use, so one rule covers them all.
file.write
An editor call that creates a file or replaces it whole, with its path and text.
file.edit
An editor call that replaces or inserts text, or an apply_patch call.
web.fetch
A fetch_web_content call, with the addresses.
mcp.<server>.<tool>
A call to an MCP tool, such as mcp.shop.refund_order for Cline's shop__refund_order. A name with more than one __ stays whole: mcp.my__shop__refund_order.
tool.<name>
Any other tool, such as one a later Cline version adds or one from a plugin.

A no stops the task

A hook can tell Cline to cancel, and that is the only way it can refuse: Cline then stops the whole task, not just the one call. In our runs a denied command never ran, and the CLI ended with [abort] aborted by another client. The reason the person gave is on the request in the inbox, not in Cline’s output. Start a new task with what you want done differently.

What Cline does when a hook fails

We ran the hook in Cline CLI 3.0.75 against a scripted model and a local copy of the service. Cline ignores a hook that exits with an error, prints something that is not JSON, or takes longer than 120 seconds, and runs the call as if there were no hook. There is no setting to make it fail closed. So the hook always prints its answer in time:

  • It waits VARIANTGATE_CLINE_HOOK_WAIT seconds for a person (90 in the file above, 75 if you leave it out), then withdraws the request and stops the task. It never waits longer than 90, whatever the setting says, because Cline’s 120 seconds cannot be changed.
  • If the service cannot be reached, or stops answering, the task stops a few seconds after the wait, and a request it already opened is taken back.
  • With no key set or saved, the hook still prints a cancel, so the call does not run.
  • What the hook cannot cover is itself not starting. If the variantgate command is missing, or npx cannot fetch it with no network, Cline runs the call. Install the command rather than relying on npx for an agent that runs unattended.

A person has about a minute and a half to answer. For longer reviews, let rules approve the routine calls so the ones that reach a person are few, and keep notifications on your phone.

MCP tool names

Cline hands the hook an MCP tool under one name, the server’s and the tool’s joined by two underscores, such as shop__refund_order. In Cline’s source, a name with characters other than letters, digits, _ and -, or one longer than 64 characters, has those characters replaced and a short hash added. A name with one __ is split there, so the request has the mcp.<server>.<tool> action the other hooks send, mcp.shop.refund_order, and one rule covers the tool in every agent. A server name can hold __ too, so when a name has more than one, the server cannot be told apart from the tool, and the action is the whole name, such as mcp.my__shop__refund_order. Rules for mcp.my.* do not cover that, so for such servers name the tool in a rule, or rename the server in Cline’s MCP settings.

The hook puts every call in front of a person, including calls to the approvals MCP server if you add it to Cline as well, so use one or the other.

In scripts and CI

A run with a prompt has nobody at the terminal and asks nobody by default, so the hook is the whole approval step there. Give the run a key, and install the variantgate command on the machine so the hook can always start:

export VARIANTGATE_KEY=...   # a key for this pipeline
cline "Fix the failing test and push a branch"

A run that pauses for a person holds the pipeline for up to the wait. Plan for a no: the task stops, and the job should fail rather than retry.

Other hook folders

Cline also runs PreToolUse files from ~/Documents/Cline/Hooks, from a folder passed with --hooks-dir, and from a project’s .clinerules/hooks and .cline/hooks. When several hooks answer, one cancel is enough to stop the task, so a second hook cannot approve what yours refused. A copy of the VariantGate hook in two of those folders asks about each call twice; setup cline warns about the Documents folder. Treat a project’s hook folder like a change to your pipeline: whoever can edit it can add hooks to every run in it. We tested the CLI; the Cline extension for VS Code reads hooks from the Documents folder in its own format, and we have not tested this hook there.

On Windows

Cline runs a hook file with bash, which Windows does not have by default, so setup cline stops there instead of writing a file that would not run, and therefore would let every call through. With Git Bash or WSL on the path, the file above works the same, but we have not tested it.

Check that it works

Start a new task and ask Cline to run echo hello. A request appears in the inbox; deny it and check that the task stops without printing hello. Then ask again and approve it.