Skip to content

Bug: opencode stats --days=X command incorrectly considers messages outside the time window defined by X #21920

@kmampent

Description

@kmampent

Description

The opencode stats --days=X command, where X defines the time-window in days, correctly looks at all sessions that have been updated within the past X days. However, it considers all messages of these sessions when computing the statistics like total cost. I think the correct behavior should be to also only consider messages created within the last X days.

I have a fix coded for this and will raise a PR.

Plugins

No response

OpenCode version

1.4.3

Steps to reproduce

  1. When a new day begins and opencode stats --days=0 reports 0 cost, choose any session you worked on prior to today.
  2. Look at the total cost reported of that session, assume the cost is 5$.
  3. Send a simple prompt that by itself should only cost a few cents.
  4. Run opencode stats --days=0 again
  5. You will see a total cost reported that is greater than 5$

Screenshot and/or share link

Operating System

MacOS 26.3.1

Terminal

iTerm2

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions