B

Bash Timeouts Polished

All-in-one setting covering configure, timeout, settings, bash. Includes structured workflows, validation checks, and reusable patterns for environment.

SettingClipticsenvironmentv1.0.0MIT
0 views0 copies

Bash Timeouts Polished

Configure timeout and output limits for bash command execution within Claude Code to prevent hanging commands while accommodating complex operations.

When to Use This Setting

Apply this setting when you need to:

  • Prevent long-running build, test, or deployment commands from blocking Claude Code sessions indefinitely
  • Increase default timeout limits for projects with complex compilation or data processing pipelines
  • Control maximum output capture to prevent memory issues from verbose command output

Consider alternatives when:

  • You only run quick, interactive commands that complete within the default 2-minute timeout
  • Your workflow relies exclusively on IDE-integrated terminals rather than Claude Code bash execution

Quick Start

Configuration

name: bash-timeouts-polished type: setting category: environment

Example Application

claude setting:apply bash-timeouts-polished

Example Output

Setting applied successfully. Configuration changes:
- BASH_DEFAULT_TIMEOUT_MS: 120000 (2 minutes)
- BASH_MAX_TIMEOUT_MS: 600000 (10 minutes)
- BASH_MAX_OUTPUT_LENGTH: 100000 characters

Core Concepts

Timeout Management Overview

AspectDetails
Default Timeout120,000 ms (2 minutes)
Maximum Timeout600,000 ms (10 minutes)
Output Limit100,000 characters captured
Exceeded BehaviorCommand terminated, partial output returned
OverridePer-command timeout parameter available

Timeout Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚        Bash Execution Pipeline       β”‚
β”‚                                      β”‚
β”‚  Command ──> Process ──> Output      β”‚
β”‚     β”‚           β”‚          β”‚         β”‚
β”‚  β”Œβ”€β”€β”΄β”€β”€β”€β”  β”Œβ”€β”€β”€β”΄β”€β”€β”€β”€β”  β”Œβ”€β”€β”΄β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚Timer β”‚  β”‚Watchdogβ”‚  β”‚Truncatorβ”‚  β”‚
β”‚  β”‚Start β”‚  β”‚Monitor β”‚  β”‚(100K)   β”‚  β”‚
β”‚  β””β”€β”€β”¬β”€β”€β”€β”˜  β””β”€β”€β”€β”¬β”€β”€β”€β”€β”˜  β””β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚     β”‚          β”‚           β”‚         β”‚
β”‚  timeout?   hang?      overflow?     β”‚
β”‚     β”‚          β”‚           β”‚         β”‚
β”‚  SIGTERM    SIGKILL    truncate      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Configuration

ParameterTypeDefaultDescription
BASH_DEFAULT_TIMEOUT_MSstring"120000"Default timeout for commands in milliseconds
BASH_MAX_TIMEOUT_MSstring"600000"Maximum allowable timeout per command
BASH_MAX_OUTPUT_LENGTHstring"100000"Maximum characters captured from stdout/stderr
BASH_KILL_SIGNALstring"SIGTERM"Signal sent when timeout is reached
BASH_GRACE_PERIOD_MSstring"5000"Time between SIGTERM and forced SIGKILL

Best Practices

  1. Profile Your Build Times First - Measure how long your typical build, test, and deployment commands take before setting timeouts. Set the default timeout to 150% of your longest routine command to provide a comfortable margin without allowing truly hung processes.

  2. Use Per-Command Timeouts for Known Long Operations - Rather than increasing the global default, use the per-command timeout parameter for specific long operations like full test suites or Docker builds. This keeps the safety net tight for most commands.

  3. Set Output Limits Based on Test Verbosity - If your test framework produces verbose output, increase BASH_MAX_OUTPUT_LENGTH accordingly. Truncated test output loses failure details at the end, which are typically the most diagnostic lines.

  4. Monitor for Silent Timeouts - Commands that are terminated by timeout may not produce an error message. Check for timeout-related failures in your workflow and add explicit progress indicators to long-running scripts.

  5. Balance Safety with Usability - Extremely short timeouts interrupt legitimate operations and frustrate developers. Extremely long timeouts defeat the purpose of the safety net. A 2-minute default with 10-minute maximum works well for most development workflows.

Common Issues

  1. Build commands consistently timing out - Your project may have longer build times than the default allows. Increase BASH_DEFAULT_TIMEOUT_MS incrementally (try 180000 or 300000) rather than jumping to the maximum value.

  2. Output truncated losing important error details - Error messages typically appear at the end of output, which gets truncated first. Increase BASH_MAX_OUTPUT_LENGTH or redirect verbose output to a file and read the file separately.

  3. Zombie processes after timeout - Some commands spawn child processes that survive SIGTERM. Set BASH_KILL_SIGNAL to SIGKILL for commands known to resist graceful termination, though this prevents cleanup handlers from running.

Community

Reviews

Write a review

No reviews yet. Be the first to review this template!

Similar Templates