[BUG] Terraform commands crash WSL2 terminal even with stdout/stderr redirected to file

Resolved 💬 3 comments Opened Mar 25, 2026 by PrestonR Closed Mar 29, 2026

Preflight

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report
  • [x] I am using the latest version of Claude Code

What's Wrong?

Running terraform init, terraform plan, or terraform apply via the Bash tool crashes the WSL2 terminal, even when all stdout and stderr are redirected to a file (e.g., terraform plan > out.txt 2>&1).

This used to work in earlier versions of Claude Code. At some point it stopped working and now consistently crashes the terminal session, requiring a full restart.

Suspected root cause

Terraform detects it's running under a PTY and writes progress indicators (spinners, ANSI escape sequences) directly to /dev/tty, bypassing shell-level > file 2>&1 redirection. Claude Code's Bash tool appears to use a pseudo-TTY, which means:

  1. Terraform's progress output goes to the PTY even though stdout/stderr are redirected
  2. The PTY buffer fills up or the accumulated output causes heap pressure
  3. The terminal becomes unresponsive or crashes

This is distinct from the OOM issues tracked in #25926 / #23621 / #16487, which are about background processes accumulating memory. This happens on foreground terraform commands with full output redirection.

Current workaround

The user must run terraform commands manually outside of Claude Code. Claude Code is used to write the Terraform files, but cannot execute any terraform commands at all — not even terraform validate.

Steps to Reproduce

  1. Have a Terraform workspace with an Azure backend (or any remote backend)
  2. Run via Claude Code's Bash tool:

``bash
terraform -chdir=/path/to/workspace init -upgrade > /tmp/init.txt 2>&1
``

  1. Terminal becomes unresponsive or crashes

This reproduces consistently on every attempt. The same command works fine when run directly in the terminal outside of Claude Code.

Environment

  • Claude Code version: Latest
  • Platform: WSL2 (Linux 6.6.87.2-microsoft-standard-WSL2) on Windows
  • Shell: bash
  • Terraform version: ~1.11.x
  • Providers: azurerm, azuread, azuredevops, datadog (multiple providers = longer init)

What Should Happen?

Terraform commands with full output redirection (> file 2>&1) should complete without crashing the terminal. If the Bash tool uses a PTY, consider:

  1. Setting TF_IN_AUTOMATION=1 in the Bash tool environment — this tells terraform to suppress interactive progress output
  2. Using a pipe instead of PTY for command execution when output is being redirected
  3. Setting NO_COLOR=1 to suppress ANSI escape sequences
  4. Detecting and handling /dev/tty writes from child processes

Related Issues

  • #25926 — heap OOM from unbounded message accumulation (closed as stale)
  • #24004 — long-running background tasks cause Aborted() cascade (closed as dupe)
  • #23621 — OOM from hanging background processes (closed as dupe)
  • #16487 — root issue in the dupe chain

None of these exactly match this scenario (foreground terraform with redirected output on WSL2).

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