Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:2aronS Duel Agents installTargetEnv

From Leeroopedia
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 (via resolveClaudeEnvPath)
    • openclaw → OpenClaw config (via resolveOpenClawConfigPath), then patches it and writes the key to ~/.openclaw/.env
    • codex, openai-compat, cursor → project .env (via resolveCodexEnvPath)
  • For OpenClaw: calls patchOpenClawConfig for the JSON5 config, then mergeEnvFile for the key in ~/.openclaw/.env
  • For all others: calls mergeEnvFile with 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

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment