# get — Retrieve a Value from the Vault

**Script name:** `get`

**Script location:** [`scripts/get.ts`](../../../scripts/get.ts)

**Invoke:**
```bash
npx --yes tsx .opencode/skills/templating-vault/scripts/get.ts \
  --key KEY [--config PATH] [--store-dir SPEC...]
```

**CRITICAL:** Always invoke the script using bash and the format noted above.

## Synopsis

```
get.ts --key KEY [--config PATH] [--store-dir SPEC...]
get.ts --prefix PREFIX [--config PATH] [--store-dir SPEC...]
```

Reads a value by key. If the key is marked `template: true` in its metadata, the
Nunjucks expression is evaluated lazily — resolving variable references from other
non-template keys in the configured stores.

With `--prefix`, returns all key-value pairs under the prefix as a batch.

## Arguments

| Flag | Type | Description |
|------|------|-------------|
| `--key KEY` | string | Dot-separated key to retrieve |
| `--prefix PREFIX` | string | Retrieve all values under this prefix (alternative to --key) |

Exactly one of `--key` or `--prefix` is required.

## Output (stdout)

Single key:
```json
{
  "key": "global.credentials.forgejo_pat",
  "value": "92224acff675c50c5958d1eaca9a688abd405e06",
  "found": true,
  "metadata": {"literal": true, "write_once": true, "type": "hex", ...},
  "evaluated": false
}
```

Key not found:
```json
{"key": "nonexistent", "value": "", "found": false}
```

Prefix batch:
```json
{
  "prefix": "global.credentials",
  "entries": {
    "global.credentials.forgejo_pat": "92224acf...",
    "global.credentials.forgejo_username": "HAL9000"
  },
  "count": 2
}
```

Computed template value (`evaluated: true`):
```json
{
  "key": "computed.merge_pool_size",
  "value": "2",
  "found": true,
  "metadata": {"template": true, ...},
  "evaluated": true
}
```

## Template Evaluation

When `meta.yaml` has `template: true`, the value file contains a Nunjucks expression.
On read, the script:
1. Collects all non-template raw values from configured stores
2. Passes them as variables to Nunjucks
3. Returns the evaluated result

Variables are available by both full key (dots→underscores: `global_config_max_workers`)
and short name (last segment: `max_workers`). Short names match first-found.

Use `{{ var | default(fallback) }}` in templates for absent dependencies.

## Exit Codes

| Code | Meaning |
|------|---------|
| 0 | Success (check `found` field) |
| 1 | Fatal error |

## Dependencies

- Node.js >= 18, `npx tsx`, `nunjucks`, `js-yaml`
