mehendocs

ReferenceThe mehen command line

The mehen command line#

What does each command do, and what are its flags, variables and exit codes?

On this page

mehen is the command line on every machine an agent works from, and mehen mcp serves the core operations as MCP tools; their inputs, output shapes, timeouts and body limits differ where those pages say so. No command and no tool returns a secret value, except the real values a human allowed into a mehen run child, which go to that child only. The command sections below are generated from the command table mehen itself is built from, so they match mehen <command> --help for the version in the footer.

By task#

TaskCLIMCP tool
Which workspaces is this machine in?mehen statusvault_status
Why is it not working?mehen doctorvault_doctor
Enrol it in a workspacemehen enrol --workspace <slug> (prints the ask and exits), then mehen wait enr_...vault_wait (to finish)
Which workspace does this checkout use?mehen workspace show
Is mehen current?mehen update --check --json (a release build with a trusted key updates itself)
What may I name as a provider?mehen templates [<id>]vault_templates
What credentials exist?mehen lsvault_list
Is this key set and right?mehen show <slug>vault_show
Will this request be allowed?mehen check <slug> <METHOD> <url>vault_check
Ask a human for a new credentialmehen request <kind> --name <slug> --provider <template> --reason <why> [--home private|project|workspace]vault_request
Connect an OAuth accountmehen connect <provider> --name <slug> --reason <why> [--expect <account>] [--request-client]vault_connect
Wait for an intake, connection, approval or enrolmentmehen wait <id>vault_wait
Which links are still open?mehen pending [<id>]vault_pending
Call an HTTP APImehen fetch <slug> <METHOD> <url> [--project <prj_id> --env <name>]vault_fetch
Run a project commandmehen run [--env <name>] -- <cmd>
Check a project's variablesmehen env checkvault_env with check
Pull the brakemehen freeze
The short guidemehen guide

Output and --json#

--json works on every command except mehen run, mehen env set, mehen init and mehen mcp. With it, results go to stdout as one JSON object per line, and errors go to stdout as an error object (see Errors and exit codes). Without it, results go to stdout and anything meant for a person reading along goes to stderr. Use --json whenever a program reads the output; it may also come before the command (mehen --json status).

The standard commands accept --no-qr, which turns off the terminal QR code for one run; mehen mcp, mehen run, mehen env and mehen init do not, so set MEHEN_QR=0 when a run's approval block must not draw one. --workspace <slug or id> is accepted by every command, before or after it, and picks which of this machine's enrolments acts (Several workspaces on one machine). mehen run --help, mehen env --help and mehen init --help print the usage and exit 0.

--timeout on wait, request and connect takes 0 (check once), a number of seconds, or 30s, 10m, 2h, up to 24 hours. The default is 10 minutes.

Environment variables#

The variables mehen reads:

VariableMeaning
MEHEN_SESSIONA label for your session (1 to 120 letters, digits, ., :, _ or -), shown to the human in the details of intake, connect and approval pages and written to the audit log. Set it; a harness that draws cards from your calls usually sets it for you. It grants nothing.
MEHEN_ENVPicks an unprotected environment for mehen run and mehen env when there is no --env. Never a protected one.
MEHEN_VAULT_URLThe vault to enrol with when it is not https://app.mehen.dev. Once a workspace is selected, a value naming another origin is workspace_mismatch.
MEHEN_HOMEWhere this machine's Mehen state lives: one directory per workspace under it, with its config, device key, key scope and ledger. Default ~/.config/mehen. A different MEHEN_HOME is a different machine to the vault. Set by the harness or the human; leave it as it is.
MEHEN_WORKSPACESWhich workspaces this agent may use, comma-separated slugs or tn_ ids; unset means all. It only narrows: anything outside is workspace_not_allowed. Set by the harness; only the human widens it.
MEHEN_WORKSPACEThe same as --workspace <slug or id>: which workspace acts.
MEHEN_MANAGED_CONTEXTSet by an agent launcher on a managed host, with the pinned workspace directory; never set it yourself.
MEHEN_NO_AUTO_UPDATE1 switches off the background update and the automatic update when the vault asks for a newer mehen.
MEHEN_QR0 turns the terminal QR code off; light or dark picks its colours when the terminal does not say.
NO_COLOR, FORCE_COLOR, TERMColour is used only on a terminal, never with NO_COLOR set or TERM=dumb; FORCE_COLOR forces it on. Colour never carries meaning on its own.

