Feature Proposal: Enhance Core bash Tool with Sessions & Safety Guardrails #8089

Closed
opened 2026-02-16 18:09:08 -05:00 by yindo · 2 comments
Owner

Originally created by @chindris-mihai-alexandru on GitHub (Jan 30, 2026).

Originally assigned to: @thdxr on GitHub.

Title: Feature Proposal: Enhance Core bash Tool with Sessions & Safety Guardrails

Description:
The current bash tool is functional but stateless and unrestricted. This creates two problems:

  1. Context Loss: The agent often loses track of working directories or environment variables between steps.
  2. Risk: There are no native guardrails against destructive commands (e.g., rm -rf /).

Proposal:
I propose upgrading the Core bash Tool (Option A) rather than creating a separate plugin.

Key Enhancements:

  1. Stateful Sessions: Maintain a persistent shell process (pty) so cd, export, and background processes work naturally across prompts.
  2. Safety Middleware: A pre-execution validation layer to catch and warn on high-risk patterns (sudo, rm -rf, chmod 777).
  3. Structured Observability: Return execution metadata (time, exit code) to help the agent self-correct.

Why Core?
These features are fundamental for a robust coding agent. Safety and context awareness should be "batteries included" defaults, not opt-in plugins.

Implementation Status:
I have prototyped the logic (session management, regex safety checks, buffer limits) and confirmed it works in isolation. I am ready to submit a PR to integrate this into the core toolset.

Originally created by @chindris-mihai-alexandru on GitHub (Jan 30, 2026). Originally assigned to: @thdxr on GitHub. **Title:** Feature Proposal: Enhance Core `bash` Tool with Sessions & Safety Guardrails **Description:** The current `bash` tool is functional but stateless and unrestricted. This creates two problems: 1. **Context Loss:** The agent often loses track of working directories or environment variables between steps. 2. **Risk:** There are no native guardrails against destructive commands (e.g., `rm -rf /`). **Proposal:** I propose upgrading the **Core `bash` Tool** (Option A) rather than creating a separate plugin. **Key Enhancements:** 1. **Stateful Sessions:** Maintain a persistent shell process (pty) so `cd`, `export`, and background processes work naturally across prompts. 2. **Safety Middleware:** A pre-execution validation layer to catch and warn on high-risk patterns (`sudo`, `rm -rf`, `chmod 777`). 3. **Structured Observability:** Return execution metadata (time, exit code) to help the agent self-correct. **Why Core?** These features are fundamental for a robust coding agent. Safety and context awareness should be "batteries included" defaults, not opt-in plugins. **Implementation Status:** I have prototyped the logic (session management, regex safety checks, buffer limits) and confirmed it works in isolation. I am ready to submit a PR to integrate this into the core toolset.
yindo closed this issue 2026-02-16 18:09:08 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Jan 30, 2026):

This issue might be a duplicate of or closely related to existing issues. Please check:

  • #7750: Persistent shell mode - keep shell session alive after executing commands
  • #2945: Session automatically compacted, destroying the entire working context
  • #3212: Agent runs "sudo" and freezes UI when analyzing system configs (e.g. Apache)
  • #8097: Allow interactive terminal input for commands requiring user input (sudo, passwords, others)
  • #9292: Expose session context to child processes via environment variables
  • #11065: Add env parameter for setting environment variables in bash

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Jan 30, 2026): This issue might be a duplicate of or closely related to existing issues. Please check: - #7750: Persistent shell mode - keep shell session alive after executing commands - #2945: Session automatically compacted, destroying the entire working context - #3212: Agent runs "sudo" and freezes UI when analyzing system configs (e.g. Apache) - #8097: Allow interactive terminal input for commands requiring user input (sudo, passwords, others) - #9292: Expose session context to child processes via environment variables - #11065: Add env parameter for setting environment variables in bash Feel free to ignore if none of these address your specific case.
Author
Owner

@chindris-mihai-alexandru commented on GitHub (Feb 15, 2026):

Closing as duplicate/superseded by the implementation PR in #11381 so discussion stays in one place.

@chindris-mihai-alexandru commented on GitHub (Feb 15, 2026): Closing as duplicate/superseded by the implementation PR in #11381 so discussion stays in one place.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#8089