Workspace Resolver
How AGH registers workspace roots, resolves the active workspace, and discovers project-local runtime resources.
- Audience
- Operators running durable agent work
- Focus
- Workspaces guidance shaped for scanability, day-two clarity, and operator context.
A workspace is a registered project root. AGH stores the registration in the global database, but the filesystem remains the source of truth. Each session starts by resolving a workspace snapshot: the canonical root directory, optional additional roots, effective configuration, visible agents, and visible skill directories.
That is the portability model: copy the project directory with its .agh/ directory, register the
new path, and the same project agents, skills, memory files, and config overlay travel with it.
What Gets Stored
AGH stores workspace registrations in the global catalog database at ~/.agh/agh.db. The
workspaces table stores:
| Field | Meaning |
|---|---|
id | Stable ID with a ws_ prefix. Sessions reference this ID. |
root_dir | Canonical absolute root path after symlink evaluation. |
add_dirs | JSON list of canonical additional roots. |
name | Human-friendly unique name for CLI and API lookup. |
default_agent | Optional workspace default agent override. |
created_at, updated_at | Registration timestamps. |
The ID is random and stable. The default name comes from the root directory basename, and AGH adds
numeric suffixes such as repo-2 when another workspace already has the same name.
Typical .agh/ Layout
my-repo/
.env
.agh/
config.toml
mcp.json
agents/
reviewer/
AGENT.md
mcp.json
skills/
repo-map/
SKILL.md
mcp.json
references/
architecture.md
memory/
MEMORY.md
release-rules.md| Path | Used by | Behavior |
|---|---|---|
<workspace>/.agh/config.toml | Config loader | Overlays built-in defaults and global config for this workspace root. |
<workspace>/.agh/mcp.json | Config loader | Adds or replaces top-level MCP servers after workspace TOML is applied. |
<workspace>/.agh/agents/<name>/AGENT.md | Resolver | Makes an agent visible to sessions in this workspace. |
<workspace>/.agh/agents/<name>/mcp.json | Agent loader | Replaces same-name MCP servers declared inline in that agent definition. |
<workspace>/.agh/skills/<name>/SKILL.md | Resolver + skills registry | Makes a skill directory visible to sessions in this workspace. |
<workspace>/.agh/skills/<name>/mcp.json | Skills registry | Replaces same-name MCP servers declared in that skill's frontmatter. |
<workspace>/.agh/memory/ | Memory runtime | Stores workspace-scoped memory files after the workspace root is resolved. |
<workspace>/.env | Config loader | Optional. Loaded before AGH_HOME is resolved when config is loaded for this workspace. |
The resolver directly snapshots config, MCP sidecars, agent definitions, and skill definitions. Workspace memory uses the resolved root, but memory files are managed by the memory runtime instead of by the workspace resolver.
Resolution Inputs
AGH resolves workspaces from three kinds of input:
| Input | Example | Lookup |
|---|---|---|
| Workspace ID | ws_8f33a913d23c4fd1 | Primary key lookup. |
| Workspace name | checkout-api | Unique name lookup. |
| Absolute path | /Users/you/src/checkout-api | Canonical path lookup after filepath.Abs and EvalSymlinks. |
Relative paths are not accepted by API workspace create/resolve requests or by agh session new --cwd. The resolver itself also requires the path to exist and to be a directory.
Register A Workspace
Use agh workspace add when you want the directory to appear in agh workspace list and to have a
stable name:
agh workspace add /Users/you/src/checkout-api --name checkout-apiAdd a workspace-local default agent when this project should start a different agent from your global default:
agh workspace add /Users/you/src/checkout-api \
--name checkout-api \
--default-agent reviewerThe command writes one registration row and immediately resolves it. If the root is missing, is not a directory, or contains invalid workspace config or agent definitions, the registration is rolled back.
Auto-Registration
AGH can also register a workspace on demand:
agh session new --cwd /Users/you/src/checkout-api --agent reviewerWhen --cwd points to a path that is not registered yet, ResolveOrRegister canonicalizes the
path, creates a registration, and resolves the new workspace before starting the session.
The CLI default is also path-based. If you run agh session new without --workspace or --cwd,
the CLI sends its current working directory as workspace_path, so that directory is resolved or
registered automatically.
Use --workspace when you want to target an existing registration by name or ID:
agh session new --workspace checkout-api --agent reviewer--workspace and --cwd are mutually exclusive. The HTTP and UDS create-session contract mirrors
that rule: send either workspace or workspace_path, not both.
Resolution Cascade
For this setup:
~/.agh/
config.toml
agents/
general/AGENT.md
reviewer/AGENT.md
skills/
repo-map/SKILL.md
/Users/you/src/checkout-api/
.agh/
config.toml
agents/
reviewer/AGENT.md
skills/
repo-map/SKILL.md
payment-rules/SKILL.mdRunning this command:
agh session new --workspace checkout-api --agent reviewerproduces this cascade:
checkout-apiis looked up as a registered workspace name.- The stored
root_diris checked withos.Stat. - The root is canonicalized again with
EvalSymlinks. If the canonical target changed, AGH updates the storedroot_dir. - Config is loaded as built-in defaults, then
~/.agh/config.toml, then~/.agh/mcp.json, then<workspace>/.agh/config.toml, then<workspace>/.agh/mcp.json. - Agents are discovered from
<workspace>/.agh/agents/first, then global~/.agh/agents/. - Skills are discovered from
<workspace>/.agh/skills/first, then global~/.agh/skills/. - Same-name agents and skills use first-wins precedence, so the workspace
reviewerandrepo-mapoverride the global ones. - The session starts with
cwdset to the workspace root and the resolved agent prompt.
Rendering diagram...
Cache And Refresh Behavior
Resolved workspace snapshots are cached in memory by workspace ID. A cached snapshot is reused only when all watched file snapshots still match and the stored workspace fields still match.
The resolver watches:
| Watched path | Why it matters |
|---|---|
~/.agh/config.toml | Global config changes can affect every workspace. |
~/.agh/mcp.json | Global top-level MCP sidecars can affect every workspace. |
<workspace>/.agh/config.toml | Workspace config overlay. |
<workspace>/.agh/mcp.json | Workspace top-level MCP sidecar. |
Every discovered AGENT.md and adjacent mcp.json | Agent availability and startup settings. |
Every discovered SKILL.md and adjacent mcp.json | Workspace skill visibility and MCP sidecars. |
| Agent and skill directories | Additions and removals. |
Cache entries expire after 10 minutes of inactivity. The resolver also exposes an internal
Invalidate(workspaceID) method used by update and unregister flows. There is no public
--force-refresh CLI flag today.
Errors To Expect
| Case | Result |
|---|---|
| Unknown ID, name, or path | workspace not found; HTTP status 404. |
| Registered root no longer exists | workspace root directory no longer exists; HTTP status 410. |
| Root exists but is a file | Validation error; HTTP status 500 through resolver paths or 400 for API path validation failures. |
| Duplicate name | workspace name already in use; HTTP status 409. |
| Duplicate canonical path | workspace path already registered; HTTP status 409. |
| Workspace still has sessions | workspace has sessions; HTTP status 409 when unregistering. |
| Invalid config or agent file | Resolution fails and the registration is not kept on a new add/auto-register. |
Related Pages
- Config Overlays explains the workspace TOML and MCP merge rules.
- Multi-Root Workspaces shows how
--add-dirchanges discovery. - Agent Definitions documents the current
AGENT.mdparser. - Skills Overview explains skill precedence after workspace resolution.
- Global vs Workspace Memory explains workspace memory files.