MingaClaudeBridge.Workdir (minga_claude_bridge v0.1.0)

Copy Markdown View Source

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.

Summary

Functions

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

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

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

Returns a random session key.

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

Types

error()

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

Functions

base_path(tmp_dir \\ System.tmp_dir!())

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

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

create(base, key)

@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(path)

@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()

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

Returns a random session key.

remove(dir)

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

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