# file_tool

> **Function** in `langchain_anthropic`

📖 [View in docs](https://reference.langchain.com/python/langchain-anthropic/middleware/anthropic_tools/_StateClaudeFileToolMiddleware/__init__/file_tool)

Execute file operations on virtual file system.

## Signature

```python
file_tool(
    runtime: ToolRuntime[None, AnthropicToolsState],
    command: str,
    path: str,
    file_text: str | None = None,
    old_str: str | None = None,
    new_str: str | None = None,
    insert_line: int | None = None,
    new_path: str | None = None,
    view_range: list[int] | None = None,
) -> Command | str
```

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `runtime` | `ToolRuntime[None, AnthropicToolsState]` | Yes | Tool runtime providing access to state. |
| `command` | `str` | Yes | Operation to perform. |
| `path` | `str` | Yes | File path to operate on. |
| `file_text` | `str \| None` | No | Full file content for create command. (default: `None`) |
| `old_str` | `str \| None` | No | String to replace for str_replace command. (default: `None`) |
| `new_str` | `str \| None` | No | Replacement string for str_replace command. (default: `None`) |
| `insert_line` | `int \| None` | No | Line number for insert command. (default: `None`) |
| `new_path` | `str \| None` | No | New path for rename command. (default: `None`) |
| `view_range` | `list[int] \| None` | No | Line range `[start, end]` for view command. (default: `None`) |

## Returns

`Command | str`

Command for state update or string result.

---

[View source on GitHub](https://github.com/langchain-ai/langchain/blob/9f232caa7a8fe1ca042a401942d5d90d54ceb1a6/libs/partners/anthropic/langchain_anthropic/middleware/anthropic_tools.py#L189)