Searching with Glob
Module: Core Features | Lesson: 5 of 7 | Time: ~10 minutes
What You Will Learn
- What glob patterns are and how they work
- Common patterns like
**/*.mdandsrc/**/*.js - How to ask Claude to find files by name or pattern
Prerequisites
- Completed Running Commands
Why This Matters
As your projects grow, you will end up with dozens or hundreds of files spread across many folders. Finding a specific file by browsing through folders manually is slow and frustrating. The Glob tool lets Claude search for files by name using special patterns called "globs." It is like a supercharged file search that understands wildcards.
What Is a Glob Pattern?
A glob pattern is a search string that uses special characters to match filenames. If you have ever searched for *.txt in Windows File Explorer, you have already used a glob pattern. The * character means "match anything."
Here are the building blocks:
| Pattern | Meaning | Example Match |
|---|---|---|
* | Any characters within a single folder | *.txt matches notes.txt, readme.txt |
** | Any folder, including nested ones | **/*.txt matches notes.txt, docs/readme.txt, a/b/c/deep.txt |
? | Exactly one character | file?.txt matches file1.txt, fileA.txt but not file10.txt |
The two most important patterns to remember are:
*-- matches files in one specific folder**-- matches files in all folders, no matter how deeply nested
Common Glob Patterns
Here are patterns you will use frequently:
Find All Files of a Type
*.txt -- all .txt files in the current folder
**/*.txt -- all .txt files everywhere in the project
**/*.md -- all Markdown files everywhere
**/*.py -- all Python files everywhere
**/*.jpg -- all JPEG images everywhere
Find Files in a Specific Folder
src/*.js -- JavaScript files in the src folder only
docs/**/*.md -- Markdown files anywhere inside docs (including subfolders)
tests/**/*.py -- Python files anywhere inside tests
Find Files by Name Pattern
**/README* -- any file starting with "README" in any folder
**/*config* -- any file with "config" in its name
**/*test*.js -- JavaScript files with "test" in their name
When working with Claude, you can just describe what you are looking for in plain English:
> Find all the text files in this project
> Where are the Python files?
> Show me every file named "config" something
Claude will use the right glob pattern automatically. But understanding the patterns helps you verify what Claude is doing.
How to Ask Claude to Search for Files
You can phrase your request many ways:
> Find all .md files in this project
> What text files exist in the docs folder?
> Search for any file with "test" in its name
> List all JavaScript files in the src directory and its subdirectories
> Are there any .env files anywhere in this project?
What the Glob Tool Looks Like
When Claude uses the Glob tool, you will see output like this:
─ Glob: **/*.txt
Found 4 files:
notes.txt
docs/guide.txt
docs/faq.txt
archive/old-notes.txt
Claude shows:
- The pattern it used (
**/*.txt) - The list of matching files with their paths relative to your project folder
After the results, Claude usually summarizes what it found: "I found 4 text files across your project. Two are in the docs folder, one is in archive, and one is in the root directory."
Glob vs Grep: Which One to Use?
This is a common point of confusion. Here is the simple rule:
| I want to... | Use |
|---|---|
| Find files by name | Glob |
| Find files by what is inside them | Grep (next lesson) |
Examples:
- "Find all
.txtfiles" -- Glob (searching by file name/extension) - "Find files that contain the word 'password'" -- Grep (searching file contents)
- "Where are the CSS files?" -- Glob (searching by file type)
- "Which file has the function called 'calculateTotal'?" -- Grep (searching for text inside files)
You do not always need to choose. You can tell Claude what you are looking for, and it will decide whether to use Glob, Grep, or both. But understanding the difference helps you ask better questions.
Common Questions
Q: Does Glob search inside files? No. Glob only looks at filenames and paths. It does not open or read any files. If you need to search file contents, use Grep (covered in the next lesson).
Q: Are glob patterns case-sensitive?
On Windows, file names are not case-sensitive, so *.TXT and *.txt will find the same files. However, it is good practice to use the lowercase version to keep things consistent.
Q: What if no files match my pattern?
Claude will tell you that no files were found and may suggest an alternative search. For example, if **/*.py finds nothing, Claude might say "No Python files were found. Would you like me to search for a different file type?"
Q: Can I search for files without an extension?
Yes. You can use patterns like **/Makefile, **/Dockerfile, or **/LICENSE to find files without extensions.
Try It Yourself
Step 1: Set Up Some Practice Files
Start Claude Code in your practice folder and create a small structure:
> Create the following files:
> - readme.md (with the text "# My Project")
> - src/app.js (with the text "console.log('hello');")
> - src/utils.js (with the text "// utility functions")
> - docs/guide.md (with the text "# User Guide")
> - docs/faq.md (with the text "# FAQ")
> - notes.txt (with the text "Some notes here")
Step 2: Search by Extension
> Find all Markdown files in this project
You should see readme.md, docs/guide.md, and docs/faq.md in the results.
Step 3: Search in a Specific Folder
> What JavaScript files are in the src folder?
You should see src/app.js and src/utils.js.
Step 4: Search by Name Pattern
> Find any file with "guide" in its name
You should see docs/guide.md.
Step 5: Try a Broad Search
> List every file in this project, regardless of type
Claude will use a pattern like **/* to find everything.
If you can find files by extension, by folder, and by name pattern, you understand the Glob tool. In the next lesson, you will learn how to search inside files with Grep.
What You Learned
- Glob tool: Searches for files by name and path pattern
*wildcard: Matches anything within one folder**wildcard: Matches across all folders, including nested ones- Common patterns:
**/*.txt(all text files),src/*.js(JS files in src),**/*config*(files with "config" in the name) - Glob vs Grep: Glob finds files by name, Grep finds files by content
- Ask naturally: Describe what you need and Claude picks the right pattern
How was this lesson? Take 2 minutes to share your feedback — it helps us make the tutorials better for everyone.