Skip to main content
File Identification is HAI Build’s intelligent file discovery system. It combines fast indexing, fuzzy search, and context tracking to help the AI find exactly the files it needs for code generation.
File identification and search

How It Works

File Identification uses a multi-layer approach to file discovery:
1

Workspace Indexing

Ripgrep scans your workspace to build a comprehensive file index.
2

Active File Tracking

Monitors currently open tabs and recently edited files.
3

Fuzzy Search

Uses Fuse.js for intelligent file matching across paths and names.
4

Context Prioritization

Ranks files based on relevance to the current task.

Core Features

Lightning-Fast Indexing

File Identification leverages ripgrep for blazing-fast file discovery:
Performance characteristics:
  • Scans 5,000+ files in milliseconds
  • Follows symlinks automatically
  • Respects .gitignore patterns
  • Excludes common build directories (node_modules, dist, .git)
Ripgrep is 10-100x faster than traditional file search tools, making it ideal for large codebases.

Intelligent File Filtering

Automatic exclusion of irrelevant directories:

Active File Prioritization

Files you’re actively working on appear first:
Active files are:
  • Currently open in tabs
  • Recently edited
  • Visible in the editor
  • Part of the current diff view
The AI sees your open files first, making it context-aware of what you’re working on.
File Identification uses Fuse.js for intelligent fuzzy matching:
Files are ranked by multiple factors:
Scoring criteria:
  1. Filename matches (weighted 2x)
  2. Full path matches
  3. Fewer gaps between matched characters
  4. Shorter paths preferred

Multi-Root Workspace Support

File Identification seamlessly handles multi-root workspaces:

Workspace Hints

Search specific workspace roots:@frontend:/componentsSearches only the frontend workspace.

Parallel Search

Searches all roots simultaneously:

Deduplication

Handles duplicate filenames:

Workspace Labels

Each result includes workspace name:
See: src/services/search/file-search.ts:209

File Context Tracking

HAI Build tracks which files are in the AI’s context:

Context Status Indicators

1

Added to Context

Files explicitly added via mentions or tool use.
2

In Active Use

Files currently being read or edited by the AI.
3

Removed from Context

Files removed during context compaction.

File Mention Tracking

Every file operation is tracked:
Tracked operations:
  • read_file: File content read
  • write_to_file: File created or modified
  • replace_in_file: File edited
  • list_files: Directory listing
  • search_files: File search results

Context Warnings

Users are warned when files are removed:
When context is compacted, the AI receives a warning about removed files to maintain awareness.

File Type Detection

Automatic file type detection and categorization:
Verifies file types using fs.lstat():
Automatically builds directory tree:
Enables folder-level operations and navigation.

Search Strategies

Different search approaches for different scenarios:

Exact Match

When you know the filename:UserService.tsReturns exact matches first.

Partial Match

When you remember part of the name:user servFuzzy matches across path segments.

Path-Based

When you know the directory:components/authSearches full paths.

Extension Filter

When you need specific file types:*.test.tsFilters by extension pattern.

Integration with AI

Automatic File Suggestions

The AI uses File Identification to:
  1. Find relevant files for a task
  2. Suggest imports based on available modules
  3. Locate configuration files automatically
  4. Discover test files for testing tasks
  5. Navigate project structure efficiently

Context-Aware Mentions

File Identification powers the @ mention feature:
Use @ mentions to explicitly add files to context before describing your task.

Performance Optimization

Lazy Loading

Results are loaded incrementally:
  • Initial 20 results displayed immediately
  • More results loaded on scroll
  • Prevents UI blocking on large workspaces

Caching Strategy

File index is cached per workspace:
  • Cache invalidated on file system changes
  • Active files cache updated every 500ms
  • Search results cached for 5 seconds

Limits and Throttling

Prevents memory issues on massive codebases.

Configuration

Custom Exclusions

Add workspace-specific exclusions:

Search Behavior

Customize search parameters:

Best Practices

  • Clear names improve search accuracy
  • Include feature/component in filename
  • Use consistent naming conventions
  • Avoid generic names like utils.ts
  • Group related files together
  • Use feature-based folder structure
  • Keep directory depth reasonable (3-5 levels)
  • Mirror logical application structure
  • Open relevant files before starting AI tasks
  • Keep related files in tabs
  • Use split editor for context files
  • Close unrelated files to reduce noise
  • Use workspace hints in multi-root setups
  • Add irrelevant directories to exclusions
  • Increase file limit if needed
  • Consider breaking into multiple workspaces

Troubleshooting

  • Check exclusion patterns
  • Verify file isn’t in .gitignore
  • Confirm file exists on disk
  • Refresh file index
  • Reduce file limit
  • Add more exclusion patterns
  • Check for symlink loops
  • Disable deep directory scanning
  • Use more specific search terms
  • Include path segments in query
  • Adjust fuzzy search threshold
  • Try exact filename match

Next Steps

Inline Editing

Make quick edits to discovered files

AI-Powered Coding

See how the AI uses file context

Focus Chain

Track which files are being worked on

Multi-Root Workspaces

Work with multiple project roots