Last updated 13 October 2026
Run interactive scripts in Claude Code
The terminal hang problem
When you tell Claude Code to run a script that requires manual confirmation, the Bash tool often waits for input that never arrives. You see the agent stall as it tries to read from a standard input stream that is not connected to your keyboard. The agent runs as a process in your shell and treats most scripts as non-interactive background tasks. If a script blocks to ask for a confirmation like a yes or no prompt, the session freezes until you press Escape to interrupt the tool.
Developers encounter this most often when running package managers or deployment scripts that enforce a safety check. You might ask the agent to install a list of dependencies or migrate a database, only to find it stuck at a hidden prompt. The agent cannot see the prompt in the same way you do in a standard terminal. It receives the output buffer, but it lacks the mechanism to send a single keystroke back to the process unless you explicitly tell it how to handle the interaction.
Use non-interactive flags and environment variables
The most reliable way to handle interactive scripts is to prevent the interaction from happening at all. Most modern command line tools provide a flag to skip confirmation prompts or a way to set a non-interactive mode via environment variables. Check the manual for the specific tool you use to find these options. Common flags include -y or --yes for package managers, and --force or --non-interactive for deployment tools.
If you work on a project where these flags are required for every run, document them in the CLAUDE.md file at the root of your repository. This file acts as the primary instruction set for the agent. By telling the agent to always use specific flags when running certain commands, you ensure that the Bash tool never hits a blocking prompt. This keeps the agent moving through its task list without needing your intervention to bypass safety checks.
Pipe input with the yes command
When a script does not offer a non-interactive flag, you can use the standard Unix pipe to provide the necessary input. The yes command is a utility that outputs a string repeatedly, which is usually the letter y followed by a newline. By piping the output of yes into your interactive script, you effectively answer every confirmation prompt with a positive response. This allows the Bash tool to complete the execution without waiting for user input.
You must be careful when using this technique because it bypasses all safety warnings. If a script asks for confirmation before deleting data, piping yes into it causes the deletion to happen immediately. Only instruct the agent to use this method for scripts where you are certain the outcome is safe. If the script requires a specific string other than y, provide that string as an argument to the yes command to satisfy the prompt requirements.
Direct the agent via project instructions
The CLAUDE.md file is the best place to store specific patterns for your build system. If your project uses a custom script that asks for a port number or an environment name, write a section in CLAUDE.md that tells the agent the correct values to provide. Instruct the agent to use a specific syntax like echo value | script.sh to pass the required data through standard input. This makes the agent more autonomous and reduces the number of times it asks you for help.
When you have many different projects with different terminal requirements, managing them one by one becomes a chore. This is where adhdTerminal helps by letting you see multiple Claude Code sessions at once. You can have one tile for your frontend and another for your backend, each using its own CLAUDE.md instructions. The app shows the last exchanges of the conversation on the tile, so you can quickly see if a script is waiting for input or if it finished successfully without switching windows.
Handle complex interactions with custom slash commands
For scripts that require a sequence of different inputs, a simple pipe might not work. In these cases, create custom slash commands in the .claude/commands directory. These are markdown files that define a specific set of actions or instructions for the agent to follow. Define a command that tells the agent to run a script and then provide a specific sequence of inputs using the Bash tool. This encapsulates the complexity of the interaction inside a single command name.
Custom commands allow you to move the logic of script interaction out of the main conversation. Instead of explaining the steps to the agent every time, you just run the custom slash command. This keeps the session history clean and prevents the context window from filling up with repetitive instructions. If a custom command starts to get too long, use /compact to summarize the session and keep the agent focused on the current task while maintaining the essential context.
Debugging terminal issues with the doctor tool
If a script behaves differently inside Claude Code than it does in your regular terminal, use the claude doctor command. This tool checks the installation and environment to ensure everything is set up correctly. It identifies issues with path configurations or missing dependencies that might cause a script to fail or prompt for input unexpectedly. Running this command is a good first step when you encounter persistent terminal behavior that you cannot explain.
Check the .claude/settings.json file for your project to see if any permission modes interfere with tool execution. If you are in plan mode, the agent will not execute the Bash tool at all, which might look like a hang if you expect it to run a script. Switching to default or bypassPermissions using Shift+Tab allows the agent to actually run the commands. This ensures that the agent has the necessary authority to interact with the shell and process the scripts as intended.
Use subagents for isolated script tasks
Sometimes a script is so complex or risky that you want to handle it in a separate context. Define subagents in the .claude/agents directory to handle these specific terminal tasks. A subagent has its own set of instructions and a narrower focus, which prevents it from making mistakes in the main project tree. You can trigger a subagent to run a deployment or a migration script, and it reports back once the task is complete.
Managing several subagents and main sessions at the same time is easier when you see their status at a glance. adhdTerminal displays whether a tile is working, waiting for you, done, or idle. If a subagent runs a long script, you watch the tile to see the progress without having to stay focused on that specific terminal. This layout is useful when you balance multiple streams of work and need to know exactly where each process stands without digging through tabs.
Monitor costs and usage during long runs
Running interactive scripts multiple times while debugging consumes many tokens. Every time the agent reads the output of a failed script or attempts to retry a command, it adds to the session cost. Use the /cost and /usage slash commands to see exactly how much you spent on the current session. This helps you decide if it is time to use /clear to reset the context or if you should refine your instructions in CLAUDE.md to be more efficient.
The context window fills up with every exchange, including the full output of the scripts the agent runs. If a script produces a large volume of logs before prompting for input, the agent might become less responsive. Using /compact periodically helps the agent summarize the logs and keep the most important information in the active context. This ensures the agent always has enough room to process the next set of instructions and handle the script interaction correctly.
Questions people ask
How do I stop a script that is stuck in a loop?
Use the Escape key once to interrupt the agent and stop the current tool execution. If you need to stop the entire session immediately, use Ctrl+C to quit the terminal process.
Can I use the /vim command to edit files during a script run?
You cannot use the /vim command while a script actively runs in the Bash tool. You must wait for the script to finish or interrupt it with Escape before you can use other slash commands.
How does the agent handle permissions for scripts?
The agent follows the permission mode you set, such as default or bypassPermissions. You can configure these in the .claude/settings.json file to allow or deny specific Bash tool actions for your project.
Read next
- Access git submodules in Claude CodeFix issues where Claude Code cannot see or modify code located inside nested git submodules within your main repository.
- Allow Claude Code to run shell scriptsResolve tool execution errors by adjusting permission settings to let Claude Code execute local bash or powershell scripts in your terminal.
- Break a linter error loop in ClaudeWhat to do when Claude Code fixes one linting error only to create another, leading to a circular set of edits.
- Change the Node version for Claude CodeResolve compatibility issues by switching the Node.js version used by Claude Code without breaking your other local development tools.