bashtool

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 4, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package bashtool implements the M2 reference port of Claude Code's Bash tool. It executes a shell command via `bash -c` and returns the combined stdout/stderr.

This is a deliberately minimal port. The real BashTool ships ~10k LOC of pathValidation, bashSecurity, bashPermissions, sandbox routing, and run_in_background plumbing; that surface lands in M5 alongside the permission system. M2's BashTool is enough to round-trip a tool call through the agent loop with real subprocess execution.

Reference: src/tools/BashTool/BashTool.tsx (~157 KB), src/tools/BashTool/toolName.ts.

Index

Constants

View Source
const DefaultTimeout = 2 * time.Minute

DefaultTimeout matches the leaked TS reference (BashTool.tsx ~882 line `timeout: timeoutMs`) when no timeout argument is supplied: 2 minutes.

View Source
const MaxOutputBytes = 30000

MaxOutputBytes truncates combined stdout+stderr to keep tool_result blocks under typical context budgets. Matches the real BashTool's `maxResultSizeChars` of ~30000.

View Source
const MaxTimeout = 10 * time.Minute

MaxTimeout caps `timeout` so a runaway tool call can't hold the agent loop hostage. Real BashTool exposes 10 min.

Variables

View Source
var SessionEnv map[string]string

SessionEnv is injected by the loop at startup from settings.Merged.Env. When non-nil, each subprocess inherits the base environment plus these vars.

Functions

This section is empty.

Types

type Input

type Input struct {
	Command     string `json:"command"`
	Timeout     int    `json:"timeout,omitempty"` // milliseconds
	Description string `json:"description,omitempty"`
}

Input is the typed view of the JSON input.

type Tool

type Tool struct{}

Tool implements the Bash tool.

func New

func New() *Tool

New returns a fresh Bash tool. Stateless; one instance is fine.

func (*Tool) Description

func (*Tool) Description() string

Description is the prompt text the model sees.

func (*Tool) Execute

func (t *Tool) Execute(ctx context.Context, raw json.RawMessage) (tool.Result, error)

Execute runs the command and returns its output.

func (*Tool) InputSchema

func (*Tool) InputSchema() json.RawMessage

InputSchema is the JSON Schema sent to the model.

func (*Tool) IsConcurrencySafe

func (*Tool) IsConcurrencySafe(json.RawMessage) bool

IsConcurrencySafe: Bash is never concurrency-safe (commands may write to shared state).

func (*Tool) IsReadOnly

func (*Tool) IsReadOnly(raw json.RawMessage) bool

IsReadOnly returns true for shell commands that are known to be read-only (ls, cat, echo, git log/status/diff/show, find, head, tail, wc, etc.). This prevents permission prompts for benign inspection commands, matching Claude Code's isReadOnlyBashCommand heuristic.

func (*Tool) Name

func (*Tool) Name() string

Name implements tool.Tool.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL