Skip to content
BENIBIX Learn

env Option

Also known as Agent SDK environment variables, Claude Agent SDK env

The option that sets env values for the agent.

Think of it like

It is like the bag of things you pack for a helper.

Example

Leo sets env to just his API key in TypeScript, and the agent can no longer find git. He spreads process.env in first, and it works.

Why it matters

With no PATH, each shell command the agent runs fails. The error does not say why.

Definition

env is the Agent SDK option that sets environment variables for the Claude Code process. The two SDKs treat it in different ways. In TypeScript, env replaces the whole set, so spread process.env into it to keep PATH and the rest. In Python, your values are merged on top.

Example code

typescript
env: { ...process.env, DEBUG: "1" }
Keep the inherited variables and add one.

Common mistake

Passing only your new variable in TypeScript. That wipes out all the rest.

Key takeaways

  1. 1
    TypeScript replaces. Spread process.env.
  2. 2
    Python merges. Over the inherited.
  3. 3
    For the agent's process. Not your app.