Skip to Content
harness-kit

External Policies and adapters

The JSON protocol any executable speaks to decide hook calls or stand in for a forge, a tracker or a project catalog, in any language.

You'll: learn the protocol an executable in any language (a shell script, a Python program, a Go binary) speaks to decide hook calls as an external Policy, or to answer for a forge, a tracker or a project catalog as an adapter. For a walkthrough, start with Writing an external Policy or adapter.

Before you start

  • An executable the kit can run, with a path relative to the configuration when it starts with ..
  • A call takes at most 10 seconds unless the adapter's timeoutMillis says otherwise; after that the executable is stopped.

What the executable reads and writes

The kit runs the executable as <executable> <operation>. The operation's name, such as decide or get_issue, is its only argument, so no secret ever appears on a command line. The executable reads one JSON object from standard input and writes one to standard output. Every message carries "protocol": 1:

  • the request is {"protocol": 1, "input": …}; anything the operation needs, a token included, is a field of input;
  • an answer is {"protocol": 1, "output": …} with exit code 0.

How it ends tells the kit what happened:

ExitStandard outputMeaning
0{"protocol": 1, "output": …}the answer
1{"protocol": 1, "error": {"kind": …, "message": …}}the remote refused: kind is not_found, unsupported, auth, invalid or network
2anything; the reason on standard errora local setup problem, such as a missing CLI or credentials
other—a protocol violation, as are a signal and an answer the operation does not read

not_found is told apart from the rest, so a Policy can read it as "missing" and everything else as "cannot tell".

harness-kit protocol schema prints the JSON Schema of every request and answer, by contract and operation, such as contracts.tracker.get_issue and contracts.policy.decide. The protocol reference shows them all.

Decide hook calls with an external Policy

An external Policy answers decide. Its input is the hook call in Claude Code's own field names (hook_event_name, session_id, tool_name, tool_input and so on), and its output is {"decision": …}, the same Decision an in-process Policy returns, tagged by _tag:

What decide prints
{
  // The version of the protocol the answer follows; it is always 1.
  "protocol": 1,
  // What `decide` answers: the Decision for the hook call.
  "output": {
    "decision": {
      // Which Decision: Allow, Deny, Ask, Context or BlockStop. A Deny refuses the tool call.
      "_tag": "Deny",
      // What is wrong with the tool call, which the agent reads.
      "reason": "A forced push rewrites history others build on.",
      // The exact step that clears it, which the agent reads after the reason.
      "fix": "Push without --force, or ask a person to."
    }
  }
}

Name the executable under adapters and run it with the built-in external Policy, which takes the adapter, the events, and optionally tools, agentTypes and timeoutMillis (10 seconds). It fails closed unless the entry opens it.

Stand in for a forge, tracker or catalog with an adapter

adapters names each adapter. Three names have a meaning to the kit: forge (pull requests), tracker (issues) and, through projects.source.command, the project catalog. Any other name is for an external Policy.

ContractOperations (beyond capabilities)Kit's own
forgepr_get, pr_list, pr_threads, pr_files, pr_commits, compare, repo_get, whoami, classify_commandGitHub
trackerget_issue, get_comments, search, count, create_issue, update, transition, link, children, find_recent, rank, active_sprint, fields, whoamiGitHub Issues, Jira
projectresolve_projectthe catalog in the configuration

An executable adapter is { executable, timeoutMillis? }. It only needs to answer the operations the Policies you use call.

Every adapter answers capabilities with the operations it supports. The kit calls only those, and falls back where it can: a tracker without count is counted by paging through its search.

Check that an adapter works

harness-kit config check asks every adapter for its capabilities, so a broken executable shows up before a hook needs it:

What config check prints
harness.config.ts loads, with 3 Policies.
The adapter tracker supports capabilities, get_issue.

If something goes wrong

  • Exit 2 or a setup message. The executable reported a local problem, such as a missing CLI or credentials. Its standard error holds the reason.
  • A protocol violation. The executable exited with another code, died from a signal, or printed an answer the operation does not read. Check that it prints one JSON object with "protocol": 1.
  • A Policy cannot tell. The remote refused with any kind but not_found. Fix the credentials or the network; a Policy follows its fail mode meanwhile.

Troubleshooting lists more.

On this page