> ## Documentation Index
> Fetch the complete documentation index at: https://braintrust.dev/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Detecting Remote Eval and CLI Execution Context: SDK Hooks and Environment Variables

export const plans_0 = "Any"

export const deployments_0 = "Any"

export const data_plane_version_0 = undefined

export const use_case_0 = undefined

<Note>
  **Applies to:**

  * Plan - {plans_0}
  * Deployment - {deployments_0}
  * {data_plane_version_0}
  * {use_case_0}
</Note>

Summary

When running evaluations via remote evals, traces may appear minimal compared to CLI evals, and prompts may not be visible in the experiment. This occurs because remote evals run on your infrastructure without Braintrust's instrumented runner. You can detect execution context using environment variables and `hooks.tags` to conditionally adjust tracing, logging, or other behavior between CLI and remote eval runs.

## Configuration Steps

### Step 1: Set Environment Variable for CLI Execution

When running evaluations via CLI, set an environment variable to mark the execution context.

```text theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
BRAINTRUST_CLI=true bt eval my_eval.py

```

### Step 2: Add Context Tag in Task Function

Check the environment variable in your task function and add a tag to identify CLI execution.

```python theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
import os
from braintrust import Eval, EvalCase

def my_task(input, hooks):
    # Add "cli" tag when running via CLI
    if os.getenv("BRAINTRUST_CLI") == "true":
        if hooks.tags is None:
            hooks.tags = ["cli"]
        else:
            hooks.tags = list(hooks.tags) + ["cli"]

    # Your task logic here
    return output

Eval(
    name="my-eval",
    data=lambda: [EvalCase(input="example")],
    task=my_task,
    scores=[...],
)

```

### Step 3: Use Context Detection in Task Logic

Check for the presence of the tag to determine execution context and implement conditional behavior.

```python theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
def my_task(input, hooks):
    is_cli = "cli" in (hooks.tags or [])

    if is_cli:
        # CLI-specific logic (e.g., verbose logging)
        print("Running in CLI context")
    else:
        # Remote eval logic (e.g., reduced logging)
        print("Running in remote eval context")

    return output

```

## Limitations

This approach requires manually prepending the environment variable to every CLI command. There is no built-in SDK support for execution context detection currently available.
