How Agent Profile Works

A deterministic, privacy-first pipeline from repository discovery to subprocess launch.

The Core Principle: Your Agents, in Separate Rooms

Modern software engineers routinely switch contexts: corporate client code, internal proprietary services, personal hobby projects, and open-source contributions. Yet virtually every coding assistant defaults to storing tokens, prompt histories, MCP servers, and cached context in a single global home folder (such as ~/.claude/, ~/.codex/, or ~/.config/cursor/).

This creates serious security risks:

Agent Profile solves this by establishing clean, deterministic profile rooms per repository. The agent owns authentication; Agent Profile owns profile selection.

The 6-Stage Execution Pipeline

Every execution of agent-profile follows a strict, one-way data pipeline where each stage verifies invariants before advancing:

Stage 1

CLI Invocation & Argument Separation

Parses the agent name (e.g. claude, codex, aider), optional profile word, and wrapper flags (--dry-run, --repo <path>). Everything after -- is isolated and preserved verbatim to pass to the agent process untouched.

Stage 2

Canonical Repository Discovery

Discovers the git repository for the current working directory (or --repo override). Resolves symlinks, NTFS junctions, and path casing to a single canonical root. Git submodules and linked worktrees are strictly treated as distinct repositories of their own.

Stage 3

Deterministic Precedence Resolution

Resolves the target profile through an unyielding 4-step ladder: Agent-specific mapping → Repository mapping → default_profile → Error. It never guesses from directory names or Git branch names.

Stage 4

Adapter Synthesis

Invokes the agent's adapter to produce relocated environment variables (e.g. CLAUDE_CONFIG_DIR, CODEX_HOME) or flag arguments (e.g. --config). The adapter computes data only; it never spawns processes.

Stage 5

LaunchPlan Verification

Emits an immutable LaunchPlan specifying executable path, arguments, working directory, and environment modifications. In --dry-run mode, this plan is formatted and printed for operator inspection.

Stage 6

Subprocess Launch & Signal Forwarding

The centralized process launcher executes the agent binary with the sterile environment. Process exit codes, signals (SIGINT, SIGTERM), and standard streams pass through cleanly.

The Deterministic Precedence Ladder

When launching without an explicit profile name (for example, agent-profile claude), the profile is resolved deterministically:

Priority Source Mechanism Scope
1. Highest Agent-specific repository link agent-profile <agent> link <profile> Applies only to this specific agent in this canonical repository root.
2. Second Repository-wide link agent-profile link <profile> Applies to all agents launched in this canonical repository root.
3. Third Global default profile default_profile = "name" in config.toml Fallback profile when no repository-specific mapping exists.
4. Terminal Resolution Error Non-zero exit with descriptive diagnostic Refuses to guess. Suggests exact link or create commands.

To inspect how the current repository resolves without running an agent, use agent-profile <agent> resolve or agent-profile status.

Repository Boundaries: Worktrees, Submodules, and Junctions

A repository mapping applies strictly to that canonical repository:

The LaunchPlan Architecture

In classical CLI wrapper designs, individual agent plugins directly call std::process::Command::spawn. This architectural flaw makes wrapper behavior impossible to test without side effects and encourages inconsistent signal handling.

Agent Profile implements a clean separation of concerns:

CLI Command
  ↓
Repository Discovery (Canonical Git Root)
  ↓
Profile Resolution (Deterministic Ladder)
  ↓
Agent Adapter (Calculates Environment & Arguments)
  ↓
LaunchPlan (Immutable Pure Data Structure)
  ↓
Process Launcher (Executes Subprocess in Clean Environment)
    

Adapters produce a LaunchPlan; they never spawn processes. This guarantees that every adapter is 100% unit testable in pure Rust, and the launcher enforces security invariants across all twelve adapters.

The Evidence-Based Isolation Harness

We do not trust vendor documentation when it claims an environment variable or flag provides isolation. Every adapter in Agent Profile is verified through an empirical sandbox test harness in Linux containers:

Review the Complete 12-Agent Matrix →