bash.py — langchain Source File
Architecture documentation for bash.py, a python file in the langchain codebase. 4 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 4ee92436_6007_4c4b_a692_e1f8844b6d29["bash.py"] cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7["collections.abc"] 4ee92436_6007_4c4b_a692_e1f8844b6d29 --> cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"] 4ee92436_6007_4c4b_a692_e1f8844b6d29 --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3 77fe0abc_1951_9614_73f3_a55b5940d118["langchain.agents.middleware.shell_tool"] 4ee92436_6007_4c4b_a692_e1f8844b6d29 --> 77fe0abc_1951_9614_73f3_a55b5940d118 50acc543_e5f0_2162_cf07_c2bf50723e0c["langchain.agents.middleware.types"] 4ee92436_6007_4c4b_a692_e1f8844b6d29 --> 50acc543_e5f0_2162_cf07_c2bf50723e0c style 4ee92436_6007_4c4b_a692_e1f8844b6d29 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
"""Anthropic-specific middleware for the Claude bash tool."""
from __future__ import annotations
from collections.abc import Awaitable, Callable
from typing import Any
from langchain.agents.middleware.shell_tool import ShellToolMiddleware
from langchain.agents.middleware.types import (
ModelRequest,
ModelResponse,
)
# Tool type constants for Anthropic
BASH_TOOL_TYPE = "bash_20250124"
BASH_TOOL_NAME = "bash"
class ClaudeBashToolMiddleware(ShellToolMiddleware):
"""Middleware that exposes Anthropic's native bash tool to models."""
def __init__(
self,
workspace_root: str | None = None,
*,
startup_commands: tuple[str, ...] | list[str] | str | None = None,
shutdown_commands: tuple[str, ...] | list[str] | str | None = None,
execution_policy: Any | None = None,
redaction_rules: tuple[Any, ...] | list[Any] | None = None,
tool_description: str | None = None,
env: dict[str, Any] | None = None,
) -> None:
"""Initialize middleware for Claude's native bash tool.
Args:
workspace_root: Base directory for the shell session.
If omitted, a temporary directory is created.
startup_commands: Optional commands executed after the session starts.
shutdown_commands: Optional commands executed before session shutdown.
execution_policy: Execution policy controlling timeouts and limits.
redaction_rules: Optional redaction rules to sanitize output.
tool_description: Optional override for tool description.
env: Optional environment variables for the shell session.
"""
super().__init__(
workspace_root=workspace_root,
startup_commands=startup_commands,
shutdown_commands=shutdown_commands,
execution_policy=execution_policy,
redaction_rules=redaction_rules,
tool_description=tool_description,
tool_name=BASH_TOOL_NAME,
shell_command=("/bin/bash",),
env=env,
)
# Parent class now creates the tool with name "bash" via tool_name parameter
def wrap_model_call(
self,
request: ModelRequest,
handler: Callable[[ModelRequest], ModelResponse],
) -> ModelResponse:
"""Replace parent's shell tool with Claude's bash descriptor."""
filtered = [
t for t in request.tools if getattr(t, "name", None) != BASH_TOOL_NAME
]
tools = [*filtered, {"type": BASH_TOOL_TYPE, "name": BASH_TOOL_NAME}]
return handler(request.override(tools=tools))
async def awrap_model_call(
self,
request: ModelRequest,
handler: Callable[[ModelRequest], Awaitable[ModelResponse]],
) -> ModelResponse:
"""Async: replace parent's shell tool with Claude's bash descriptor."""
filtered = [
t for t in request.tools if getattr(t, "name", None) != BASH_TOOL_NAME
]
tools = [*filtered, {"type": BASH_TOOL_TYPE, "name": BASH_TOOL_NAME}]
return await handler(request.override(tools=tools))
__all__ = ["ClaudeBashToolMiddleware"]
Domain
Subdomains
Classes
Dependencies
- collections.abc
- langchain.agents.middleware.shell_tool
- langchain.agents.middleware.types
- typing
Source
Frequently Asked Questions
What does bash.py do?
bash.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, RunnableInterface subdomain.
What does bash.py depend on?
bash.py imports 4 module(s): collections.abc, langchain.agents.middleware.shell_tool, langchain.agents.middleware.types, typing.
Where is bash.py in the architecture?
bash.py is located at libs/partners/anthropic/langchain_anthropic/middleware/bash.py (domain: CoreAbstractions, subdomain: RunnableInterface, directory: libs/partners/anthropic/langchain_anthropic/middleware).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free