# Single extension--glob "*.py"# Multiple extensions--glob "*.{js,ts,jsx,tsx}"# All code files--glob "*.py,*.js,*.go,*.rs"
# Specific directory--glob "docs/*"# Any depth--glob "docs/**/*"# Specific subdirectory--glob "src/components/**/*.tsx"# Multiple directories--glob "docs/**,notes/**"
# Specific filename--glob "README.md"# Name pattern--glob "test_*.py"# Multiple name patterns--glob "*_test.py,test_*.py"
Glob patterns use Python’s fnmatch module for matching. Patterns are matched against both the full path and the basename:
# From src/db.py:326-335for item in items: source_path = item.meta.get("path", "") if include_globs: path_str = Path(source_path).as_posix() base_name = Path(source_path).name if not any( fnmatch.fnmatch(path_str, pattern) or fnmatch.fnmatch(base_name, pattern) for pattern in include_globs ): continue # Skip non-matching files
The --since flag is parsed into a Unix timestamp, then files are filtered by their modification time (mtime):
# From src/know.py:38-53def _parse_since(since: Optional[str]) -> float | None: if not since: return None value = since.strip() if not value: return None unit_map = {"m": 60, "h": 3600, "d": 86400, "w": 604800} unit = value[-1].lower() if unit in unit_map and value[:-1].isdigit(): delta = int(value[:-1]) * unit_map[unit] return (datetime.now() - timedelta(seconds=delta)).timestamp() if "T" in value: dt = datetime.fromisoformat(value) else: dt = datetime.strptime(value, "%Y-%m-%d") return dt.timestamp()
# From src/db.py:336-340if since_timestamp is not None: path = Path(source_path) mtime = path.stat().st_mtime if mtime < since_timestamp: continue # Skip older files
Filters can also be applied during indexing to selectively add content:
# Index only Markdown filesknow index --glob "*.md"# Index files modified in the last weekknow index --since 7d# Index recent documentationknow index --glob "docs/**/*.md" --since 30d# Index specific extensionsknow index --ext .py --ext .js --ext .ts
The --ext flag provides an alternative to glob patterns for filtering by file extension:
# Index Python files onlyknow index --ext pyknow index --ext .py # Leading dot is optional# Multiple extensionsknow index --ext py --ext js --ext tsknow index --ext "py,js,ts" # Comma-separated
By default, know indexes these extensions:Documents:.md, .txt, .pdf, .docx, .pptx, .htmlCode:.py, .js, .ts, .jsx, .tsx, .go, .rs, .java, .c, .cpp, .h, .hpp, .rb, .sh, .lua, .swiftSee src/db.py:29-54 for the full list.
When filters are applied, know retrieves more candidates before filtering to ensure you get the requested number of results:
# From src/db.py:442-444needs_filter = bool(include_globs) or since_timestamp is not Nonebase_limit = max(limit, 10) if benchmark else limitcandidate_limit = max(base_limit * 3, 20) if needs_filter else base_limit
This means requesting 5 results with filters will retrieve up to 15 candidates, then filter and return the top 5.
Remember that patterns match against both full paths and basenames:
# These are equivalent for matching basenames--glob "*.md"--glob "**/*.md"# But this only matches root-level files--glob "*.md" # via basename matching