Skip to main content
Glama

find_file_context

Search Claude conversation history to find all discussions and modifications related to a specific file, helping users track changes and reference previous work.

Instructions

Find all conversations and changes related to a specific file

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filepathYesFile path to search for in conversation history
operation_typeNoFilter by operation: read, edit, create, or allall
limitNoMaximum number of results (default: 15)
detail_levelNoResponse detail: summary (default), detailed, rawsummary

Implementation Reference

  • MCP server dispatch handler for 'find_file_context' tool: extracts args, calls UniversalHistorySearchEngine.findFileContext, formats result with BeautifulFormatter
    case 'find_file_context': {
      const universalResult = await this.universalEngine.findFileContext(
        args?.filepath as string,
        (args?.limit as number) || 15
      );
    
      const detailLevel = (args?.detail_level as string) || 'summary';
      const operationType = (args?.operation_type as string) || 'all';
      const formattedResult = this.formatter.formatFileContext(
        universalResult.results,
        args?.filepath as string,
        detailLevel,
        operationType
      );
    
      return {
        content: [{ type: 'text', text: formattedResult }],
      };
    }
  • UniversalHistorySearchEngine.findFileContext: proxies to HistorySearchEngine.findFileContext (primary impl), adds desktop support (currently disabled)
    async findFileContext(
      filepath: string,
      limit?: number
    ): Promise<{ source: string; results: FileContext[]; enhanced: boolean }> {
      await this.initialize();
    
      const claudeCodeResults = await this.claudeCodeEngine.findFileContext(filepath, limit);
    
      if (!this.claudeDesktopAvailable) {
        return {
          source: 'claude-code',
          results: claudeCodeResults,
          enhanced: false,
        };
      }
    
      const desktopMessages = await this.searchClaudeDesktopConversations(filepath, undefined, limit);
    
      const combinedResults = this.combineFileContextResults(claudeCodeResults, desktopMessages);
    
      const hasDesktopData = desktopMessages.length > 0;
    
      return {
        source: hasDesktopData ? 'claude-desktop' : 'claude-code',
        results: combinedResults,
        enhanced: hasDesktopData,
      };
    }
  • Core HistorySearchEngine.findFileContext implementation: parallel search across projects' jsonl conversation files for messages referencing the filepath, extracts related contexts grouped by operation
    async findFileContext(filePath: string, limit: number = 25): Promise<FileContext[]> {
      const fileContexts: FileContext[] = [];
    
      try {
        const projectDirs = await findProjectDirectories();
    
        // COMPREHENSIVE: Process more projects to match GLOBAL's reach
        const limitedDirs = projectDirs.slice(0, 15); // Increased significantly to match GLOBAL scope
    
        // PARALLEL PROCESSING: Process all projects concurrently
        const projectResults = await Promise.allSettled(
          limitedDirs.map(async (projectDir) => {
            const jsonlFiles = await findJsonlFiles(projectDir);
    
            // COMPREHENSIVE: Process more files to match GLOBAL's reach
            const limitedFiles = jsonlFiles.slice(0, 10); // Increased to match GLOBAL scope
    
            const fileResults = await Promise.allSettled(
              limitedFiles.map(async (file) => {
                const messages = await this.parser.parseJsonlFile(projectDir, file);
    
                const fileMessages = messages.filter((msg) => {
                  // ENHANCED file matching logic like GLOBAL with more patterns
                  const hasFileRef = msg.context?.filesReferenced?.some((ref) => {
                    const refLower = ref.toLowerCase();
                    const pathLower = filePath.toLowerCase();
                    // More comprehensive matching patterns
                    return (
                      refLower.includes(pathLower) ||
                      pathLower.includes(refLower) ||
                      refLower.endsWith('/' + pathLower) ||
                      pathLower.endsWith('/' + refLower) ||
                      refLower.split('/').pop() === pathLower ||
                      pathLower.split('/').pop() === refLower ||
                      refLower === pathLower ||
                      refLower.includes(pathLower.replace(/\\/g, '/')) ||
                      refLower.includes(pathLower.replace(/\//g, '\\'))
                    );
                  });
    
                  // Enhanced content matching with case variations and path separators
                  const contentLower = msg.content.toLowerCase();
                  const pathVariations = [
                    filePath.toLowerCase(),
                    filePath.toLowerCase().replace(/\\/g, '/'),
                    filePath.toLowerCase().replace(/\//g, '\\'),
                    filePath.toLowerCase().split('/').pop() || '',
                    filePath.toLowerCase().split('\\').pop() || '',
                  ];
    
                  const hasContentRef = pathVariations.some(
                    (variation) => variation.length > 0 && contentLower.includes(variation)
                  );
    
                  // Enhanced git pattern matching
                  const hasGitRef =
                    /(?:modified|added|deleted|new file|renamed|M\s+|A\s+|D\s+)[\s:]*[^\n]*/.test(
                      msg.content
                    ) &&
                    pathVariations.some(
                      (variation) => variation.length > 0 && contentLower.includes(variation)
                    );
    
                  return hasFileRef || hasContentRef || hasGitRef;
                });
    
                if (fileMessages.length > 0) {
                  // Claude-optimized filtering - preserve valuable context
                  const cleanFileMessages = fileMessages.filter((msg) => {
                    return msg.content.length > 15 && !this.isLowValueContent(msg.content);
                  });
    
                  const dedupedMessages = SearchHelpers.deduplicateByContent(cleanFileMessages);
    
                  if (dedupedMessages.length > 0) {
                    // Group by operation type (heuristic)
                    const operationType = SearchHelpers.inferOperationType(dedupedMessages);
    
                    return {
                      filePath,
                      lastModified: dedupedMessages[0]?.timestamp || '',
                      relatedMessages: dedupedMessages.slice(0, Math.min(limit, 10)), // More context for Claude
                      operationType,
                    };
                  }
                }
                return null;
              })
            );
    
            // Collect successful file results
            const validContexts: FileContext[] = [];
            for (const result of fileResults) {
              if (result.status === 'fulfilled' && result.value) {
                validContexts.push(result.value);
              }
            }
    
            return validContexts;
          })
        );
    
        // Aggregate all results from parallel processing
        for (const result of projectResults) {
          if (result.status === 'fulfilled') {
            fileContexts.push(...result.value);
          }
        }
    
        return fileContexts.sort(
          (a, b) => new Date(b.lastModified).getTime() - new Date(a.lastModified).getTime()
        );
      } catch (error) {
        console.error('File context search error:', error);
        return [];
      }
    }
  • Input schema and metadata definition for find_file_context tool in MCP ListTools response
    {
      name: 'find_file_context',
      description: 'Find all conversations and changes related to a specific file',
      inputSchema: {
        type: 'object',
        properties: {
          filepath: {
            type: 'string',
            description: 'File path to search for in conversation history',
          },
          operation_type: {
            type: 'string',
            description: 'Filter by operation: read, edit, create, or all',
            enum: ['read', 'edit', 'create', 'all'],
            default: 'all',
          },
          limit: {
            type: 'number',
            description: 'Maximum number of results (default: 15)',
            default: 15,
          },
          detail_level: {
            type: 'string',
            description: 'Response detail: summary (default), detailed, raw',
            enum: ['summary', 'detailed', 'raw'],
            default: 'summary',
          },
        },
        required: ['filepath'],
      },
    },
  • src/index.ts:41-256 (registration)
    Registration of all tools including find_file_context in MCP ListToolsRequestSchema handler
    this.server.setRequestHandler(ListToolsRequestSchema, async () => {
      return {
        tools: [
          {
            name: 'search_conversations',
            description: 'Search through Claude Code conversation history with smart insights',
            inputSchema: {
              type: 'object',
              properties: {
                query: {
                  type: 'string',
                  description: 'Search query to find relevant conversations',
                },
                project: {
                  type: 'string',
                  description: 'Optional project name to filter results',
                },
                timeframe: {
                  type: 'string',
                  description: 'Time range filter (today, week, month)',
                },
                limit: {
                  type: 'number',
                  description: 'Maximum number of results (default: 10)',
                  default: 10,
                },
                detail_level: {
                  type: 'string',
                  description: 'Response detail: summary (default), detailed, raw',
                  enum: ['summary', 'detailed', 'raw'],
                  default: 'summary',
                },
              },
              required: ['query'],
            },
          },
          {
            name: 'find_file_context',
            description: 'Find all conversations and changes related to a specific file',
            inputSchema: {
              type: 'object',
              properties: {
                filepath: {
                  type: 'string',
                  description: 'File path to search for in conversation history',
                },
                operation_type: {
                  type: 'string',
                  description: 'Filter by operation: read, edit, create, or all',
                  enum: ['read', 'edit', 'create', 'all'],
                  default: 'all',
                },
                limit: {
                  type: 'number',
                  description: 'Maximum number of results (default: 15)',
                  default: 15,
                },
                detail_level: {
                  type: 'string',
                  description: 'Response detail: summary (default), detailed, raw',
                  enum: ['summary', 'detailed', 'raw'],
                  default: 'summary',
                },
              },
              required: ['filepath'],
            },
          },
          {
            name: 'find_similar_queries',
            description: 'Find previous similar questions or queries with enhanced matching',
            inputSchema: {
              type: 'object',
              properties: {
                query: {
                  type: 'string',
                  description: 'Query to find similar previous questions',
                },
                limit: {
                  type: 'number',
                  description: 'Maximum number of results (default: 8)',
                  default: 8,
                },
                detail_level: {
                  type: 'string',
                  description: 'Response detail: summary (default), detailed, raw',
                  enum: ['summary', 'detailed', 'raw'],
                  default: 'summary',
                },
              },
              required: ['query'],
            },
          },
          {
            name: 'get_error_solutions',
            description: 'Find solutions for specific errors with enhanced matching',
            inputSchema: {
              type: 'object',
              properties: {
                error_pattern: {
                  type: 'string',
                  description: 'Error message or pattern to search for solutions',
                },
                limit: {
                  type: 'number',
                  description: 'Maximum number of results (default: 8)',
                  default: 8,
                },
                detail_level: {
                  type: 'string',
                  description: 'Response detail: summary (default), detailed, raw',
                  enum: ['summary', 'detailed', 'raw'],
                  default: 'summary',
                },
              },
              required: ['error_pattern'],
            },
          },
          {
            name: 'list_recent_sessions',
            description: 'Browse recent sessions with smart activity detection and summaries',
            inputSchema: {
              type: 'object',
              properties: {
                limit: {
                  type: 'number',
                  description: 'Maximum number of sessions (default: 10)',
                  default: 10,
                },
                project: {
                  type: 'string',
                  description: 'Optional project name to filter sessions',
                },
                include_summary: {
                  type: 'boolean',
                  description: 'Include intelligent session summaries (default: true)',
                  default: true,
                },
              },
            },
          },
          {
            name: 'extract_compact_summary',
            description: 'Get intelligent summary of a conversation session with key insights',
            inputSchema: {
              type: 'object',
              properties: {
                session_id: {
                  type: 'string',
                  description: 'Session ID to summarize',
                },
                max_messages: {
                  type: 'number',
                  description: 'Maximum messages to analyze (default: 10)',
                  default: 10,
                },
                focus: {
                  type: 'string',
                  description: 'Focus area: solutions, tools, files, or all',
                  enum: ['solutions', 'tools', 'files', 'all'],
                  default: 'all',
                },
              },
              required: ['session_id'],
            },
          },
          {
            name: 'find_tool_patterns',
            description: 'Analyze tool usage patterns, workflows, and successful practices',
            inputSchema: {
              type: 'object',
              properties: {
                tool_name: {
                  type: 'string',
                  description: 'Optional specific tool name to analyze',
                },
                pattern_type: {
                  type: 'string',
                  description: 'Type of patterns: tools, workflows, or solutions',
                  enum: ['tools', 'workflows', 'solutions'],
                  default: 'tools',
                },
                limit: {
                  type: 'number',
                  description: 'Maximum number of patterns (default: 12)',
                  default: 12,
                },
              },
            },
          },
          {
            name: 'search_plans',
            description:
              'Search Claude Code plan files for past implementation approaches, decisions, and patterns',
            inputSchema: {
              type: 'object',
              properties: {
                query: {
                  type: 'string',
                  description: 'Search query for plan content',
                },
                limit: {
                  type: 'number',
                  description: 'Maximum number of results (default: 10)',
                  default: 10,
                },
                detail_level: {
                  type: 'string',
                  description: 'Response detail level',
                  enum: ['summary', 'detailed', 'raw'],
                  default: 'summary',
                },
              },
              required: ['query'],
            },
          },
        ],
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions 'find all conversations and changes,' implying a read-only operation, but doesn't specify permissions, rate limits, data sources, or response format. For a tool with 4 parameters and no output schema, this leaves significant gaps in understanding how it behaves.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence: 'Find all conversations and changes related to a specific file.' It's front-loaded with the core purpose, has zero wasted words, and is appropriately sized for the tool's complexity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool has 4 parameters with 100% schema coverage but no annotations and no output schema, the description is minimally adequate. It states the purpose clearly but lacks behavioral context, usage guidance, and output details. For a search tool with moderate complexity, it should do more to compensate for the missing structured data.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all parameters thoroughly. The description doesn't add any meaning beyond what the schema provides—it doesn't explain parameter interactions, default behaviors, or practical examples. With high schema coverage, the baseline score of 3 is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Find all conversations and changes related to a specific file.' It specifies the verb ('find'), resource ('conversations and changes'), and target ('specific file'). However, it doesn't explicitly differentiate from sibling tools like 'search_conversations' or 'list_recent_sessions', which might have overlapping functionality.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention sibling tools like 'search_conversations' or 'list_recent_sessions', nor does it specify prerequisites, exclusions, or contextual triggers for usage. The agent must infer usage from the purpose alone.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Vvkmnn/claude-historian'

If you have feedback or need assistance with the MCP directory API, please join our Discord server