github/copilot-sdk · error

Set environment variables via either the client-level env…

Error message

Set environment variables via either the client-level env option or the connection's env (RuntimeConnection.forStdio/forTcp), not both. Prefer the connection-level env for child-process transports.

What it means

Like create_session, resume_session() accepts either a static github_token or a dynamic github_token_provider, and raises this ValueError when both are supplied. The two credential mechanisms are alternatives; supplying both is treated as a config/programming error and rejected before the resume RPC is issued.

Solutions

  1. Supply exactly one: remove github_token or github_token_provider from the resume_session call.
  2. Keep github_token_provider if tokens need refresh; keep github_token for simple static credentials.
  3. Audit wrappers/helpers to forward at most one credential option.

Example fix

// before
await client.resume_session(
    "session-123",
    github_token=token,
    github_token_provider=provider,
)
// after
await client.resume_session(
    "session-123",
    github_token_provider=provider,
)
Defensive patterns

Strategy: validation

Validate before calling

if github_token is not None and github_token_provider is not None:
    raise ValueError("Pass either github_token or github_token_provider, not both")

Try / catch

try:
    await client.resume_session("session-123", **cred_kwargs)
except ValueError as e:
    if "mutually exclusive" in str(e):
        cred_kwargs.pop("github_token", None)
        await client.resume_session("session-123", **cred_kwargs)

Prevention

When it happens

Trigger: Calling resume_session(...) with both github_token and github_token_provider not None - typically because credential options are merged from env vars and code, or a wrapper forwards both unconditionally.

Common situations: Refactoring from static tokens to provider-based auth while leaving the old argument; shared helper functions with two credential parameters where callers populate both; test fixtures setting both for safety.

Related errors


AI-assisted analysis of github/copilot-sdk@cd8cf15dc3 (2026-09-09). Data as JSON: /api/errors/1fbf2b7319641bc4. Report an issue: GitHub.

Appendix: source

Thrown at nodejs/src/client.ts:640

                "env is not supported with RuntimeConnection.forInProcess(): the in-process transport loads " +
                    "the native runtime into the shared host process, whose single environment block cannot " +
                    "carry per-client values. Set the variables on the host process environment instead."
            );
        }
        if (conn.kind === "inprocess" && options.telemetry !== undefined) {
            throw new Error(
                "telemetry is not supported with RuntimeConnection.forInProcess(): telemetry configuration " +
                    "is lowered to environment variables read by native runtime code running in the shared " +
                    "host process, so per-client telemetry cannot be honored in-process. Configure telemetry " +
                    "via the host process environment, or use a child-process transport."
            );
        }
        if (
            (conn.kind === "stdio" || conn.kind === "tcp") &&
            conn.env !== undefined &&
            options.env !== undefined
        ) {
            throw new Error(
                "Set environment variables via either the client-level env option or the connection's env " +
                    "(RuntimeConnection.forStdio/forTcp), not both. Prefer the connection-level env for " +
                    "child-process transports."
            );
        }
        if (conn.kind === "tcp" && conn.connectionToken !== undefined) {
            if (typeof conn.connectionToken !== "string" || conn.connectionToken.length === 0) {
                throw new Error("connectionToken must be a non-empty string");
            }
        }

        this.connectionConfig = conn;

        if (options.sessionFs) {
            this.validateSessionFsConfig(options.sessionFs);
        }
        if (options.builtinPluginDirectories) {
            for (const path of options.builtinPluginDirectories) {

View on GitHub (pinned to cd8cf15dc3)