Skip to content

feat(session): add messageCount endpoint for efficient message counting#13795

Open
sjawhar wants to merge 1 commit intoanomalyco:devfrom
sjawhar:feat/session-message-count
Open

feat(session): add messageCount endpoint for efficient message counting#13795
sjawhar wants to merge 1 commit intoanomalyco:devfrom
sjawhar:feat/session-message-count

Conversation

@sjawhar
Copy link
Copy Markdown

@sjawhar sjawhar commented Feb 16, 2026

Issue for this PR

Closes #14602

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Adds a Session.messageCount() function that uses SELECT COUNT(*) to efficiently get the number of messages in a session without loading all message data, and exposes it via a GET /:sessionID/message/count API route.

Currently there's no way to get just the count of messages in a session — clients must fetch the full message list, which is wasteful for use cases like displaying session summaries.

Changes:

  • packages/opencode/src/session/index.ts: New messageCount export using Drizzle sql template for COUNT(*)
  • packages/opencode/src/server/routes/session.ts: New route with OpenAPI docs, param validation, and error responses

How did you verify your code works?

  • Typecheck passes
  • Tested the endpoint locally against an existing session with messages

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions
Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@sjawhar
Copy link
Copy Markdown
Author

sjawhar commented Feb 17, 2026

@adamdotdevin this is ready for review: issue linked, CI passing, and mergeable. Could you take a look when you have a moment?

resolve: merge conflicts in generated SDK files
@sjawhar sjawhar force-pushed the feat/session-message-count branch from 23f9706 to af0aef3 Compare March 26, 2026 11:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE]: add session message count endpoint for efficient counting

1 participant