Skip to main content

Module tool_pattern

Module tool_pattern 

Source
Expand description

Tool permission patterns for --allowed-tools / --disallowed-tools.

The Claude CLI accepts three pattern shapes in its tool lists:

  • Bare name: Bash, Read, Write.
  • Name with argument glob: Bash(git log:*), Write(src/*.rs).
  • MCP pattern: mcp__server__tool or mcp__server__*.

ToolPattern models all three. The typed constructors (ToolPattern::tool, ToolPattern::tool_with_args, ToolPattern::all, ToolPattern::mcp) always produce well-formed output. ToolPattern::parse validates shape of a raw string and returns PatternError on malformed input.

For back-compat, From<&str> / From<String> accept any string and store it verbatim – callers passing raw CLI strings through QueryCommand::allowed_tool keep working without changes. Use ToolPattern::parse directly when you want to catch typos before the CLI invocation.

§Example

use claude_wrapper::ToolPattern;

let p = ToolPattern::tool_with_args("Bash", "git log:*");
assert_eq!(p.as_str(), "Bash(git log:*)");

let p = ToolPattern::all("Write");
assert_eq!(p.as_str(), "Write(*)");

let p = ToolPattern::mcp("my-server", "*");
assert_eq!(p.as_str(), "mcp__my-server__*");

Structs§

ToolPattern
A tool permission pattern, ready to be emitted in a comma-joined --allowed-tools / --disallowed-tools value.

Enums§

PatternError
Errors from parsing a raw string with ToolPattern::parse.