Skip to content

Fix context bar showing ~10% in worktree/agent sessions#30

Open
hangingwithshu wants to merge 1 commit into
ykdojo:mainfrom
hangingwithshu:fix/worktree-transcript-path
Open

Fix context bar showing ~10% in worktree/agent sessions#30
hangingwithshu wants to merge 1 commit into
ykdojo:mainfrom
hangingwithshu:fix/worktree-transcript-path

Conversation

@hangingwithshu
Copy link
Copy Markdown

Summary

  • Claude Code agents (spawned via the Agent tool or background jobs) run in isolated git worktrees via EnterWorktree
  • When the CWD switches to the worktree path, Claude Code derives a new project key, so transcript_path points to a project directory that doesn't exist yet
  • The -f check fails and the bar falls back to the 20k baseline (~10%), regardless of actual context usage

Fix

If transcript_path doesn't exist, fall back to searching for the session file by its UUID filename across all project directories under ~/.claude/projects. The transcript is always written to the original project dir, so the fallback finds it reliably.

Test plan

  • Open a session normally — context bar reads from transcript_path as before (no change)
  • Spawn a Claude agent or enter a worktree mid-session — context bar now finds the transcript via fallback and shows accurate usage instead of ~10%

Claude Code agents (spawned via the Agent tool or background jobs) now
run in isolated git worktrees. When EnterWorktree switches the CWD,
Claude Code derives the project key from the new worktree path, so
transcript_path points to a project directory that doesn't exist yet.
The -f check fails and the bar falls back to the 20k baseline (~10%),
regardless of how much context is actually loaded.

Fix: if transcript_path doesn't exist, search for the session file by
its UUID filename across all project directories under ~/.claude/projects.
The transcript is always written to the original project dir, so the
fallback finds it reliably.
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