Computes the environment of a Claude Code child process.
The child must use Claude Code's own login and settings, never Minga's provider keys or the configuration of a parent Claude Code session. child_env/2 builds the environment in three steps:
- Start from the parent environment and remove every variable in
stripped?/1:ANTHROPIC_*,AWS_*,NODE_*, the Bedrock, Vertex, and Foundry switches, the variables a parent Claude Code session sets on its children, and Minga's provider key variables. - Apply the route credential's
enventry. An empty value removes the variable.HOME,CLAUDE_CONFIG_DIR, andUSERPROFILEare rejected, because the bridge reads Claude Code's session files through the parent's values. - Force the variables in
forced/0, which keep Claude Code from compacting on its own, loading claude.ai MCP servers, sending non-essential traffic, cutting MCP tool descriptions, deferring tools behind tool search, or timing out a tool call Minga is still running.
The result is in the format of the :env option of Port.open/2: charlist pairs, with false for a variable to remove. A Port applies :env on top of the inherited environment, so every removal is explicit.
Values are secrets. This module never logs them, and callers must not log the result.
Summary
Functions
Builds the child environment from the parent environment and the credential's env entry.
Returns the final environment as a map, after the same three steps as child_env/2.
The variables step 3 forces.
The credential keys the bridge rejects.
Returns true when step 1 removes the inherited variable name.
Types
Functions
Builds the child environment from the parent environment and the credential's env entry.
Returns {:error, {:forbidden_env, keys}} when the credential sets HOME, CLAUDE_CONFIG_DIR, or USERPROFILE, and {:error, {:invalid_env, keys}} for a credential key that is empty or contains = or a NUL byte, or a value that contains a NUL byte. Error reasons name keys, never values.
Returns the final environment as a map, after the same three steps as child_env/2.
@spec forced() :: env_map()
The variables step 3 forces.
@spec rejected_credential_keys() :: [String.t()]
The credential keys the bridge rejects.
Returns true when step 1 removes the inherited variable name.