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 getEnvForTarget

From Leeroopedia
Knowledge Sources
Domains Configuration, Developer_Tools
Last Updated 2026-10-27 14:00 GMT

Overview

Concrete tool for mapping a single Duel API key and proxy URL to the target-specific environment variable sets that each supported IDE tool expects, provided by `@duel-agents/core`.

Description

The getEnvForTarget function is the single source of truth for which environment variables each tool needs. It is a pure, side-effect-free switch on the `InstallTarget` union type. The key is re-validated via `requireApiKey` before the mapping is computed, so the returned record always contains a well-formed key.

The mapping covers five targets:

  • claude-code → `ANTHROPIC_BASE_URL`, `ANTHROPIC_API_KEY`, `DUEL_API_KEY`
  • codex / openai-compat → `OPENAI_BASE_URL`, `OPENAI_API_KEY`, `DUEL_API_KEY`
  • cursor → `DUEL_API_KEY`, `DUEL_PROXY_URL`
  • openclaw → `DUEL_API_KEY`, `DUEL_PROXY_URL`

Usage

Import this function when you need to:

  • Determine which env vars to write for a given tool during install
  • Programmatically resolve the env-var set for a target without writing files
  • Extend install support to a new tool by adding a case to the switch

Code Reference

Source Location

  • Repository: Duel-Agents
  • File: packages/core/src/config.ts (lines 59-93)

Signature

export type InstallTarget =
  | "claude-code"
  | "cursor"
  | "codex"
  | "openclaw"
  | "openai-compat";

export function getEnvForTarget(
  target: InstallTarget,
  apiKey: string,
  proxyUrl?: string,           // default: getProxyUrl()
): Record<string, string>;

Import

import { getEnvForTarget, type InstallTarget } from "@duel-agents/core";

I/O Contract

Inputs

Name Type Required Description
target InstallTarget Yes Which IDE tool
apiKey string Yes Validated Duel key (re-validated via requireApiKey)
proxyUrl string No Proxy base URL (default getProxyUrl())

Outputs

Name Type Description
returns Record<string, string> Env var map for the target; throws if key invalid

Usage Examples

Resolve Env Vars for Claude Code

import { getEnvForTarget } from "@duel-agents/core";

const vars = getEnvForTarget("claude-code", "duel_abcd1234_...");
// => { ANTHROPIC_BASE_URL: "https://duelagents.com/v1",
//      ANTHROPIC_API_KEY: "duel_abcd1234_...",
//      DUEL_API_KEY: "duel_abcd1234_..." }

Resolve Env Vars with Custom Proxy

import { getEnvForTarget } from "@duel-agents/core";

const vars = getEnvForTarget("codex", apiKey, "https://staging.duelagents.com/v1");
// => { OPENAI_BASE_URL: "https://staging.duelagents.com/v1",
//      OPENAI_API_KEY: apiKey, DUEL_API_KEY: apiKey }

Related Pages

Implements Principle

Requires Environment

Page Connections

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