Exit codes#

These are Mehen's own exit codes. mehen run returns the child's exit code after a successful start; it is not limited to this table. Errors and exit codes says what to do with each, and names every error code.

ExitMeaning
0OK
1Error
2Usage
3Approval required
4A human must act
5Refused by rule
6Identity
7Transient

Commands#

In the order mehen --help lists them. Standard commands accept the global flags --json, --help, --no-qr, --workspace. run, env, init and mcp have the command-specific exceptions described under Output and --json and in their usage.

CommandWhat it does
setupregister the Mehen MCP server and skills in your installed agents, at user level
updatecheck for or install a signed Mehen release and refresh managed skills
enrolenrol this machine in a workspace: prints the link a human accepts in the browser, then mehen wait finishes it; the key is kept across attempts
statusshow every workspace this machine is in, or one with --workspace
whoamisame as mehen status
doctorcheck in one go: every workspace on this machine, its key, the vaults, the clock, identity, session label, frozen, and what to do next
lslist the items this machine may use
showshow an item's public metadata (never its value)
templateslist the credential templates and OAuth providers an agent may name (no network)
checkevaluate an item's base policy locally (advisory, not permission to send)
requestask a human for a credential (prints the link for them)
connectask a human to connect an OAuth account (prints the link for them)
waitwait for an intake (int_), approval (apr_), connection (con_), enrolment (enr_) or policy proposal (pol_)
pendinglist the asks still waiting for a human, or show one again (mehen pending [<id>|<slug>])
policyread policy or stop access; preview and propose are unavailable in this release
fetchmake an HTTP request with an item's credential, through the vault
revokerevoke this workspace's device key and forget it locally
freezefreeze the whole workspace: every use is refused until a human unfreezes it
guidehow agents use the vault: references, intake, next, exit codes
versionprint the mehen version and the commit it was built from
runrun a command with the project's variables (mehen run [--env <env>] -- <command>)
envlist, check or set the project's variables (mehen env ls|check|set)
initcreate the project and write mehen.toml
workspacelist, show, forget or bind a checkout to this machine's workspaces (mehen workspace list|show|forget|bind)
mcpserve the vault tools over MCP on stdio

setup#

Register the Mehen MCP server and skills in your installed agents, at user level.

mehen setup [--agent <name>]... [--workspaces <a,b>] [--mcp-file <path>] [--remove] [--dry-run] [--force] [--reset-env] [--print [--format json|toml]]
FlagShortTakes
--agenta value; repeatable
--workspacesa value
--mcp-filea value
--dry-runnothing (a switch)
--removenothing (a switch)
--forcenothing (a switch)
--reset-envnothing (a switch)
--printnothing (a switch)
--formata value

Examples:

mehen setup --json
mehen setup --agent codex --dry-run
mehen setup --workspaces acme --agent claude-code
mehen setup --mcp-file /path/to/mcp.json
mehen setup --print --format toml
mehen setup --remove

update#

Check for or install a signed Mehen release and refresh managed skills.

mehen update [--check] [--force] [--version <v>] [--rollback]
FlagShortTakes
--checknothing (a switch)
--forcenothing (a switch)
--versiona value
--rollbacknothing (a switch)
--backgroundnothing (a switch)

Examples:

mehen update --check --json
mehen update --json
mehen update --rollback --json

enrol#

Enrol this machine in a workspace: prints the link a human accepts in the browser, then mehen wait finishes it; the key is kept across attempts.

mehen enrol --workspace <slug> [--name <machine-name>] [--team <team-slug>] [--backend secure-enclave|software] [--fresh-key] [--wait] [--no-renew] [--connect <code>]
FlagShortTakes
--namea value
--teama value
--backenda value
--fresh-keynothing (a switch)
--waitnothing (a switch)
--no-renewnothing (a switch)
--connecta value

Examples:

mehen enrol --workspace acme --name my-laptop
mehen enrol --workspace acme --name ci-runner --team ci --backend software --json

status#

Show every workspace this machine is in, or one with --workspace.

mehen status [--workspace <slug or id>]

No flags of its own; the global flags apply.

Examples:

mehen status
mehen status --json
mehen status --workspace acme

whoami#

Same as mehen status.

mehen whoami

No flags of its own; the global flags apply.

Examples:

mehen whoami --json

doctor#

Check in one go: every workspace on this machine, its key, the vaults, the clock, identity, session label, frozen, and what to do next.

mehen doctor

No flags of its own; the global flags apply.

Examples:

mehen doctor
mehen doctor --json

ls#

List the items this machine may use.

mehen ls [--tag <tag>] [--kind <kind>] [--provider <provider>]
FlagShortTakes
--taga value
--kinda value
--providera value

Examples:

mehen ls
mehen ls --kind api-key --json
mehen ls --provider openai

show#

Show an item's public metadata (never its value).

mehen show <item>

No flags of its own; the global flags apply.

Examples:

mehen show openai-personal
mehen show gmail-personal --json

templates#

List the credential templates and OAuth providers an agent may name (no network).

mehen templates [<id>]

No flags of its own; the global flags apply.

Examples:

mehen templates
mehen templates google-gmail --json

check#

Evaluate an item's base policy locally (advisory, not permission to send).

mehen check <item> <METHOD> <URL> [-H 'Name: value']... [-d @file|-|text]
FlagShortTakes
--header-Ha value; repeatable
--data-da value

Examples:

mehen check openai-personal GET https://api.openai.com/v1/models
mehen check gmail-personal POST https://gmail.googleapis.com/gmail/v1/users/me/messages/send -d @message.json --json

request#

Ask a human for a credential (prints the link for them).

mehen request <kind> --name <slug> --reason <why> [--provider <template>] [--home private|project|workspace] [--project <prj_id>] [--tag <tag>]... [--host <host>]... [--path <glob>]... [--header <name> --format "Bearer {key}"] [--wait] [--new] [--timeout <duration>]
FlagShortTakes
--namea value
--homea value
--projecta value
--providera value
--reasona value
--taga value; repeatable
--hosta value; repeatable
--patha value; repeatable
--headera value
--formata value
--waitnothing (a switch)
--newnothing (a switch)
--timeouta value

Examples:

mehen request api-key --name openai-personal --provider openai --reason 'run the nightly evals against the OpenAI API' --json
mehen request api-key --name snyk --host api.snyk.io --header Authorization --format 'token {key}' --reason 'scan this repo'\''s dependencies'
mehen request api-key --name openai-team --provider openai --home project --project prj_3kQ9vXyZ7 --reason 'run the evals for this project'

connect#

Ask a human to connect an OAuth account (prints the link for them).

mehen connect <provider> --name <slug> --reason <why> [--client <oauth-client-item>] [--home private|project|workspace] [--project <prj_id>] [--scopes a,b] [--expect <account>] [--request-client] [--client-tag <tag>]... [--wait] [--new] [--timeout <duration>]
FlagShortTakes
--clienta value
--namea value
--homea value
--projecta value
--scopesa value; repeatable
--expecta value
--reasona value
--request-clientnothing (a switch)
--client-taga value; repeatable
--waitnothing (a switch)
--newnothing (a switch)
--timeouta value

Examples:

mehen connect google-gmail --name gmail-personal --expect you@example.com --reason 'read and draft replies in your inbox' --request-client --json
mehen connect github-oauth --name github-personal --scopes read:user,repo --reason 'open pull requests for you'

wait#

Wait for an intake (int_), approval (apr_), connection (con_), enrolment (enr_) or policy proposal (pol_).

mehen wait <id> [--timeout <duration>] [--json [--events]]
FlagShortTakes
--timeouta value
--eventsnothing (a switch)

Examples:

mehen wait int_3kQ9vXyZ7 --timeout 10m
mehen wait apr_7Hq2 --json --events

pending#

List the asks still waiting for a human, or show one again (mehen pending [<id>|<slug>]).

mehen pending [<id>|<slug>]

No flags of its own; the global flags apply.

Examples:

mehen pending
mehen pending apr_7Hq2 --json

policy#

Read policy or stop access; preview and propose are unavailable in this release.

