Implementation:2aronS Duel Agents installTargetEnv
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Configuration, Developer_Tools |
| Last Updated | 2026-10-27 14:00 GMT |
Overview
Concrete tool for writing the environment variables and config files a given install target needs, dispatching to mergeEnvFile for most targets and to patchOpenClawConfig for OpenClaw, provided by @duel-agents/core.
Description
The installTargetEnv function is the install-time dispatcher that turns a target and a validated key into a concrete file write. It delegates to the internal writeTargetEnv function, which:
- Resolves the env-var map via
getEnvForTarget - Resolves the target file path:
claude-code→~/.claude/.env(viaresolveClaudeEnvPath)openclaw→ OpenClaw config (viaresolveOpenClawConfigPath), then patches it and writes the key to~/.openclaw/.envcodex,openai-compat,cursor→ project.env(viaresolveCodexEnvPath)
- For OpenClaw: calls
patchOpenClawConfigfor the JSON5 config, thenmergeEnvFilefor the key in~/.openclaw/.env - For all others: calls
mergeEnvFilewith the full env-var map
Usage
Import this function when you need to:
- Perform the actual file write for an install target
- Orchestrate the full install write path (env vars + OpenClaw config patch)
Code Reference
Source Location
- Repository: Duel-Agents
- File:
packages/core/src/index.ts(lines 198-240)
Signature
/** Resolve env path for each target. */
export function resolveClaudeEnvPath(): string; // ~/.claude/.env
export function resolveCodexEnvPath(cwd?: string): string; // cwd/.env
/** Internal: writes env vars / patches config for a target. */
async function writeTargetEnv(
target: InstallTarget,
apiKey: string,
proxyUrl?: string,
): Promise<{ path: string; vars: Record<string, string>; warnings: string[] }>;
/** Public entry: dispatch to writeTargetEnv for known targets. */
export async function installTargetEnv(
target: InstallTarget,
apiKey: string,
proxyUrl?: string,
): Promise<{ path: string; vars: Record<string, string>; warnings: string[] }>;
Import
import { installTargetEnv } from "@duel-agents/core";
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| target | InstallTarget |
Yes | Which tool to install for |
| apiKey | string |
Yes | Validated Duel key |
| proxyUrl | string |
No | Proxy URL (default getProxyUrl())
|
Outputs
| Name | Type | Description |
|---|---|---|
| returns.path | string |
File path that was written |
| returns.vars | Record<string, string> |
Env vars that were written |
| returns.warnings | string[] |
Conflict warnings from mergeEnvFile
|
| throws | Error |
If target is unknown |
Usage Examples
Install for Claude Code
import { installTargetEnv } from "@duel-agents/core";
const result = await installTargetEnv("claude-code", apiKey);
console.log(`✓ Wrote ${result.path}`);
for (const w of result.warnings) console.warn(`⚠ ${w}`);
// result.path === "~/.claude/.env"
Install for OpenClaw (Config + .env)
import { installTargetEnv } from "@duel-agents/core";
// For openclaw: patches openclaw.json AND writes ~/.openclaw/.env
const result = await installTargetEnv("openclaw", apiKey);
console.log(`✓ Updated ${result.path}`); // the openclaw.json path
Related Pages
Implements Principle
- Principle:2aronS_Duel_Agents_Environment_Routing
- Principle:2aronS_Duel_Agents_Idempotent_Config_Merge
- Principle:2aronS_Duel_Agents_Safe_Config_Patching
- Principle:2aronS_Duel_Agents_Secret_Isolation
Requires Environment
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment