Skip to main content
Glama

list_recent_sessions

Browse recent Claude conversation sessions with smart activity detection and summaries to track work history and find past solutions.

Instructions

Browse recent sessions with smart activity detection and summaries

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
limitNoMaximum number of sessions (default: 10)
projectNoOptional project name to filter sessions
include_summaryNoInclude intelligent session summaries (default: true)

Implementation Reference

  • MCP tool handler for 'list_recent_sessions': extracts parameters, calls UniversalHistorySearchEngine.getRecentSessions, formats with BeautifulFormatter.formatRecentSessions, and returns formatted text content.
    case 'list_recent_sessions': {
      const limit = (args?.limit as number) || 10;
      const project = args?.project as string;
    
      const universalResult = await this.universalEngine.getRecentSessions(limit, project);
      const formattedResult = this.formatter.formatRecentSessions(
        universalResult.results as any,
        project
      );
    
      return {
        content: [{ type: 'text', text: formattedResult }],
      };
    }
  • Input schema and registration for 'list_recent_sessions' tool in ListToolsRequest handler.
      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,
          },
        },
      },
    },
  • Core implementation of getRecentSessions in HistorySearchEngine: scans recent .jsonl files across projects in parallel, extracts session metadata (duration, tools, accomplishments, etc.), sorts by recency, limits to requested number.
    async getRecentSessions(limit: number = 10): Promise<any[]> {
      try {
        // OPTIMIZED: Fast session discovery with parallel processing and early termination
        const projectDirs = await findProjectDirectories();
    
        // PERFORMANCE: Limit projects and use parallel processing like GLOBAL
        const limitedDirs = projectDirs.slice(0, 10); // Limit projects for speed
    
        // PARALLEL PROCESSING: Process projects concurrently
        const projectResults = await Promise.allSettled(
          limitedDirs.map(async (projectDir) => {
            const jsonlFiles = await findJsonlFiles(projectDir);
            const decodedPath = projectDir.replace(/-/g, '/');
            const projectName = decodedPath.split('/').pop() || 'unknown';
    
            // PERFORMANCE: Limit files per project and process in parallel
            const limitedFiles = jsonlFiles.slice(0, 5); // Limit files for speed
    
            const sessionResults = await Promise.allSettled(
              limitedFiles.map(async (file) => {
                const messages = await this.parser.parseJsonlFile(projectDir, file);
    
                if (messages.length === 0) return null;
    
                // Fast extraction of session data
                const toolsUsed = [...new Set(messages.flatMap((m) => m.context?.toolsUsed || []))];
                const startTime = messages[0]?.timestamp;
                const endTime = messages[messages.length - 1]?.timestamp;
    
                // Quick duration calculation
                let realDuration = 0;
                if (startTime && endTime) {
                  realDuration = Math.round(
                    (new Date(endTime).getTime() - new Date(startTime).getTime()) / 60000
                  );
                }
    
                // Extract accomplishments - what was actually done
                const accomplishments = this.extractSessionAccomplishments(messages);
    
                return {
                  session_id: file.replace('.jsonl', ''),
                  project_path: decodedPath,
                  project_dir: projectDir,
                  project_name: projectName,
                  message_count: messages.length,
                  duration_minutes: realDuration,
                  end_time: endTime,
                  start_time: startTime,
                  tools_used: toolsUsed.slice(0, 5), // Limit tools for speed
                  assistant_count: messages.filter((m) => m.type === 'assistant').length,
                  error_count: messages.filter((m) => m.context?.errorPatterns?.length).length,
                  session_quality: this.calculateSessionQuality(messages, toolsUsed, []),
                  accomplishments: accomplishments.slice(0, 3), // Top 3 accomplishments
                };
              })
            );
    
            // Collect successful session results
            return sessionResults
              .filter((result) => result.status === 'fulfilled' && result.value)
              .map((result) => (result as PromiseFulfilledResult<any>).value);
          })
        );
    
        // Flatten and collect all sessions
        const realSessions: any[] = [];
        for (const result of projectResults) {
          if (result.status === 'fulfilled') {
            realSessions.push(...result.value);
          }
        }
    
        // Sort by real end time
        return realSessions
          .filter((s) => s.end_time) // Only sessions with real timestamps
          .sort((a, b) => new Date(b.end_time).getTime() - new Date(a.end_time).getTime())
          .slice(0, limit);
      } catch (error) {
        console.error('Recent sessions error:', error);
        return [];
      }
    }
  • Formatter for recent sessions results: ranks by productivity, structures JSON output with session details (id, ts, duration, messages, project, tools, accomplishments), adds robot emoji header.
    formatRecentSessions(sessions: any[], project?: string): string {
      const filter = project ? `"${project}"` : 'all';
      const header = `${robots.sessions} ${filter} | ${sessions.length} sessions`;
    
      if (sessions.length === 0) {
        return `${header}\n\n{"sessions":[]}`;
      }
    
      const rankedSessions = this.rankSessionsByProductivity(sessions);
      const topSessions = rankedSessions.slice(0, 10);
    
      const structured = {
        sessions: topSessions.map((s) => ({
          id: s.session_id?.substring(0, 8) || null,
          ts: this.formatTimestamp(s.end_time || s.start_time),
          duration: s.duration_minutes || 0,
          messages: s.message_count || 0,
          project: s.project_path?.split('/').pop() || null,
          tools: s.tools_used || null,
          accomplishments: s.accomplishments || null,
        })),
      };
    
      return `${header}\n\n${JSON.stringify(structured, null, 2)}`;
    }
  • UniversalHistorySearchEngine.getRecentSessions: delegates to HistorySearchEngine.getRecentSessions, adds enhanced flag if Claude Desktop available (though no Desktop sessions currently).
    // Universal methods for all tools
    async getRecentSessions(limit?: number, project?: string): Promise<UniversalSearchResult> {
      await this.initialize();
    
      const claudeCodeSessions = await this.claudeCodeEngine.getRecentSessions(limit || 10);
    
      if (!this.claudeDesktopAvailable) {
        return {
          source: 'claude-code',
          results: claudeCodeSessions as any,
          enhanced: false,
        };
      }
    
      // For sessions, Desktop doesn't have traditional sessions, so we focus on Code
      // But we mark as enhanced if Desktop is available for future Desktop session support
      return {
        source: 'claude-code',
        results: claudeCodeSessions as any,
        enhanced: this.claudeDesktopAvailable,
      };
    }
Behavior2/5

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

No annotations are provided, so the description carries full burden. It mentions 'smart activity detection and summaries' which hints at some processing behavior, but doesn't disclose critical details like whether this is a read-only operation, what permissions might be needed, rate limits, or how the 'smart' detection works. The description is vague about actual behavioral traits.

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 that gets straight to the point. Every word contributes to understanding the tool's purpose without any wasted text. It's appropriately sized and front-loaded with the core functionality.

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

Completeness2/5

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

For a tool with no annotations and no output schema, the description is insufficient. It doesn't explain what 'recent' means temporally, what format the results come in, what 'smart activity detection' entails, or how summaries are generated. The description leaves too many questions unanswered for a tool that presumably returns structured session 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 fully documents all three parameters. The description doesn't add any meaningful parameter semantics beyond what's in the schema - it doesn't explain how parameters interact or provide usage examples. Baseline 3 is appropriate when schema does the heavy lifting.

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 action ('Browse') and resource ('recent sessions'), and mentions additional features ('smart activity detection and summaries'). However, it doesn't explicitly differentiate this tool from sibling tools like 'search_conversations' or 'extract_compact_summary', 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. With siblings like 'search_conversations' and 'extract_compact_summary' available, there's no indication of when this browsing tool is preferred over those search or extraction tools.

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