# Directory references

A reference is a name for a folder outside the working directory. The user registers it once; every conversation then reaches it as `@name` or `@name/sub/path`. User page: [References](https://openprogram.io/docs/capabilities/references.html).

| Part | Design |
| --- | --- |
| Registry | `references` in the profile's `config.json`: `{name: {path, writable?, description?}}` or `{name: {repository, branch?, description?}}`, written through `update_config` |
| Told to the model | One line in `<environment>`: every reference by name, with its path, access and description |
| Mention | The composer's `@` file mention. A first segment that names a reference resolves inside it |
| Read | Open, as any folder outside the working directory, under the sandbox's read denials |
| Write | Refused into a read-only reference in every mode; a writable one counts as a working directory |
| Repository | Cloned once, shallow, into `<state>/references/<host>/<path>[@<branch>]`; always read-only; updated by `refresh` |
| Management | `openprogram references list\|add\|remove\|refresh` and `/references` on the shared command registry |

## Decisions

| Question | Choice | Why |
| --- | --- | --- |
| Named or a plain extra directory | Named, persistent, per profile | OpenCode, the only harness with names, keys `references` by alias in its config. Oh My Pi persists `workspace.additionalDirectories` but without names; Claude Code, Codex, KimiCode, Copilot CLI and Antigravity take `--add-dir` per session. A name is what lets a message point at the folder. |
| Word | “references” | OpenCode's term. `/context` already shows the token breakdown, so “contexts” would sit one letter from it in the slash menu. |
| Mention syntax | The existing `@path`: `@name`, `@name/path`; `@./name` reaches a same-named folder of the working directory | The Web menu and resolver work unchanged, and the TUI already sends `@path` as typed. A registered name wins the first segment because the user chose it. |
| What a mention sends | A file becomes the usual path attachment; a folder stays as typed | Every attachment reaches the model as a path it reads on demand. OpenCode attaches a listing of the root; here the system line already maps the name to its path. |
| Which references the model sees | All of them, sorted by name | OpenCode advertises only described ones, but its clients attach the alias. The TUI, channels and `--print` send the text as typed, so the model needs every name to read `@name`. |
| Prompt cache | The line is built from the registry alone | It stays byte-identical turn to turn and changes only when a reference is added or removed. |
| Default access | Read-only; `--writable` for a local folder | OpenCode references grant no permission of their own. Claude Code's additional directories and Codex's `--add-dir` are writable roots. Reading outside the working directory is already open, so the mark that changes behaviour is the write one. |
| Where read-only is enforced | `permission_decision`, after identity and before the owner's rules | Like Plan's read-only promise, it holds in Bypass and outranks allow rules. Write targets come from the call's arguments or the tool profile's `written_paths`, so `write`, `edit` and `apply_patch` are covered. |
| Nesting | The closest folder holding the target decides | A project inside a read-only reference stays writable; a read-only `vendor` inside the project stays protected. |
| Sandbox | Writable references join `writable_roots`; read-only ones are not roots | The sandbox already refuses writes outside its roots, so read-only needs no extra rule there. Read denials (credentials) are not lifted. |
| Repositories | `https://`, `ssh://`, `git://`, `git@host:path`; refreshed only on request | OpenCode clones into a per-remote cache and refreshes daily in the background. Here nothing reaches the network unasked; the clone is shallow and single-branch. |
| Clone safety | `--` before the URL, `file` and `ext` transports off, no terminal prompt, branch names checked, host and path segments checked before they become folders | The URL is user text handed to Git, and its parts become folder names under the profile. |
| Remove | Forgets the name; deletes a clone no other reference uses | A clone lives in OpenProgram's cache and can be cloned again; a user's folder is never touched. |

## Data path

| Stage | Code | Behaviour |
| --- | --- | --- |
| Register | `state/directory_references.py`, `interfaces/cli/commands/capabilities/references.py`, `runtime/commands/directory_references.py` | Validates the name and folder, or clones; a relative folder is read from the CLI's directory or the conversation's working directory |
| Suggest | `/api/file-search` in `interfaces/server/routes/files/file_search.py` | Matching names lead the results as folders; `name/partial` walks the reference |
| Attach | `/api/file-resolve` | `name/path` resolves inside the reference; leaving it by `..` or a symlink is a 400. Reference folders are attachment roots, so the chip opens |
| Prompt | `environment_block` in `runtime/context/prompt_assembly/components.py` | Adds the line; left out when the file tools act on another machine |
| Read | `state/worktree/path_resolve.py` | No outside-worktree warning for a path inside a reference |
| Write | `runtime/permissions/file_safety.py`, `policy.py`, `identity.path_is_safe`, `host/sandbox` | `READ_ONLY_REFERENCE` refusal; writable references in the Accept edits fence and the sandbox roots |

## Implementation status

| Item | Status |
| --- | --- |
| TUI `@` menu | Walks the local disk itself and does not list references yet; `@name/path` typed there works through the system line |
| Shell commands | Checked only by the sandbox. A read-only reference inside a sandbox writable root is protected from the file tools only |
| Automatic refresh | None; `refresh` is explicit |

[Additional working directories](https://openprogram.io/docs/reference/design/runtime/session/additional-working-directories.html)
