Skip to main content
Glama

list_sessions

Browse and search Claude Code conversation history by project or date to find relevant sessions using local semantic and keyword indexing.

Instructions

List all indexed Claude Code sessions. Use when the user wants to browse conversation history or find sessions by project/date.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
projectNo
limitNo
sortNo

Implementation Reference

  • The handler function 'handleListSessions' that retrieves sessions from the database based on project filters and sorting preferences.
    export async function handleListSessions(
      db: Database.Database,
      params: ListSessionsParams
    ): Promise<{ content: Array<{ type: string; text: string }> }> {
      const limit = Math.min(params.limit || 20, 100);
      const sortDir = params.sort === "oldest" ? "ASC" : "DESC";
    
      let filterClause = "";
      const queryParams: unknown[] = [];
    
      if (params.project) {
        filterClause = "WHERE p.name LIKE ?";
        queryParams.push(`%${params.project}%`);
      }
    
      const sessions = db
        .prepare(
          `SELECT s.session_id, p.path as project, p.name as project_name,
                  s.branch, s.started_at, s.model, s.intent, s.turn_count,
                  s.indexed_at IS NOT NULL as indexed,
                  (SELECT COUNT(*) FROM chunks c WHERE c.session_id = s.id) as chunk_count
           FROM sessions s
           JOIN projects p ON p.id = s.project_id
           ${filterClause}
           ORDER BY s.started_at ${sortDir}
           LIMIT ?`
        )
        .all(...queryParams, limit) as any[];
    
      const totalSessions = (
        db.prepare("SELECT COUNT(*) as count FROM sessions").get() as any
      ).count;
    
      const totalIndexed = (
        db
          .prepare(
            "SELECT COUNT(*) as count FROM sessions WHERE indexed_at IS NOT NULL"
          )
          .get() as any
      ).count;
    
      // Project summary with registered status
      const userConfig = loadUserConfig();
      const registeredSet = new Set(userConfig.indexed_projects);
    
      const projects = db
        .prepare(
          `SELECT p.dir_name, p.name, p.path, COUNT(s.id) as session_count
           FROM projects p
           LEFT JOIN sessions s ON s.project_id = p.id
           GROUP BY p.id
           ORDER BY session_count DESC`
        )
        .all() as any[];
    
      const result = {
        sessions: sessions.map((s: any) => ({
          ...s,
          indexed: Boolean(s.indexed),
        })),
        total_sessions: totalSessions,
        total_indexed: totalIndexed,
        projects: projects.map((p: any) => ({
          name: p.name,
          path: p.path,
          session_count: p.session_count,
          registered: registeredSet.has(p.dir_name),
        })),
      };
    
      return { content: [{ type: "text", text: JSON.stringify(result) }] };
    }
  • Type definition for the input parameters of 'list_sessions'.
    export interface ListSessionsParams {
      project?: string;
      limit?: number;
      sort?: "recent" | "oldest";
    }
  • src/server.ts:84-99 (registration)
    Registration of the 'list_sessions' tool in the MCP server setup.
    // list_sessions tool
    server.tool(
      "list_sessions",
      "List all indexed Claude Code sessions. Use when the user wants to browse conversation history or find sessions by project/date.",
      {
        project: z.string().optional(),
        limit: z.number().optional(),
        sort: z.enum(["recent", "oldest"]).optional(),
      },
      async (args): Promise<ToolResult> => {
        return handleListSessions(db, {
          project: args.project,
          limit: args.limit,
          sort: args.sort,
        });
      }
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 that sessions are 'indexed' and implies filtering capabilities ('by project/date'), but lacks details on permissions, rate limits, pagination, or what 'indexed' entails. For a list tool with zero annotation coverage, this leaves significant gaps in understanding the tool's behavior and constraints.

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 concise and well-structured, consisting of two sentences that efficiently convey the tool's purpose and usage. The first sentence states what it does, and the second provides context for when to use it, with no wasted words or redundancy.

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?

Given the complexity (3 parameters, no annotations, no output schema), the description is incomplete. It lacks details on behavioral aspects like permissions or rate limits, and parameter semantics are underspecified. Without an output schema, it also doesn't describe return values (e.g., session format). For a tool with moderate complexity and no structured support, the description should provide more comprehensive guidance.

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

Parameters2/5

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

The input schema has 3 parameters with 0% description coverage, meaning no parameter details are documented in the schema. The description only vaguely references 'project/date' for filtering, which partially covers the 'project' parameter but ignores 'limit' and 'sort'. It doesn't explain what 'limit' controls (e.g., number of results) or the meaning of 'sort' enum values ('recent', 'oldest'), failing to compensate for the low schema coverage.

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: 'List all indexed Claude Code sessions.' It specifies the verb ('List') and resource ('indexed Claude Code sessions'), making it easy to understand what the tool does. However, it doesn't explicitly differentiate this tool from sibling tools like 'search' or 'get_context', which might also involve session retrieval.

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

Usage Guidelines4/5

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

The description provides clear usage guidance: 'Use when the user wants to browse conversation history or find sessions by project/date.' This gives context for when to invoke the tool, such as for browsing or filtering by project/date. It doesn't explicitly state when not to use it or name alternatives like 'search', but the context is sufficient for basic decision-making.

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/hyunjae-labs/lore'

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