mehen policy show <item> | preview --file <path|-> | propose --file <path|-> | propose --item <slug> --policy-mode <relaxed|yolo> (--session|--device) --host <host> --method <METHOD> --path <pattern> --anchor-path <path> --reason <text> | cancel <pol_id> | stop <pov_id|gnt_id>
FlagShortTakes
--filea value; repeatable
--newnothing (a switch)
--sessionnothing (a switch)
--devicenothing (a switch)
--itema value; repeatable
--policy-modea value; repeatable
--actiona value; repeatable
--hosta value; repeatable
--methoda value; repeatable
--patha value; repeatable
--anchor-patha value; repeatable
--reasona value; repeatable
--fora value; repeatable
--untila value; repeatable

Examples:

mehen policy show example-key
mehen policy preview --file proposal.json
mehen policy propose --file - --json
mehen policy stop pov_example

fetch#

Make an HTTP request with an item's credential, through the vault.

mehen fetch <item> <METHOD> <URL> [-H 'Name: value']... [-d @file|-|text] [--project <prj_id> --env <name>] [--approval apr_...] [--fail] [-o <file>] [--select <path>] [-i] [--max-time <duration>]   (or mehen fetch --run <run> <METHOD> <URL>)
FlagShortTakes
--header-Ha value; repeatable
--projecta value
--enva value
--data-da value
--runa value
--approvala value
--failnothing (a switch)
--output-oa value
--selecta value
--include-inothing (a switch)
--max-timea value

Examples:

mehen fetch openai-personal GET https://api.openai.com/v1/models --select data.0.id
mehen fetch openai-personal POST https://api.openai.com/v1/responses -H 'Content-Type: application/json' -d @body.json
mehen fetch github-work GET https://api.github.com/repos/acme/app/tarball -o app.tar.gz --max-time 2m
mehen fetch stripe-prod GET https://api.stripe.com/v1/balance --project prj_3kQ9vXyZ7 --env prod

revoke#

Revoke this workspace's device key and forget it locally.

mehen revoke [--workspace <slug or id>]

No flags of its own; the global flags apply.

Examples:

mehen revoke
mehen revoke --workspace acme

freeze#

Freeze the whole workspace: every use is refused until a human unfreezes it.

mehen freeze

No flags of its own; the global flags apply.

Examples:

mehen freeze

guide#

How agents use the vault: references, intake, next, exit codes.

mehen guide

No flags of its own; the global flags apply.

Examples:

mehen guide

version#

Print the mehen version and the commit it was built from.

mehen version
FlagShortTakes
--extract-helpera value

Examples:

mehen version --json

run#

Run a command with the project's variables (mehen run [--env <env>] -- <command>).

mehen run [--env <env>] [--approval <id>] [--] <command> [args...]
FlagShortTakes
--envsee the usage
--approvalsee the usage

Global flags: see the exceptions above; the usage lists what this command accepts.

env#

List, check or set the project's variables (mehen env ls|check|set).

mehen env ls [--env <env>] [--json] | mehen env check [--env <env>] [--json] | mehen env set <NAME> --env <env> [--item <slug> [--field <field>]] [--plain <value>]
FlagShortTakes
--envsee the usage
--jsonsee the usage
--itemsee the usage
--fieldsee the usage
--plainsee the usage

Global flags: see the exceptions above; the usage lists what this command accepts.

init#

Create the project and write mehen.toml.

mehen init [--slug <slug>] [--env <name>]...
FlagShortTakes
--slugsee the usage
--envsee the usage

Global flags: see the exceptions above; the usage lists what this command accepts.

workspace#

List, show, forget or bind a checkout to this machine's workspaces (mehen workspace list|show|forget|bind).

mehen workspace list [--check] | show | forget (<slug or id> | --slot <path>) | bind
FlagShortTakes
--checksee the usage
--slotsee the usage

Examples:

mehen workspace list --json
mehen workspace show
mehen workspace forget acme
mehen workspace bind

mcp#

Serve the vault tools over MCP on stdio.

mehen mcp [--workspace <slug or id>]
FlagShortTakes
--workspacesee the usage

Global flags: see the exceptions above; the usage lists what this command accepts.