-
Notifications
You must be signed in to change notification settings - Fork 59
Watch Mode
Drift's watch mode provides real-time pattern detection as you edit files, with automatic persistence to the pattern store.
Watch mode:
- Monitors file changes in real-time
- Detects patterns and violations instantly
- Persists patterns to the
.driftstore - Supports debouncing and filtering
- Provides live feedback during development
# Start watching
drift watch
# With verbose output
drift watch --verbose
# Filter by categories
drift watch --categories api,auth,errors
# Custom debounce delay
drift watch --debounce 500
# Without persistence (violations only)
drift watch --no-persistdrift watch [options]| Option | Description | Default |
|---|---|---|
--verbose |
Show detailed output | false |
--context <file> |
Auto-update AI context file | none |
-c, --categories <list> |
Filter by categories (comma-separated) | all |
--debounce <ms> |
Debounce delay in milliseconds | 300 |
--no-persist |
Disable pattern persistence | false |
π Drift Watch Mode
Watching: /Users/dev/my-project
Categories: api, auth, errors
Debounce: 300ms
Persistence: enabled
Press Ctrl+C to stop
ββββββββββββββββββββββββββββββββββββββββββββββββββ
[10:23:45] Loaded 847 existing patterns
[10:23:45] Loaded 156 detectors
[10:23:45] Watching for changes...
[10:24:12] β src/api/users.ts (3 patterns)
[10:24:18] β src/services/payment.ts - 1 error, 2 warnings
β Line 45: Missing error handling for external API call
β Line 67: Bare catch clause
β Line 89: Swallowed error
[10:24:25] β src/hooks/useAuth.ts (2 patterns)
[10:24:31] Deleted: src/old-file.ts
[10:24:45] Saved patterns to disk
Watch mode uses native file system events to detect changes:
File Change Event
β
βΌ
βββββββββββββββββββ
β Debounce β Wait for typing to stop
ββββββββββ¬βββββββββ
β
βΌ
βββββββββββββββββββ
β Hash Check β Skip if content unchanged
ββββββββββ¬βββββββββ
β
βΌ
βββββββββββββββββββ
β Pattern Detect β Run all applicable detectors
ββββββββββ¬βββββββββ
β
βΌ
βββββββββββββββββββ
β Store Update β Merge patterns into store
ββββββββββ¬βββββββββ
β
βΌ
βββββββββββββββββββ
β Console Output β Show results
βββββββββββββββββββ
When a file changes, watch mode:
- Removes old patterns from that file
- Detects new patterns
- Merges into existing pattern store
- Preserves patterns from other files
Watch mode maintains a file map (.drift/index/file-map.json) that tracks:
- Last scan timestamp
- Content hash
- Pattern IDs found in file
This enables:
- Skipping unchanged files
- Efficient incremental updates
- Clean removal when files are deleted
| Extension | Language |
|---|---|
.ts, .tsx
|
TypeScript |
.js, .jsx
|
JavaScript |
.py |
Python |
.cs |
C# |
.css, .scss
|
CSS |
.json |
JSON |
.md |
Markdown |
Watch mode automatically ignores:
node_modules/.git/dist/build/coverage/.turbo/.drift/
Use --context to maintain an auto-updated context file for AI assistants:
drift watch --context .drift/CONTEXT.mdThis creates a file that's updated on every change:
# Drift Context (Auto-updated)
Last updated: 2024-01-15T10:24:45.000Z
## Current Stats
- Patterns tracked: 847
- Active violations: 23
This file is auto-updated by `drift watch`.
Run `drift export --format ai-context` for full pattern details.
## Quick Commands
- `drift where <pattern>` - Find pattern locations
- `drift files <path>` - See patterns in a specific file
- `drift status` - View pattern summary
- `drift dashboard` - Open web UIPatterns are saved to .drift/patterns/:
drift watch
# Patterns persist across sessions
# Full scan not needed after restartOnly show violations, don't save patterns:
drift watch --no-persist
# Useful for quick feedback during development
# Patterns not saved to diskWatch mode uses file locking to prevent conflicts:
- Lock file:
.drift/index/.lock - Timeout: 10 seconds
- Automatic cleanup on exit
This ensures safe concurrent access when:
- Multiple watch processes run
- CLI commands run during watch
- MCP server accesses patterns
Filter which patterns to detect:
# Only API and auth patterns
drift watch --categories api,auth
# Only error patterns
drift watch --categories errors
# Multiple categories
drift watch --categories api,auth,security,errorsAvailable categories:
-
apiβ API patterns -
authβ Authentication -
securityβ Security patterns -
errorsβ Error handling -
loggingβ Logging patterns -
testingβ Test patterns -
data-accessβ Database patterns -
configβ Configuration -
typesβ Type patterns -
structuralβ Code structure -
componentsβ UI components -
stylingβ CSS/styling -
accessibilityβ A11y patterns -
documentationβ Doc patterns -
performanceβ Performance
Debounce prevents excessive scanning during rapid edits:
# Default: 300ms
drift watch
# Faster feedback (may increase CPU)
drift watch --debounce 100
# Slower, more efficient
drift watch --debounce 1000Recommendation:
- Fast typing: 300-500ms
- Slow saves: 100-200ms
- Large files: 500-1000ms
Get instant feedback while coding:
drift watch --verboseRun watch in CI for incremental checks:
# In CI script
timeout 60 drift watch --no-persist &
# Run tests
npm test
# Watch catches pattern violations during testsKeep AI context updated:
drift watch --context .cursor/drift-context.mdMultiple developers can run watch simultaneously (file locking prevents conflicts).
# Increase debounce
drift watch --debounce 1000
# Filter categories
drift watch --categories api,auth# Check if file type is supported
drift watch --verbose
# Ensure file isn't in ignored paths# If lock file is stale, remove it
rm .drift/index/.lock
# Or wait for timeout (10 seconds)# Ensure persistence is enabled
drift watch # Not --no-persist
# Check disk space
df -h
# Check permissions
ls -la .drift/View watch results in real-time:
# Terminal 1
drift watch
# Terminal 2
drift dashboard
# Dashboard updates as patterns changeWatch mode and MCP server can run simultaneously:
# Terminal 1
drift watch
# Terminal 2 (or in IDE)
# MCP server reads patterns updated by watchCombine with pre-commit:
# .husky/pre-commit
drift watch --no-persist &
WATCH_PID=$!
npm test
kill $WATCH_PID- Incremental Scans β Efficient re-scanning
- Dashboard β Visual pattern monitoring
- Quality Gates β CI/CD integration
- Cortex V2 Overview
- Memory Setup Wizard
- Memory CLI
- Universal Memory Types
- Learning System
- Token Efficiency
- Causal Graphs
- Code Generation
- Predictive Retrieval
- Architecture
- Call Graph Analysis
- Impact Analysis
- Security Analysis
- Data Boundaries
- Test Topology
- Coupling Analysis
- Error Handling Analysis
- Wrappers Detection
- Environment Variables
- Constants Analysis
- Styling DNA
- Constraints
- Contracts
- Decision Mining
- Speculative Execution
- Watch Mode
- Trends Analysis
- Projects Management
- Package Context
- Monorepo Support
- Reports & Export
- Dashboard
- 10 Languages
- 21 Frameworks
- 16 ORMs
- 400+ Detectors
- 50+ MCP Tools
- 60+ CLI Commands
- 23 Memory Types