GlobTool: Find Files
8/2/2026, 1:20:50 PM · Source
AI-translated on 8/2/2026, 1:23:49 PM · by Qwen3.6 35B (fast, default)
The retrieved documents from the K12 knowledge base do not contain specific information about "Claude Code" or a tool called "GlobTool." The results focus exclusively on general computer science curriculum content (e.g., AP Computer Science A/Principles course descriptions, programming practices, and computational thinking frameworks) without mentioning Claude-specific tools, file discovery mechanisms, or implementation details. This indicates that either: 1. The term "GlobTool" does not exist within current knowledge base resources related to this student's context (K12), or 2. A different approach would be required for accurate information gathering — such as searching external documentation sources directly referenced by Claude Code developers. To provide authoritative guidance on GlobTool, additional research via official Anthropic channels or direct access to Claude Code's source repository would be necessary. Without explicit references in the provided knowledge base or external verification tools, I cannot provide verified details about this specific tool's design principles or workflows.
This tool looks simple, but its role is highly critical
GlobTool does exactly what you'd expect: finds files by name or wildcard pattern.
But within Claude Code's main loop, it actually serves as:
Transforming "I roughly know what file I'm looking for" into "I have identified the candidate paths."
With many complex tasks, the first step isn't reading a file directly; it's narrowing down the scope first.
GlobTool is the standard entry point for this step.
Let's look at its input definition
tools/GlobTool/GlobTool.ts:
const inputSchema = z.strictObject({
pattern: z.string().describe('The glob pattern to match files against'),
path: z.string().optional().describe('The directory to search in'),
})
This schema is simple, but its design intent is clear:
pattern: used to express "what I'm looking for"path: used to limit the search scope
In other words, Claude Code wants the model not to blindly scrape the entire repo by default, but rather to learn how to narrow down the search radius.
It performs no writes, and is concurrency-safe
These declarations in the source code are particularly worth noting:
isConcurrencySafe() {
return true
}
isReadOnly() {
return true
}
isSearchOrReadCommand() {
return { isSearch: true, isRead: false }
}
This shows the system has defined GlobTool as from the very beginning:
- read-only
- concurrency-safe
- explicitly a "search-type" tool
This matters a great deal for main loop scheduling and UI rendering.
A diagram of its position in the search chain
The model knows roughly what filename or extension it's looking for
GlobTool
Returns candidate file paths
FileReadTool continues with detailed reading
FileEditTool / FileWriteTool
It's not just a simple find
GlobTool does not directly expose Bash find to the model; instead, it relies on its own internal file search implementation:
import { glob } from '../../utils/glob.js'
This means:
- structured search results
- permissions-aware
- return values better suited for downstream model processing
This differs most from Bash commands in that:
the system knows "you are performing file discovery," rather than just seeing a block of raw shell output.
It validates that the path isn't filled in randomly
There's some very practical logic inside validateInput():
if (path) {
const absolutePath = expandPath(path)
...
if (!stats.isDirectory()) {
return {
result: false,
message: `Path is not a directory: ${path}`,
}
}
}
This shows GlobTool clearly distinguishes between:
- the path is a directory
- the path doesn't exist
- the path is incorrect
It even attempts to suggest paths relative to the working directory.
Details like this make it feel like a true product-facing tool, rather than just an SDK demo.
It also actively limits result volume
There's a default limit in the call logic:
const limit = globLimits?.maxResults ?? 100
This shows Claude Code is well aware of one problem:
Without result limiting in file search, it's easy to return hundreds or thousands of items at once, wasting context.
So GlobTool's goal isn't "the more, the better," but rather "provide the main loop with a sufficiently useful set of candidates."
Its division of labor with GrepTool
This is the most important point to remember:
GlobTool: I roughly know what file is namedGrepTool: I roughly know what text is inside the file
These two tools are often conflated, but from an engineering perspective, they represent two different search strategies.
Typical Usage Path
FileReadTool GlobTool Model FileReadTool GlobTool Model Search for a certain type of file Return candidate paths Read the most relevant files Return body text
Where it's Most Easily Misunderstood
Misconception One: Since Bash has find, Glob is unnecessary
Incorrect.
The advantage of GlobTool lies exactly in being structured, controllable, and more amenable to the main loop.
Misconception Two: Glob is just a nicer UI
Also incorrect.
It affects permissions checking, context control, and downstream tool selection.
Misconception Three: It's just a minor tool, unimportant
Search tools often look simple, but within a system like Claude Code,
"finding the right file first" is itself a very critical main path.
Summary
The value of GlobTool can be summed up in one sentence:
It makes "discovering target files by file path pattern" into a standard, read-only, structured search entry point for Claude Code, serving as the true first step for many tasks.
Learning map
- Clarify Tool Positioning: Define GlobTool's core responsibility as "matching physical paths via wildcard patterns", distinguishing it from content search (GrepTool) and read/write operations.
- Understand Input Specifications: Learn the usage boundaries for the
patternandpathparameters, and grasp directory restrictions and standard wildcard syntax. - Internalize System Mechanics: Understand its read-only concurrent nature, automatic throttling strategy (default 100 results), and path validation logic.
- Integrate into Standard Workflows: Combine with FileReadTool/GrepTool to build a complete Agent task pipeline: "locate → search → process".
- Optimize Invocation Strategy: Learn to restrict the
pathparameter to narrow the search scope, control context consumption, and avoid indiscriminate full-repository scanning.
Get hands-on — step by step
- Create a multi-layer test folder structure in the project root directory (e.g.,
src/components/,docs/api/,tests/unit/). - In Claude Code, execute the first instruction:
GlobTool(pattern: "*.ts", path: "src/components")and observe the returned structured path list and format. - Retry without the
pathparameter to compare results across a full repository search, noting changes in result count—experience the system's automatic throttling and context-protection mechanisms. - Deliberately pass a file path (rather than a directory) as the
pathvalue, and verify that error messaging matches expected type-validation behavior. - Chain downstream tools to execute a complete task: issue the instruction "use GlobTool to find all
.vuefiles undersrc/components, and read the first 20 lines ofindex.vue"—observe the system's automatic routing logic. - Compare search-strategy differences: fire off
GlobTool(pattern: "*.log")andGrepTool(pattern: "ERROR")in parallel, then summarize the engineering separation of concerns between "finding physical files" and "finding text content."
Top 3 sources
- 1Claude Code 官方工具文档
Anthropic 官方的 Claude Code 工具使用指南,包含完整 schemas、调度规则、并发限制与多工具协同示例。
https://docs.anthropic.com/en/docs/claude-code/tools
- 2isaacs/node-glob 核心源码库
GlobTool 底层通配符匹配引擎的权威实现,提供节点文件系统遍历机制、模式语法详解与性能说明。
https://github.com/isaacs/node-glob
- 3PromptingGuide - Tool Use Patterns
详细讲解 AI Agent 系统里工具调用编排、上下文控制与多工具路由的最佳实践指南,涵盖设计哲学与常见陷阱。
https://www.promptingguide.ai/techniques/tools
Links are AI-suggested — worth a quick sanity check before diving in.