Skip to content

Persist usage statistics (currently only shown once when CLI exits) #1394

Closed

Description

@quijote

Describe the feature or problem you'd like to solve

Copilot CLI does not persist usage statistics (premium requests, token usage per model)

Proposed solution

Copilot CLI does not provide usage statistics for individual users on an Enterprise plan.

Therefore, I asked Copilot CLI to generate a Python script to analyze its own data in ~/.copilot/ directory (see screenshot in context).

Unfortunately the following valuable information is currently only shown once to the user but not persisted in events.jsonl or other files:

 Total usage est:        7 Premium requests
 API time spent:         2m 59.626s
 Total session time:     12m 15.77s
 Total code changes:     +206 -77
 Breakdown by AI model:
  claude-sonnet-4.5       453.0k in, 13.1k out, 405.7k cached (Est. 7 Premium requests)

When user exits Copilot CLI, please write information above into ~/.copilot/session-state/events.jsonl (e.g. as part of message with type abort) or another file. Please ensure that statistics cover the entire session (including continuations).

Example prompts or workflows

No response

Additional context

Image

Activity

  1. added theissue type on Feb 10, 2026
  2. dscho commented on Mar 15, 2026

    @dscho

    To add insult to injury, when resuming a session (e.g. as part of an /update), the usage statistics are completely lost:

    Total usage est:        15 Premium requests
     API time spent:         4m 15s
     Total session time:     34m 41s
     Total code changes:     +122 -8
     Breakdown by AI model:
      claude-opus-4.6         1.3m in, 11.2k out, 1.1m cached (Est. 15 Premium requests)
      claude-haiku-4.5        130.0k in, 3.0k out, 105.8k cached (Est. 0 Premium requests)
    
     Resume this session with copilot --resume=c07bcaac-341b-4e6b-b20e-56f02d353dfb
    Total usage est:        0 Premium requests
     API time spent:         0s
     Total session time:     35m 3s
     Total code changes:     +122 -8
    
     Resume this session with copilot --resume=c07bcaac-341b-4e6b-b20e-56f02d353dfb
    

    This lack of persistence/continuity caused rather unpleasant surprises over here.

  3. markus-gaisbauer-dt commented on Apr 1, 2026

    @markus-gaisbauer-dt

    I think this ticket has been implemented sometime around beginning of March.

    Event type session.shutdown now contains modelMetrics:

    {
        "type": "session.shutdown",
        "data": {
            "shutdownType": "routine",
            "totalPremiumRequests": 1,
            "totalApiDurationMs": 430642,
            "sessionStartTime": 1772816419880,
            "codeChanges": {
                "linesAdded": 0,
                "linesRemoved": 0,
                "filesModified": []
            },
            "modelMetrics": {
                "gpt-5.4": {
                    "requests": {
                        "count": 5,
                        "cost": 1
                    },
                    "usage": {
                        "inputTokens": 244120,
                        "outputTokens": 2383,
                        "cacheReadTokens": 202112,
                        "cacheWriteTokens": 0
                    }
                },
                "claude-sonnet-4.5": {
                    "requests": {
                        "count": 55,
                        "cost": 0
                    },
                    "usage": {
                        "inputTokens": 2158320,
                        "outputTokens": 10643,
                        "cacheReadTokens": 2118726,
                        "cacheWriteTokens": 0
                    }
                }
            },
            "currentModel": "gpt-5.4"
        },
        "id": "...",
        "timestamp": "2026-03-06T17:08:10.988Z",
        "parentId": "..."
    }
    
  4. examon commented on Apr 7, 2026

    @examon

    This has been fixed. Usage statistics (premium requests, per-model token usage, API time, code changes) are now persisted to events.jsonl as a session.shutdown event when the CLI exits. Usage metrics also survive session resume. If you believe this isn't fully resolved, feel free to reopen this issue.

  5. yuvalhnoga commented on Apr 12, 2026

    @yuvalhnoga

    @examon It's broken still for me in latest version of copilot and now it doesn't even show the breakdown per AI model anymore.
    Looks like this on first exit:

    Image

    Then looks like this after resuming:

    Image
  6. reopened this on Apr 13, 2026
  7. added
    area:sessionsSession management, resume, history, session picker, and session state
    and removed on Apr 16, 2026
  8. patniko commented on Oct 26, 2026

    @patniko
    Collaborator

    Thanks for the report. We've shipped fixes in this area since this was filed (most recently in Copilot CLI v1.0.96), and we believe this may now be resolved. Could you retest on the latest release (Copilot CLI v1.0.103) and let us know whether you still see it? If we don't hear back in a couple of weeks, we may close this issue — you can always reopen it.

    Triaged as part of a Copilot SDK backlog review, with help from GitHub Copilot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:sessionsSession management, resume, history, session picker, and session statemore-info-needed

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions