All Agent Engineering

Implement tool approval and default-policy checks in the Cline SDK

Set explicit tool policies, check raw input shape per tool in the approval callback before approving, and handle rejections in the host.

AINavWritten / Updated
On this page

At a glance

A host application embedding the Cline SDK has to decide which tools may run automatically and which need approval from a person or a rule. The key warning in the official permission documentation is that a tool not listed in toolPolicies is enabled and auto-approved by default. An approval callback alone is therefore not enough: you also list every tool and give each one an explicit policy. The deliverable here is a host-side procedure covering explicit tool policies, a per-tool shape check on request.input, and what to do after a rejection.

Runtime and applicability

Article type
Engineering practice
Verified
Applies to
  • Cline Implement tool approval and default-policy checks in the Cline SDK

Execution locations and responsibilities

  • Host application embedding Cline SDK Use the workflow below to distinguish responsibilities of the caller, runtime, and external actions.
Engineering workflow order
Engineering workflow order1. List every tool the host registers → 2. Write explicit toolPolicies for each tool → 3. Implement requestToolApproval and check input shape per tool → 4. Write approval rules only for narrow read-only operations → 5. Deny everything else by default and record it → 6. Check agent behaviour after a rejection. Arrows show the order of checks in the guide. Follow each step’s prerequisites, branches and stop conditions; unexecuted steps are not completed work.1. List every tool the host registers2. Write explicit toolPolicies for each tool3. Implement requestToolApproval and check input shapeper tool4. Write approval rules only for narrow read-onlyoperations5. Deny everything else by default and record it6. Check agent behaviour after a rejection

Arrows show the order of checks in the guide. Follow each step’s prerequisites, branches and stop conditions; unexecuted steps are not completed work.

When to use

  • toolPolicies is set per tool name: { autoApprove: true } runs immediately, { autoApprove: false } waits for approval, and { enabled: false } hides the tool from the model. With no policy the tool is enabled and auto-approved. Checking this layer means confirming that every name in the tool set has an explicit policy.

When not to use

  • The documentation does not spell out the order of evaluation when toolPolicies and requestToolApproval are both configured, so do not assume it from habit; read the documentation and confirm in your own environment before relying on it.
  • The path check in the official example rejects .. and limits prefixes. It is not a complete path-security scheme, and symlinks are not discussed, so do not rely on that rule alone for sensitive directories.
  • Approving everything is meant for sandboxed or fully trusted environments; the official warning is that the agent can then run any shell command, modify any file and make network requests without review.

Prerequisites and input

  • The host can already create an Agent or a ClineCore session and knows which tools it passes in.
  • You can read and edit the host's policy configuration and approval callback, and view host logs.
  • The commands and directory scope used by approval rules have been agreed by the owner, rather than guessed inside the callback.

Engineering checks

Policy layer: what is allowed by default — toolPolicies is set per tool name: { autoApprove: true } runs immediately, { autoApprove: false } waits for approval, and { enabled: false } hides the tool from the model. With no policy the tool is enabled and auto-approved. Checking this layer means confirming that every name in the tool set has an explicit policy.

Callback layer: what approval actually inspects — requestToolApproval receives request.input, which is the model's raw tool input. The official example checks its shape per tool first, then judges the content, and returns { approved: true } or { approved: false }. Input of the wrong shape should never be treated as approvable.

Rejection layer: what happens after a denial — After a denial the agent receives a rejection message. The documented possibilities include asking for clarification, using another tool, retrying with different parameters or abandoning the subtask. The rejection counts as a response and the agent moves to its next iteration. The host should plan checks for those follow-up behaviours.

1. List every tool the host registers

Where: the host code that creates the Agent or session. Input: the tool set actually passed in, for example built-ins from createBuiltinTools plus any tools the host adds. Action: write each tool name down and sort it as read-only, changes files or runs commands, reaches the network, or cannot be judged. Completion check: every tool name has a category, including the cannot-be-judged one. Stop condition: a tool whose side effects you cannot judge must stay out of the auto-approve list and requires approval instead.

2. Write explicit toolPolicies for each tool

Where: toolPolicies in the configuration. Input: the categorised list from the previous step. Action: give each tool { autoApprove: true }, { autoApprove: false } or { enabled: false }; use { enabled: false } for tools you do not need, so the model cannot see them. Completion check: policy keys match tool names one to one with nothing missing. Stop condition: if a name does not match a registered tool name, fix it first; per the documentation, unlisted names get the default of enabled and auto-approved.

3. Implement requestToolApproval and check input shape per tool

Where: capabilities.requestToolApproval. Input: request.toolName and request.input. Action: treat request.input as raw model input and confirm its shape per tool name: for run_commands, commands must be an array whose elements are all strings; for read_files, files must be an array whose elements are objects with a string path. Inspect content only after the shape passes. Completion check: input of the wrong shape reaches a denial before any approving branch, and a well-formed read_files request is not wrongly rejected for having object elements. Stop condition: if the input structure of a tool is not described in the material you have, do not write an automatic approval rule for it and use manual approval.

4. Write approval rules only for narrow read-only operations

Where: per-tool branches inside the callback. Input: { commands: string[] } for run_commands and { files: { path: string }[] } for read_files. Action: match whole commands against a fixed set, because flags can change what a command does; Git commands may run programs named in repository configuration, with core.fsmonitor as the documented example, so approve them only in trusted repositories. For file reads, reject entries whose path contains .. and restrict them to directory prefixes such as the /src/ and /tests/ used in the official example. Completion check: each rule requires every element of the array to qualify. Stop condition: when a need extends to pipelines, commands with other flags or directories outside the set, do not widen the rule and hand the decision to a person.

5. Deny everything else by default and record it

Where: the final branch of the callback. Input: any request that matched no rule. Action: log the tool name and input, then return { approved: false }; an application that needs human oversight can instead present the request to a person, as the official interactive example does, and let the answer decide. Completion check: every unapproved request has a tool name and input in the log, handled under your own sensitive-data rules. Stop condition: if the log cannot be written, do not approve the request.

6. Check agent behaviour after a rejection

Where: the host's run records. Input: one deliberately constructed request that should be denied. Action: observe whether the agent adjusts in one of the documented ways, and confirm each retry passes through the same shape check and rules again. Completion check: the denied action did not execute, the agent moved to later iterations and the host recorded the denial. Stop condition: if the same kind of denied action keeps returning with different parameters, the host ends that run; the supplied text names no specific end-of-run interface, so look it up separately.

Task example

This is an original synthetic walkthrough, not a record of a real run. Suppose a host registers read_files, search_codebase, editor, run_commands and fetch_web_content. The owner decides that reads and searches are approved only under rules, editor and run_commands need approval, and fetch_web_content is turned off. toolPolicies then holds five entries, one per name, with no reliance on the default. Suppose the model requests run_commands with the input { commands: ["git status", "git push"] }. Hypothetical expected observation: the second element is not in the fixed set, so the callback returns { approved: false }, the log records the tool name and input, the agent receives a rejection message and may afterwards ask for only git status, which must pass the checks again. If commands were a string instead of an array, the same denial is expected; if read_files carried files as an array of objects with string path values inside the allowed prefixes, the shape is valid and the request moves on to the content rules. All of this is expectation only and nothing was executed.

Completion checks

  • Policy check: every name in the tool set has an explicit entry in toolPolicies, with no reliance on the default for unlisted names.
  • Shape check: when commands for run_commands is not an array of strings, when files for read_files is not an array of objects with a string path, or when a path contains .., the callback never returns { approved: true }; a well-formed read_files request is not wrongly rejected by the shape check.
  • Rejection check: a denied request did not execute, was logged, and the agent's later iterations and every retry pass through the same check again.

Verification scope

Written from the official Cline permission-handling documentation, which was read. Installation, login, API execution and output were not tested, and the example above is a synthetic walkthrough, not a result from any real run.

Sources

All links are official pages; verification dates are listed per source, and links point to the version checked.

  1. Cline · Cline documentation: cline-approval

Found an error? Tell us →