fix: default to the current session via CLAUDE_CODE_SESSION_ID#4
Closed
wan-huiyan wants to merge 1 commit into
Closed
fix: default to the current session via CLAUDE_CODE_SESSION_ID#4wan-huiyan wants to merge 1 commit into
wan-huiyan wants to merge 1 commit into
Conversation
Run with no args, cctime picked the most-recently-*modified* session file — which loses to any concurrently-active Claude session, so it could silently report a different session's stats than the one you're in (hit in practice: a 16h background session shadowed the 1h session being asked about). Claude Code exports CLAUDE_CODE_SESSION_ID to subprocesses. Resolve it via getSessionById (the same authoritative lookup --session uses) so the default is the actual current session. getSessionById matches by id and skips the messageCount>2 "main session" filter — important because an active session's cached index count can be stale/low and would otherwise exclude it from getAllSessions. When not inside Claude Code and ≥2 sessions were active in the last 5 min, print the chosen id + a --session hint instead of choosing silently. Adds getCurrentSessionId() + getAllSessions() to finder + 2 tests. 89 pass. Verified live: no-arg run now reports the current session, not a 16h sibling.
Author
|
Superseded by #8 — moved to a dedicated branch ( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Run with no args,
cctimeselects the most-recently-modified session file. With a concurrently-active Claude session, that file is written last — socctimesilently reports a different session than the one you're in.Fix
Claude Code exports
CLAUDE_CODE_SESSION_IDto subprocesses. The no-arg default now resolves it viagetSessionById(the same authoritative by-id lookup--sessionuses) → reports the actual current session. By-id lookup also skips themessageCount > 2"main session" filter, which can otherwise drop an active session whose cached index count is stale (verified: an active session was missing fromgetAllSessionsbut found by id). When not inside Claude Code and ≥2 sessions were active in the last 5 min, it prints the chosen id + a--sessionhint instead of choosing silently.Tests
New
getCurrentSessionId()+getAllSessions()helpers;getLastSessiondelegates. +2 tests;tscclean. Verified live: no-arg run reports the current session, not a concurrent sibling.🤖 Generated with Claude Code