Skip to content

Aggressive ignore file loading breaks code indexing for production-oriented projects #39

@amondnet

Description

@amondnet

Problem

Context-please automatically applies ignore rules from all .xxxignore files (.dockerignore, .gitignore, .npmignore, etc.) with no mechanism to selectively disable them. This prevents indexing of critical development files needed by AI agents.

Reference Issue

This is based on upstream issue: zilliztech/claude-context#222

Core Issue

The current implementation in packages/core/src/context.ts (lines 1206-1229) automatically discovers and loads all ignore files:

private async findIgnoreFiles(codebasePath: string): Promise<string[]> {
  const entries = await fs.promises.readdir(codebasePath, { withFileTypes: true })
  const ignoreFiles: string[] = []
  
  for (const entry of entries) {
    if (entry.isFile() 
      && entry.name.startsWith('.') 
      && entry.name.endsWith('ignore')) {
      ignoreFiles.push(path.join(codebasePath, entry.name))
    }
  }
  return ignoreFiles
}

This approach is inappropriate for code indexing because:

  1. .dockerignore is designed for container optimization, not code analysis

    • Production containers often use patterns like * with !out/ to exclude everything except build artifacts
    • This excludes all source code from indexing
  2. .npmignore prevents files from npm packages, not from AI analysis

    • May exclude documentation, examples, or type definitions needed for understanding code
  3. No override mechanism exists

    • Configuration system is purely additive
    • Cannot selectively disable problematic ignore files
    • No way to prioritize code analysis needs over deployment needs

Real-World Impact

Quality: F (Complete Failure) - For projects with aggressive .dockerignore patterns, the system cannot index any files.

Current Limitation: "In its current form, the project is only useful for scripting languages" (projects without complex deployment configurations)

Steps to Reproduce

  1. Create a project with a .dockerignore file containing:

    *
    !out/
    !dist/
    
  2. Attempt to index the codebase using context-please MCP:

    {
      "path": "/path/to/project"
    }
  3. Observe that no source files are indexed

Expected Behavior

Users should be able to:

  • Selectively choose which ignore files to respect (e.g., .gitignore yes, .dockerignore no)
  • Override ignore patterns on a per-file or per-pattern basis
  • Specify that code indexing should prioritize completeness over deployment optimization

Proposed Solutions

  1. Whitelist Approach: Only respect .gitignore and .contextignore by default

    • Add configuration option to enable other ignore files explicitly
  2. Configurable Ignore File Discovery:

    interface IndexOptions {
      respectIgnoreFiles?: string[]  // Default: ['.gitignore', '.contextignore']
      ignoreIgnoreFiles?: string[]   // Blacklist certain ignore files
    }
  3. Priority System: Allow MCP ignorePatterns parameter to override file-based patterns

  4. Negative Patterns: Support !pattern syntax to explicitly include files even if ignored elsewhere

Workaround

As documented in the upstream issue, mounting /dev/null over .dockerignore in Docker configurations:

{
  "mounts": [
    {
      "source": "/dev/null",
      "target": "${workspaceFolder}/.dockerignore",
      "type": "bind"
    }
  ]
}

However, this is a hacky solution that shouldn't be necessary.

Related Code

  • packages/core/src/context.ts:1206-1229 - Automatic ignore file discovery
  • packages/core/src/context.ts:1171-1194 - loadIgnorePatterns() method
  • packages/mcp/src/index.ts - MCP index_codebase tool (accepts ignorePatterns but can't disable file-based patterns)

Labels

  • type: bug - Current behavior breaks legitimate use cases
  • p1 - High priority - Blocks usage for many production projects
  • area: core - Core indexing functionality affected

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:coreCore indexing and search functionalityp1High prioritytype:bugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions