Environment Variables and CLI Arguments Injected for Hive-Aware Agents in Munder Difflin
The Munder Difflin orchestrator injects nine environment variables and two CLI arguments into hive-aware agents via the ensureAgent() function in src/main/hive.ts, enabling automatic discovery of hive resources, socket communication, and telemetry streaming.
When spawning Claude Code and other hive-aware providers, the Munder Difflin orchestrator automatically configures the runtime environment without manual intervention. This injection mechanism establishes agent identity, communication paths, and observability settings by populating specific environment variables and extending CLI arguments during the spawn process.
Environment Variables Injected for Hive-Aware Agents
The orchestrator sets nine distinct environment variables in src/main/hive.ts within the ensureAgent() function (lines 20-26, 33-38, 68-77, and 78-89). These variables provide read-only metadata about the agent's identity, filesystem context, and operational capabilities.
Core Identity and Directory Variables
The first four variables establish the agent's identity and location within the hive structure:
AGENT_ID: The unique UUID assigned to the spawned agent instance (lines 22-26).AGENT_NAME: A human-readable identifier (e.g., "Michael") for the agent (lines 22-26).HIVE_ROOT: Absolute path to the hive's root directory containingregistry.jsonandfleet.json(lines 22-26).AGENT_DIR: The per-agent working directory located at<HIVE_ROOT>/agents/<id>(lines 22-26).
Communication and Runtime Variables
Additional variables enable technical integration with the hive's infrastructure:
HIVE_NODE: Path to the bundled node wrapper that lets the agent execute helper tools (tools/*.cjs) without requiring Node.js on the systemPATH(lines 33-38).HIVE_SOCK: Path to the Unix or Windows domain socket for event streaming. This variable is injected only for hive-aware agents that support socket communication (lines 78-89).HIVE_PROXY_SESSION: A stable session identifier generated when the provider operates through a proxy sidecar, used for log correlation and cost accounting (lines 20-21).
Telemetry and Observability Variables
For Claude Code agents specifically, the orchestrator injects OpenTelemetry configuration variables to enable metrics collection without modifying CLI flags:
CLAUDE_CODE_ENABLE_TELEMETRY: Set to1when telemetry collection is active (lines 68-70).OTEL_*variables: Complete OpenTelemetry environment configuration including metrics, logs, exporter endpoints, intervals, and resource attributes for the embedded OTLP collector (lines 71-77).
CLI Arguments Injected for Hive-Aware Agents
Beyond environment variables, the orchestrator appends two specific command-line arguments when spawning hive-aware providers. These are defined in src/main/hive.ts lines 81-92.
Protocol and Configuration Arguments
--append-system-prompt: Injects the hive's system prompt generated bythis.injectedPrompt(), containing the protocol description, knowledge-graph flags, and operational instructions (lines 81-82).--settings <path>: Path to a generatedsettings.jsonfile containing hook configuration including theHIVE_SOCKlocation, enabling automatic inbox drainage onStopevents. This argument is added only when both socket and shim are available (lines 88-92).
Non-hive-aware providers fall back to alternative injection mechanisms such as positional prompts or proxy sidecars, bypassing these specific CLI arguments.
Practical Implementation Examples
Spawning a Hive-Aware Agent
The following simplified example demonstrates how ensureAgent() assembles the environment and arguments:
// src/main/hive.ts → ensureAgent()
const env = {
AGENT_ID: meta.id,
AGENT_NAME: meta.name,
HIVE_ROOT: root,
AGENT_DIR: dir,
HIVE_NODE: this.nodeCommand()
// HIVE_SOCK and telemetry vars added conditionally
};
const args = [
'--append-system-prompt',
this.injectedPrompt(meta, dir, root, false, false, null)
];
if (sock && shim) {
env.HIVE_SOCK = sock;
const settingsPath = join(dir, 'settings.json');
this.writeJson(settingsPath, this.hookSettings(shim, meta.cwd, opts.mcpDefaults, opts.theme));
args.push('--settings', settingsPath);
}
spawnProcess('claude', args, { env });
Consuming Injected Variables in Agent Scripts
Agents can reference the injected environment to communicate with the hive:
#!/usr/bin/env bash
# Access injected identity variables
echo "Agent: $AGENT_NAME ($AGENT_ID)"
echo "Working directory: $AGENT_DIR"
# Emit status event via hive socket
node $HIVE_NODE tools/hive-event.cjs \
--sock $HIVE_SOCK \
--type Status \
--payload '{"status":"running"}'
Summary
- Nine environment variables are injected via
ensureAgent()insrc/main/hive.ts, including identity variables (AGENT_ID,AGENT_NAME), directory paths (HIVE_ROOT,AGENT_DIR), and communication endpoints (HIVE_SOCK). - Two CLI arguments (
--append-system-promptand--settings) configure protocol behavior and hook settings exclusively for hive-aware agents. - Telemetry injection occurs through
CLAUDE_CODE_ENABLE_TELEMETRYandOTEL_*variables for Claude Code providers, enabling automated metrics collection. - Conditional logic in lines 78-92 determines whether socket-related variables and settings are appended based on shim availability.
Frequently Asked Questions
What distinguishes a hive-aware agent from other providers in Munder Difflin?
Hive-aware agents understand the Claude-style protocol and can interpret the injected environment variables and CLI arguments defined in src/main/hive.ts. Non-hive-aware providers lack support for --append-system-prompt and --settings, requiring the orchestrator to use alternative mechanisms such as proxy sidecars or positional prompt injection.
How does the HIVE_NODE variable enable agent operations without Node.js on the system PATH?
The HIVE_NODE variable points to a bundled node wrapper that executes helper scripts like agent-env.cjs and kg.cjs using the hive's internal Node.js runtime. This allows agents to invoke tooling even when the host system does not have Node.js installed or available in the environment PATH.
Are telemetry variables injected for all agent types or only Claude Code?
The CLAUDE_CODE_ENABLE_TELEMETRY and OTEL_* environment variables are injected only for Claude Code agents, specifically when telemetry collection is active (lines 68-77). This targeted injection allows the hive to collect usage metrics without altering the CLI flag set of other providers.
What happens if the socket and shim are unavailable during agent spawn?
If sock and shim are not available, the orchestrator skips injecting HIVE_SOCK and omits the --settings argument entirely (lines 88-92). The agent spawns with basic identity variables and the system prompt only, operating without automatic event streaming capabilities.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →