Skip to content
Back to skills

Glob Minimatch Patterns

BSecurity

Glob pattern matching and file filtering using minimatch. Convert glob patterns to optimized regex, batch file filtering, negation patterns, brace expansion, and ReDoS-safe usage. Sources: isaacs/minimatch.

  • 10 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added September 9, 2026
ai-agentsjavascriptjavaexpressgit

Security analysis

B88/100
  • criticalAccesses sensitive system or user directories

Pro shows the line behind each finding and how to fix it

Scanned September 9, 2026

npx -y skills add yanacuti1121/Yana-AI --skill glob-minimatch-patterns --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Glob Minimatch Patterns?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Glob Minimatch Patterns
[![Security: B — Skills Directory](https://www.skillsdirectory.com/api/skills/yanacuti1121-glob-minimatch-patterns/badge)](https://www.skillsdirectory.com/skills/yanacuti1121-glob-minimatch-patterns)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: glob-minimatch-patterns
description: Glob pattern matching and file filtering using minimatch. Convert glob patterns to optimized regex, batch file filtering, negation patterns, brace expansion, and ReDoS-safe usage. Sources: isaacs/minimatch.
origin: yana-ai — synthesized from isaacs/minimatch (ISC License)
license: Apache-2.0
version: 1.0.0
compatibility: yana-ai >= 1.3.48
---

# /glob-minimatch-patterns

## When to Use

- Filter skill/rule/script file lists by glob pattern (core/**/*.sh)
- Implement `.gitignore`-style file exclusion in agent tools
- Build allowlists/denylists for which files agents can read or write
- Validate file paths before passing to sandboxed commands

## Do NOT use for

- Directory traversal — use [[filesystem-isolation-chroot]] for path containment
- User-supplied regex patterns (use [[regex-escape-redos-guard]] first)

---

## Basic matching

```javascript
import { minimatch } from 'minimatch'

// Single match
minimatch('core/scripts/tool-proxy.sh', 'core/**/*.sh')  // true
minimatch('core/rules/foo.md', 'core/**/*.sh')            // false

// Options
minimatch('README.MD', '**/*.md', { nocase: true })       // true
minimatch('.hidden',   '**',      { dot: true })          // true (dot:true matches dotfiles)
```

---

## Batch file filtering

```javascript
import { minimatch }   from 'minimatch'
import { readdirSync } from 'fs'
import { join }        from 'path'

function filterFiles(
  dir:      string,
  patterns: string[],
  negations: string[] = []
): string[] {
  const allFiles = readdirSync(dir, { recursive: true, withFileTypes: false }) as string[]

  return allFiles.filter(f => {
    const rel = f.replace(/\\/g, '/')  // normalize Windows paths
    const included = patterns.some(p  => minimatch(rel, p, { dot: false }))
    const excluded = negations.some(p => minimatch(rel, p, { dot: false }))
    return included && !excluded
  })
}

// Example: all skill files, excluding drafts
const skills = filterFiles(
  '/workspaces/yana-ai/core/skills',
  ['*/SKILL.md'],
  ['**/draft-*', '**/*.bak']
)
```

---

## Build file access allowlist for sandbox

```javascript
const READABLE_PATTERNS = [
  'core/skills/**/*.md',
  'core/rules/**/*.md',
  'README.md',
  'MANIFEST.json',
]

const WRITABLE_PATTERNS = [
  'releases/**',
  'core/memory/**',
]

function checkAccess(path: string, mode: 'read' | 'write'): boolean {
  const patterns = mode === 'read' ? READABLE_PATTERNS : WRITABLE_PATTERNS
  return patterns.some(p => minimatch(path, p, { matchBase: false }))
}
```

---

## Brace expansion

```javascript
import { minimatch, braceExpand } from 'minimatch'

// Expand patterns before matching
const patterns = braceExpand('core/{skills,rules,scripts}/**/*.{md,sh}')
// → ['core/skills/**/*.md', 'core/skills/**/*.sh', 'core/rules/**/*.md', ...]
```

---

## Anti-Fake-Pass Checklist

```
❌ matchBase:true — 'foo.sh' matches 'deeply/nested/foo.sh' unexpectedly
❌ dot:false (default) — patterns miss dotfiles (.claude/, .gitignore)
❌ Path not normalized (\\→/) on Windows — all matches fail
❌ User-supplied glob not validated — **/../../../etc/passwd traversal
❌ Glob on absolute paths — minimatch expects relative paths from a root
❌ No negation — cannot express "all .md except drafts" without both arrays
```

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.