Documentation · Extensibility

PolicyAdvisor Plugins

Use a PolicyAdvisor plugin to route named projects to your personal or work sign-in and set model defaults for a project.

Discovery and SHA-256 binary pinning

ohd discovers regular executable files (chmod 0700, non-symlink) inside ~/.config/oh-router/plugins/ and merges them with explicit plugins entries in ~/.config/oh-router/config.json. When an entry specifies sha256, ohd hashes the plugin binary before every invocation and skips execution if the digest does not match. Every invocation runs under a hard 2000ms timeout.

Inspect the built-in PolicyAdvisor specification
$ oh-router policy plugin-spec
$ oh-router policy plugin-spec --json

Route projects to personal and work profiles

Create two profiles with the provider you plan to use. Then run the provider’s CLI sign-in inside each profile’s directory so OH Router can start the CLI with that sign-in. This example uses Claude Code with opus.

Set up separate sign-ins
$ oh-router daemon start
$ oh-router profiles add --provider claude --id personal --label "Personal"
$ oh-router profiles add --provider claude --id work --label "Work"
$ oh-router profiles list --json
$ CLAUDE_CONFIG_DIR="$HOME/.config/oh-router/profiles/claude/personal/personal" claude auth login
$ CLAUDE_CONFIG_DIR="$HOME/.config/oh-router/profiles/claude/work/personal" claude auth login

Use the personal_dir returned by profiles list --json if your configuration lives elsewhere. The last personal means an interactive session, even for the profile named work. Before running background sessions, sign in to their work_dir as well. For Codex, create the profiles with --provider codex, set CODEX_HOME to the matching directory when running codex login, and use the sol tier.

Download the workspace plugin example, which uses Python 3. Edit WORKSPACES to map your project names to profile IDs. Review the script before making it executable because plugins run with your local permissions.

Save the script as ~/.config/oh-router/plugins/workspace-policy and run chmod 0700 ~/.config/oh-router/plugins/workspace-policy. From the project folder run oh-router spawn --project studio --tier opus. Run oh-router inspect <id> --json to check the selected profile.

The example leaves explicit --profile choices in place. It waits when the mapped profile is unavailable or the session reaches a usage limit. For unmapped projects it leaves stdout empty, so another plugin or the router’s defaults can handle the request.

Stdio JSONL wire contract (launch and on_limit)

ProcessPolicyPlugin writes one JSON line to the plugin's stdin with event set to "launch" or "on_limit", along with session metadata, available workspace profiles, the four-tier models catalog, and the current policy view. The plugin writes a single JSON line to stdout.

FieldDirectionValues & Meaning
eventstdin"launch" when spawning a new session, or "on_limit" when an active session hits a window hold.
sessionstdin{ project, kind, model_class, model_tier, profile_id, headless, is_review, requirements }.
actionstdout"proceed", "relaunch", "wait", or "redeem_reset".
profile_idstdoutOptional workspace profile ID (for example mapping a work repository to a dedicated work directory).
model_tierstdoutOptional tier override: "opus", "sol", "fable", or "astra".

Core invariants enforced after plugin advice

  • Plugins can advise which sign-in and model to use. OH Router checks each recommendation before starting or resuming a session.
  • Capability pinning: any session declaring --require browser-auth stays pinned to claude regardless of plugin output.
  • Lane lease validation: an advised profile_id must exist on the chosen provider, be signed in, have an uncontended personal or work flock lane, and not have an active hold window.