Skip to content

fix: default to the current session via CLAUDE_CODE_SESSION_ID#4

Closed
wan-huiyan wants to merge 1 commit into
dioptx:mainfrom
wan-huiyan:feat/default-to-current-session
Closed

fix: default to the current session via CLAUDE_CODE_SESSION_ID#4
wan-huiyan wants to merge 1 commit into
dioptx:mainfrom
wan-huiyan:feat/default-to-current-session

Conversation

@wan-huiyan

Copy link
Copy Markdown

Problem

Run with no args, cctime selects the most-recently-modified session file. With a concurrently-active Claude session, that file is written last — so cctime silently reports a different session than the one you're in.

Fix

Claude Code exports CLAUDE_CODE_SESSION_ID to subprocesses. The no-arg default now resolves it via getSessionById (the same authoritative by-id lookup --session uses) → reports the actual current session. By-id lookup also skips the messageCount > 2 "main session" filter, which can otherwise drop an active session whose cached index count is stale (verified: an active session was missing from getAllSessions but found by id). When not inside Claude Code and ≥2 sessions were active in the last 5 min, it prints the chosen id + a --session hint instead of choosing silently.

Tests

New getCurrentSessionId() + getAllSessions() helpers; getLastSession delegates. +2 tests; tsc clean. Verified live: no-arg run reports the current session, not a concurrent sibling.

🤖 Generated with Claude Code

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.
@wan-huiyan

Copy link
Copy Markdown
Author

Superseded by #8 — moved to a dedicated branch (upstream/current-session). Same diff.

@wan-huiyan wan-huiyan closed this May 29, 2026
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.

1 participant