# Which Environment Variables Control the Maximum Impact Analysis Depth in Code‑Review‑Graph?

> Discover which environment variables control impact analysis depth in Code-Review-Graph. Learn about CRG_MAX_IMPACT_DEPTH and CRG_MAX_BFS_DEPTH for optimal graph traversals.

- Repository: [Tirth Kanani/code-review-graph](https://github.com/tirth8205/code-review-graph)
- Tags: how-to-guide
- Published: 2026-08-16

---

**The `CRG_MAX_IMPACT_DEPTH` environment variable controls the maximum depth for impact analysis, defaulting to `2` BFS hops, while `CRG_MAX_BFS_DEPTH` provides a separate cap for generic graph traversals at `15` hops.**

Impact analysis is a core feature of `tirth8205/code-review-graph` that traces how code changes propagate through your codebase. The tool performs a breadth‑first search (BFS) to explore callers, callees, tests, and other dependencies affected by modified files. This article explains exactly which environment variables govern that exploration depth and how to configure them.

## Primary Variable: CRG_MAX_IMPACT_DEPTH

The blast‑radius (impact‑radius) analysis walks the code‑graph up to a configurable number of hops. This depth is governed by `CRG_MAX_IMPACT_DEPTH`.

| Variable | What it Controls | Default Value | Source Location |
|----------|----------------|---------------|-----------------|
| `CRG_MAX_IMPACT_DEPTH` | Maximum BFS hops when computing the impact radius (callers, callees, tests, etc.) | `2` | [`code-review-graph-vscode/src/backend/sqlite.ts`](https://github.com/tirth8205/code-review-graph/blob/main/code-review-graph-vscode/src/backend/sqlite.ts) lines 441‑447 |

In the SQLite backend, the impact query implementation reads this variable to set the `maxDepth` parameter for its BFS loop. The smaller the default, the faster the analysis—but potentially at the cost of missing transitive dependencies.

## Secondary Variable: CRG_MAX_BFS_DEPTH

A related but distinct variable exists for other traversal operations:

| Variable | What it Controls | Default Value | Source Location |
|----------|----------------|---------------|-----------------|
| `CRG_MAX_BFS_DEPTH` | Upper bound for generic graph traversals (e.g., `traverse_graph_tool`) | `15` | [`README.md`](https://github.com/tirth8205/code-review-graph/blob/main/README.md) Environment Variables table |

**Critical distinction:** `CRG_MAX_BFS_DEPTH` does **not** affect impact‑radius logic directly. It only caps other BFS‑based queries exposed by the tool.

## How to Configure Impact Analysis Depth

### Bash/Shell Configuration

```bash

# Increase impact depth to 4 hops for more thorough analysis

export CRG_MAX_IMPACT_DEPTH=4

# Run the CLI—the new depth takes effect immediately

code-review-graph detect-changes --brief

```

### Python API Usage

```python
import os
from code_review_graph import GraphReader

# The backend reads the env var automatically; you can also pass it manually

depth = int(os.getenv("CRG_MAX_IMPACT_DEPTH", "2"))
impact = GraphReader().getImpactRadius(changed_files, depth)

print(f"Impact radius (depth={depth}) includes {len(impact.impactedNodes)} nodes")

```

Note that changing the variable only requires a new process start (or re‑export) because the CLI reads it at runtime.

## Key Implementation Files

Understanding where these variables are consumed helps with debugging and customization:

- **[`code-review-graph-vscode/src/backend/sqlite.ts`](https://github.com/tirth8205/code-review-graph/blob/main/code-review-graph-vscode/src/backend/sqlite.ts)** – Defines the BFS loop that respects `maxDepth`, with the value taken from `CRG_MAX_IMPACT_DEPTH` at lines 441‑447 according to the `tirth8205/code-review-graph` source code.

- **[`README.md`](https://github.com/tirth8205/code-review-graph/blob/main/README.md)** – Lists all configurable environment variables, including both `CRG_MAX_IMPACT_DEPTH` and `CRG_MAX_BFS_DEPTH`, in the Environment Variables table.

## Performance Trade‑offs

Adjusting `CRG_MAX_IMPACT_DEPTH` changes how many transitive levels the blast‑radius explorer follows:

- **Lower values (1‑2):** Faster analysis, suitable for quick feedback in CI pipelines.
- **Higher values (4‑6+):** More thorough detection of indirect impacts, but with exponentially growing query times on large codebases.

## Summary

- **`CRG_MAX_IMPACT_DEPTH`** is the primary environment variable controlling maximum impact analysis depth—set this to adjust blast‑radius exploration.
- Default depth is `2` BFS hops, balancing speed and coverage.
- **`CRG_MAX_BFS_DEPTH`** is a separate variable for generic traversals and does not affect impact analysis.
- Changes take effect on process restart; no configuration file edits required.
- The implementation resides in [`code-review-graph-vscode/src/backend/sqlite.ts`](https://github.com/tirth8205/code-review-graph/blob/main/code-review-graph-vscode/src/backend/sqlite.ts) with documentation in [`README.md`](https://github.com/tirth8205/code-review-graph/blob/main/README.md).

## Frequently Asked Questions

### What happens if I don't set CRG_MAX_IMPACT_DEPTH?

The tool defaults to `2` hops, meaning it explores direct callers, callees, and tests of changed files, plus one additional level of transitive dependencies. This provides reasonable coverage without excessive query overhead.

### Can I use CRG_MAX_BFS_DEPTH to control impact analysis?

No. According to the source code, `CRG_MAX_BFS_DEPTH` governs generic graph traversal tools like `traverse_graph_tool` but does not influence the impact‑radius calculation. Always use `CRG_MAX_IMPACT_DEPTH` for blast‑radius analysis.

### Do I need to rebuild or reinstall after changing these variables?

No rebuild is necessary. The CLI reads environment variables at runtime, so simply export the new value and restart the process. The Python API also respects freshly set environment variables on new `GraphReader` instantiations.

### Where is the depth limit enforced in the source code?

The BFS loop in [`code-review-graph-vscode/src/backend/sqlite.ts`](https://github.com/tirth8205/code-review-graph/blob/main/code-review-graph-vscode/src/backend/sqlite.ts) (lines 441‑447) retrieves the depth from `CRG_MAX_IMPACT_DEPTH` and uses it as the `maxDepth` termination condition for the impact radius query.