cbs Virtual Key Mapper
Short-lived keys from your company gateway, labelled with the repository you work in, for every tool you use.
vkm signs you in to your company's gateway once, with its single sign-on. From then on your
tools get short-lived keys from it, and every request carries the labels of the
repository you are working in: key/value pairs such as customer = "acme" and
project = "webshop". Spend is attributed by label without anyone pasting API keys into
config files, and nothing goes out while a required label has no value.
vkm does not depend on a particular gateway or tool. Gateways, sign-in methods and tools
are separate adapters (docs/adapters.md), so new ones can be added
without touching the rest.
✨ What works where
Gateways and sign-in
| Gateway | Sign-in | What the gateway receives |
|---|---|---|
| LiteLLM | Its native CLI single sign-on in the browser, with team choice. The refresh token stays in the OS vault. | The SSO user and team (from the token), the labels as request tags x-litellm-tags (by default one KEY:VALUE tag per label, e.g. customer:acme), and x-litellm-spend-logs-metadata = {"labels": {"customer": "acme"}, "sources": {"customer": "explicit|env|local|file|rules"}, "repository": "github.com/org/repo"} (repository only inside a Git checkout with an origin). |
| LiteLLM, from a VS Code dev container, SSH or WSL window | forwarded: the two VS Code extensions relay short-lived keys from the sign-in on your own computer; the refresh token never leaves it. |
The same. |
More gateways and sign-in methods are adapters (docs/adapters.md).
Tools
| Tool | Connected with | Labels | Key renewal | While a required label has no value |
|---|---|---|---|---|
| Claude Code CLI | vkm setup claude |
per repository, checked before each prompt | ✅ | the prompt is blocked |
| Claude Code for VS Code | vkm setup claude + "claudeCode.disableLoginPrompt": true |
per repository, checked before each prompt | ✅ | the prompt is blocked |
| Codex CLI | vkm setup codex + the shell hook |
of the folder where Codex starts | ✅ | no key is sent; the gateway refuses |
| OpenCode v1 | vkm setup opencode |
per request, of the folder OpenCode runs in | ✅ | the request is blocked |
| OpenCode v2 | vkm run opencode (setup refuses v2) |
fixed at launch | ❌ key from launch time; restart when it expires | as for vkm run |
| GitHub Copilot Chat in VS Code | the Virtual Key Mapper extension | per workspace folder, shown in the status bar | ✅ | blocked, with an "Assign labels" button that runs vkm repo bind |
| any of the above, one launch | vkm run [--label KEY=VALUE]... TOOL |
fixed at launch (or the ones you give) | ✅ (OpenCode v2: ❌) | asks in a terminal for each missing label and saves the answers; blocked without a terminal or outside Git |
| Codex for VS Code | not supported yet | |||
| Copilot inline completions | not possible: they always use GitHub's models |
Platforms
✅ = tested in CI on every push, with the real tools (pinned in ci/agents, plus a weekly
run with their latest releases) against a local test gateway. ☑️ = supported and checked by
hand with the manual checklist.
| Windows | macOS | Linux | Dev container | SSH, WSL | |
|---|---|---|---|---|---|
| Claude Code CLI, Codex CLI, OpenCode v1 | ✅ (interactive Codex ☑️) | ✅ | ✅ | ✅ Claude Code and Codex, ☑️ OpenCode | ☑️ |
| Claude Code for VS Code, Copilot Chat, OpenCode v2 | ☑️ | ☑️ | ☑️ | ☑️ | ☑️ |
| Credential vault | ✅ Credential Manager | ✅ Keychain | ✅ Secret Service (GNOME Keyring), ☑️ KWallet | not needed | not needed |
| Shell hooks | ✅ PowerShell 7, bash; ☑️ Windows PowerShell 5.1 and PCs that block scripts (shell-init pwsh --terminal) |
✅ bash, zsh, fish, PowerShell 7 | ✅ bash, zsh, fish, PowerShell 7 | as on Linux | as on Linux |
| VS Code extensions | ✅ in a VS Code extension host | ✅ in an extension host, with the relay | ✅ in an extension host, with the relay | ✅ relay in a real dev container | ☑️ |
Choosing labels
Each label is resolved on its own, so customer can come from a central rule and project
from a committed file. For each key the first source with a value wins:
| Source | Who sets it | Applies to |
|---|---|---|
vkm run --label KEY=VALUE |
you | that launch |
VKM_LABEL_<KEY> (e.g. VKM_LABEL_CUSTOMER) |
you | every process started with the variable set |
vkm repo bind --label KEY=VALUE |
you | clones of that repository on this computer (same origin, or it as upstream), only for you |
a committed .vkm file (vkm repo bind --shared --label KEY=VALUE writes it at the repository root) |
the team | that folder and everything below it, unless a nearer .vkm exists |
| central rules (a JSON file or URL in the profile) | your organisation | repositories matching a pattern, e.g. github.com/acme-*/** |
Which labels exist and which are required is set by your organisation's central rules document or by your profile (Labels).
🚀 Quick start
Needs Python 3.11 or newer and an OS credential vault.
uv tool install virtual-key-mapper # or: pipx install virtual-key-mapper
Update later with uv tool upgrade virtual-key-mapper (or pipx upgrade virtual-key-mapper).
From a checkout instead:
python -m venv .venv
.venv/bin/python -m pip install -e . # Windows: .venv\Scripts\python.exe -m pip install -e .
vkm is the installed command. If your machine blocks pip-generated .exe launchers (some
Windows policies do), use python -m virtual_key_mapper everywhere instead; it accepts the
same arguments.
Prefer a page to the command line? Run vkm ui (or python -m virtual_key_mapper ui). It opens a
setup page in your browser where you add your gateway, sign in, connect your tools and assign the
labels of your repositories. The page runs on your computer only, until you press Ctrl+C. The same
steps on the command line:
# 1. Once per machine: a profile for your gateway and your business-unit team, then sign in.
# If your organisation publishes its label definitions, pass --rules URL instead of --label.
vkm profile add work --gateway https://llm.company.example --team-id YOUR_TEAM_ID \
--label customer --required --description "Who the work is billed to"
vkm login # browser sign-in; choose the same team there
vkm status # "state": "ready"
# 2. Once per machine: connect your tools.
vkm models list # the model aliases your gateway offers you
vkm setup claude --model YOUR_CLAUDE_ALIAS # start model; /model lists all gateway models
vkm setup codex --model YOUR_CODEX_ALIAS
vkm setup opencode
# 3. Once per repository (unless a central rule or a committed .vkm covers it):
cd ~/src/some-repo
vkm repo bind --label customer=acme # or plain 'vkm repo bind' to be asked
vkm repo show
The gateway address is its root URL (no /v1); the team ID is the exact ID from the gateway,
not its display name. Your sign-in renews itself; sign in again only after logging out, a
long pause or a change of team membership.
The gateway must be served at its host root with LiteLLM's PROXY_BASE_URL set to that URL
(see Gateway requirements).
vkm profile remove NAME signs out of a profile and deletes it; tools set up with it then get no
more keys.
🧭 Labels
A label is a key with a value, such as customer = "acme" or project = "webshop". What a
label means is up to your organisation; vkm knows the keys, which of them are required,
where their values may come from and how the gateway receives them. The full reference is
docs/labels.md.
Definitions
Labels are defined in your organisation's central rules document (profile add --rules URL|PATH
or profile update NAME --rules ...) and, for keys the document does not define, in your profile:
vkm profile update work --label project --description "Project within the customer"
vkm profile update work --label customer --required --value acme=Acme --value globex=Globex --strict
vkm profile update work --no-label project
vkm labels list # the labels in effect, where each is defined, and notices
One label per call. --required: nothing is sent while it has no value. --value ID[=NAME]:
the choices the picker offers; with --strict only those are accepted. --source NAME
(repeatable) limits where values may come from. Keys are 1-32 lowercase letters, digits, _
or -, starting with a letter. A profile label for a key the central document defines is
refused (or, when the document cannot be read at the time, ignored with a notice): the central
one applies. If no label is defined anywhere, requests carry only the repository, and setup,
run and repo show say so. The setup page (vkm ui) edits the same labels, their values and
the rules location under "Profile settings"; sources and outputs stay with the command.
Values
For each defined key, the first source with a value wins:
--label KEY=VALUE(forrunandrepo show);- the environment variable
VKM_LABEL_<KEY>(exactly: uppercase,-as_; empty counts as unset; otherVKM_LABEL_*names are ignored); - your personal binding:
vkm repo bind --label KEY=VALUE, stored only for you (repositories.jsonon this computer), keyed by the repository'sorigin/upstreamaddress, so every clone on this computer shares it. It keeps keys you do not name; a different value for a key already bound needs--replace.repo unbindremoves the binding,repo unbind --label KEYone key; - the nearest committed
.vkmfile, written withrepo bind --shared --label KEY=VALUE:
A file in a parent folder such as# Labels for AI tool requests in this folder and below (vkm). [labels] customer = "acme" project = "webshop"~/src/acme/covers all repositories below it, and the nearest file wins as a whole (a nearer file withoutprojectdoes not fall through to a parent's). Inside your home folder the search stops below home, so a file in home or above it never applies (repo bind --sharedrefuses to write one there); for folders outside home, such as/workspacesin a dev container or another drive on Windows, it goes up to the root of the drive; - a central rule (below).
--label KEY= on the command line, "" in a .vkm and null in a rule mean "no value here,
stop searching". --label refuses keys that no definition knows (typos); values for unknown keys
from other sources are not sent, and repo show lists them. Values are 1-256 printable ASCII
characters without ,, surrounding spaces or a leading ! or &.
The central rules document
{
"version": "2.0",
"labels": [
{"key": "customer", "required": true, "description": "Who the work is billed to",
"values": [{"id": "acme", "name": "Acme"}, {"id": "globex", "name": "Globex"}]},
{"key": "project", "description": "Project within the customer"}
],
"outputs": {"litellm": {"tags": {"format": ["${customer}", "${customer}:${project}"]}}},
"rules": [
{"match": "github.com/acme-*/**", "labels": {"customer": "acme"}},
{"match": "**", "labels": {"project": null}}
]
}
Rules are tried in order, each against origin, then upstream; each key takes its value from
the first matching rule that sets it, so a catch-all below can still supply another label.
** spans path segments, */? stay within one. Write the repository as repo show prints it
(lowercase, %20 decoded to a space). outputs are grouped by gateway type, so one document
can serve profiles on different gateways. A URL is cached for an hour; if a fetch fails or a
newly published document is invalid, the last good copy is used.
Required labels
A required label without a value blocks every request with a message starting
Required labels have no value:, naming the keys and the ways to set them. vkm run and
vkm repo bind in a terminal, and "Assign labels" in VS Code, ask for each missing one and save
the answers as your personal binding. The picker offers the label's values, else the
gateway's catalogue, else accepts any valid typed value without signing in (vkm labels values KEY
shows which). vkm repo bind asks only for labels a personal binding (with --shared: a .vkm
file) may set.
repo show tells you each label's value and where it came from.
What the gateway receives
For LiteLLM, by default:
x-litellm-tags: customer:acme,project:webshop
x-litellm-spend-logs-metadata: {"labels":{"customer":"acme","project":"webshop"},"repository":"github.com/acme-shop/web","sources":{"customer":"rules","project":"file"}}
The tags format can be changed in the central document (it wins) or in the profile; the metadata can be switched off:
vkm profile update work --output 'tags=${customer}' --output 'tags=${customer}:${project}'
vkm profile update work --output-off metadata
vkm profile update work --output-default tags
An entry that uses an optional label without a value is left out; $$ is a literal $.
Formats that could make one label's value look like another's are refused, as is any setup in
which a required label reaches no output. The rules are in
docs/labels.md.
Labels are attribution, not access control: enforce allowed values on the gateway if you need
that. Gateway settings that break or leak attribution (tag routing, client-side tag rejection,
header forwarding) and why the picker needs values in the central document are listed in
Gateway requirements.
🧩 Tools
Claude Code (CLI and the official VS Code extension)
vkm setup claude [--model ALIAS] [--replace] [--remove]
Writes ~/.claude/settings.json (or $CLAUDE_CONFIG_DIR): an apiKeyHelper that runs
vkm token, the gateway address, gateway model discovery and a prompt hook. /model (also in the
VS Code extension) then lists the models your gateway offers you; --model only picks the one new
sessions start on. Before each prompt the hook
resolves the labels, writes the resulting headers to the repository's .claude/settings.local.json
(excluded from Git) and asks you once to send the prompt again; prompts are blocked while a
required label has no value.
For the VS Code extension also set "claudeCode.disableLoginPrompt": true in your VS Code
user settings. --remove undoes exactly what setup wrote.
Codex CLI
vkm setup codex [--model ALIAS] [--remove]
eval "$(vkm shell-init bash)" # add to ~/.bashrc; also zsh, fish, pwsh
On Windows, add vkm shell-init pwsh | Out-String | Invoke-Expression to your PowerShell
$PROFILE. Where the execution policy blocks scripts (common on company PCs, "running scripts is
disabled on this system"), a profile cannot load; run vkm shell-init pwsh --terminal
instead and paste its command line into Windows Terminal (Settings → your PowerShell profile →
Command line) or its snippet into your VS Code user settings. Check in a new terminal:
Get-Command codex shows Function.
Codex cannot list the gateway's models itself; vkm models list prints the aliases to pass to
--model.
Codex reads the label headers from environment variables that the shell hook sets per directory.
Without them, or while a required label has no value, Codex gets no credential and the gateway refuses the request. The hook also makes
codex start with --no-daemon: Codex's shared background daemon would keep the variables of the
terminal that started it. If one is running from before, stop it once: codex app-server daemon stop.
OpenCode
vkm setup opencode [--model ALIAS] [--remove]
Adds a provider with the gateway's models and a small plugin to
~/.config/opencode/opencode.json; the plugin adds a fresh credential and the folder's
label headers to every request, and blocks requests while a required label has no value. OpenCode v2 is supported only through vkm run opencode.
One-off launches
vkm run [--label KEY=VALUE]... [--model ALIAS] claude|codex|opencode [-- TOOL ARGUMENTS]
Starts the tool with child-only configuration, without changing your setup; each --label
sets that key for that process (--label KEY= for no value), the others resolve as usual. In a
terminal it asks for missing required labels and saves the answers as your personal binding.
Local apps and scripts
vkm serve [--port PORT] [--directory FOLDER]
vkm ui runs the same server and opens the setup page in your browser (--no-browser prints its address).
Serves the same JSON documents as the commands on 127.0.0.1 until you stop it with Ctrl+C:
/api/token, /api/repository (the labels and request headers of a folder, repo show --json),
/api/labels, /api/labels/KEY/values, /api/models, /api/status and /api/profiles.
Without directory=FOLDER, the labels are those of the folder the server started in;
label=KEY=VALUE sets a label for one request, as --label does. profile=NAME picks a profile.
Changes are POST requests with a JSON body (Content-Type: application/json), the same as the
commands: /api/profiles (profile add, with name, gateway, team_id, rules and
definitions), /api/profiles/update (profile update, with name, rules, null to stop using
them, and the labels or outputs in definitions, which replace the profile's),
/api/profiles/remove (profile remove, with name), /api/profiles/default (profile use),
/api/login and /api/logout,
/api/setup/TOOL (with model and replace) and /api/setup/TOOL/remove,
/api/repository/bind (with labels, directory, shared and replace) and
/api/repository/unbind (with keys). GET /api/tools and GET /api/repositories list the
tools and your personal bindings. /api/login opens the browser on this computer and answers when
the sign-in is done.
Every request needs Authorization: Bearer TOKEN. A new token is made at each start and written,
with the URL, to serve.json in the configuration folder, which only you can read. Requests to
another host name or from other websites are refused. Responses are {"result": ..., "messages": [...]},
or {"error": "...", "messages": [...]} with an HTTP error status.
Any other tool, through the local proxy
cd ~/src/some-repo
vkm serve --proxy [--label KEY=VALUE]... [--port PORT]
For tools and scripts that know nothing about vkm. Set the tool's base URL to
http://127.0.0.1:47474/openai-chat (OpenAI Chat Completions), …/openai-responses (OpenAI
Responses) or …/anthropic-messages (Anthropic Messages), and its API key to the contents of
proxy.key in the configuration folder (made once, readable only by you). The proxy replaces that
key with your current gateway key and adds the labels:
- labels the request sends itself, as
X-Vkm-Label: customer=acme, project=webshop; - otherwise the
--labelvalues given at start; - otherwise the labels of the folder in the request's
X-Vkm-Directoryheader, or
