[BUG] Terraform commands crash WSL2 terminal even with stdout/stderr redirected to file
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:
- Terraform's progress output goes to the PTY even though stdout/stderr are redirected
- The PTY buffer fills up or the accumulated output causes heap pressure
- 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
- Have a Terraform workspace with an Azure backend (or any remote backend)
- Run via Claude Code's Bash tool:
``bash``
terraform -chdir=/path/to/workspace init -upgrade > /tmp/init.txt 2>&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:
- Setting
TF_IN_AUTOMATION=1in the Bash tool environment — this tells terraform to suppress interactive progress output - Using a pipe instead of PTY for command execution when output is being redirected
- Setting
NO_COLOR=1to suppress ANSI escape sequences - Detecting and handling
/dev/ttywrites 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).
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