Bash tool runs commands in background despite run_in_background not being set

Resolved 💬 2 comments Opened Mar 6, 2026 by KikeTorillo Closed Apr 4, 2026

Description

The Bash tool intermittently runs commands in background (returning a task_id and writing output to a temp file) even when run_in_background is not set to true in the tool call.

This forces the agent to poll with TaskOutput, adding significant latency to simple commands that complete in seconds.

Reproduction

  1. Call the Bash tool with a simple command like poetry run pytest tests/ -q without setting run_in_background
  2. Instead of returning output directly, it returns:

``
Command running in background with ID: bt2kelt7i. Output is being written to: /tmp/claude-1000/.../tasks/bt2kelt7i.output
``

  1. Subsequent TaskOutput calls with 30s-120s timeouts all return retrieval_status: timeout even though the command finishes in ~4 seconds
  2. The output file remains empty or takes very long to become readable

Expected behavior

Commands should run in foreground and return output directly when run_in_background is not explicitly set to true.

Observed behavior

  • Commands are silently promoted to background execution
  • TaskOutput polling adds minutes of latency to a 4-second test suite
  • Multiple TaskOutput calls with increasing timeouts (30s, 60s, 120s) all timed out before the output was available
  • The output eventually appeared but only after significant delay

Environment

  • Claude Code (CLI)
  • Model: claude-opus-4-6
  • OS: Linux 6.17.0-14-generic (Ubuntu)
  • Shell: bash
  • The Bash permission "Bash(poetry run pytest:*)" and "Bash(poetry run:*)" are both in the allow list

Workaround

None reliable. The behavior is intermittent — the same commands run in foreground in other sessions.

View original on GitHub ↗

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