# `MingaClaudeBridge.Workdir`
[🔗](https://github.com/jsmestad/minga-claude-bridge/blob/main/lib/minga_claude_bridge/workdir.ex#L1)

Private directories the bridge owns: the empty working directory of each `claude` process, and the debug log directory.

Everything lives under one base directory, `<tmp>/minga-claude-bridge-<home uid>`, created with mode 0700. Before it uses any of these directories, `ensure_private_dir/1` checks that it is a real directory (not a symlink) owned by the current user, then sets its mode to 0700. A base that fails the check is an error, never repaired, because another user may control it.

A session directory is `<base>/sessions/<key>`. `create/2` removes a stale directory with the same key first, so the child always starts in an empty directory. Claude Code stores sessions under `~/.claude/projects`, keyed by the working directory path, so a stable `key` per conversation keeps `--resume` working across restarts.

# `error`

```elixir
@type error() :: {:workdir, atom() | {atom(), term()}}
```

# `base_path`

```elixir
@spec base_path(Path.t()) :: Path.t()
```

Returns the base directory path for `tmp_dir`. Does not create it.

# `create`

```elixir
@spec create(Path.t(), String.t()) :: {:ok, Path.t()} | {:error, error()}
```

Creates the empty working directory for session `key` under `base` and returns its path. `key` may hold only letters, digits, `-`, and `_`.

# `ensure_private_dir`

```elixir
@spec ensure_private_dir(Path.t()) :: {:ok, Path.t()} | {:error, error()}
```

Creates (if needed) and checks a 0700 directory owned by the current user.

# `random_key`

```elixir
@spec random_key() :: String.t()
```

Returns a random session key.

# `remove`

```elixir
@spec remove(Path.t() | nil) :: :ok
```

Removes a session directory. Safe to call more than once.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
