Skip to content

fix(ccusage): add auto-refresh polling to CLI hooks using usageLimitsRefreshInterval preference#27281

Merged
raycastbot merged 3 commits intoraycast:mainfrom
kud:fix/ccusage-cli-auto-refresh
Apr 23, 2026
Merged

fix(ccusage): add auto-refresh polling to CLI hooks using usageLimitsRefreshInterval preference#27281
raycastbot merged 3 commits intoraycast:mainfrom
kud:fix/ccusage-cli-auto-refresh

Conversation

@kud
Copy link
Copy Markdown
Contributor

@kud kud commented Apr 19, 2026

Description

The four CLI hooks in the ccusage extension (useCCUsageDailyCli, useCCUsageMonthlyCli, useCCUsageTotalCli, useCCUsageSessionCli) were not auto-refreshing. useExec from @raycast/utils is a one-shot hook — it fetches once on mount and never polls again. As a result, usage data (today's cost, monthly total, session list) would only update when the user triggered a manual revalidation.

The fix adds a setInterval inside each CLI hook that calls result.revalidate() on the interval configured by the existing usageLimitsRefreshInterval preference (default 60 s). This wires up the refresh cadence that was already exposed as a user preference but had no effect on the CLI hooks.

Screencast

No visual changes — this is a background data-refresh fix. The displayed figures now update automatically at the configured interval instead of remaining stale until a manual refresh.

Checklist

@raycastbot raycastbot added extension fix / improvement Label for PRs with extension's fix improvements extension: ccusage Issues related to the ccusage extension AI Extension platform: macOS labels Apr 19, 2026
@raycastbot
Copy link
Copy Markdown
Collaborator

raycastbot commented Apr 19, 2026

Thank you for your contribution! 🎉

🔔 @nyatinte @zhuravel @GarrickZ2 @raulgg you might want to have a look.

You can use this guide to learn how to check out the Pull Request locally in order to test it.

📋 Quick checkout commands
BRANCH="fix/ccusage-cli-auto-refresh"
FORK_URL="https://github.com/kud/raycast-extensions.git"
EXTENSION_NAME="ccusage"
REPO_NAME="raycast-extensions"

git clone -n --depth=1 --filter=tree:0 -b $BRANCH $FORK_URL
cd $REPO_NAME
git sparse-checkout set --no-cone "extensions/$EXTENSION_NAME"
git checkout
cd "extensions/$EXTENSION_NAME"
npm install && npm run dev

We're currently experiencing a high volume of incoming requests. As a result, the initial review may take up to 10-15 business days.

@kud kud marked this pull request as ready for review April 19, 2026 16:28
@kud kud requested a review from pernielsentikaer as a code owner April 19, 2026 16:28
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 19, 2026

Greptile Summary

This PR wires up the pre-existing usageLimitsRefreshInterval preference to the four CLI data hooks (daily, monthly, total, session) by adding a setInterval inside a useEffect that calls result.revalidate() on the configured cadence. The fix is straightforward and correct; the only notable omission is that useCCUsageBlocksCli — which follows the same hook structure — was not given the same treatment.

Confidence Score: 5/5

Safe to merge; all findings are minor P2 style/completeness suggestions that do not affect correctness.

The polling logic is correct, the cleanup via clearInterval on unmount is present, and useExec's stable revalidate reference makes the stale-closure concern benign in practice. The missing useCCUsageBlocksCli update and the dependency-array style issue are both P2.

No files require special attention; minor polish suggestions exist across all four updated hooks.

Important Files Changed

Filename Overview
extensions/ccusage/src/hooks/useCCUsageDailyCli.ts Adds a setInterval-based auto-refresh via useEffect; stale-closure lint concern with result.revalidate not in the dependency array (benign in practice since revalidate is stable).
extensions/ccusage/src/hooks/useCCUsageMonthlyCli.ts Same polling pattern as daily hook; identical stale-closure caveat applies.
extensions/ccusage/src/hooks/useCCUsageTotalCli.ts Same polling pattern as daily hook; identical stale-closure caveat applies.
extensions/ccusage/src/hooks/useCCUsageSessionCli.ts Same polling pattern as daily hook; identical stale-closure caveat applies.
extensions/ccusage/CHANGELOG.md New [v2.3.1] entry added at the top with {PR_MERGE_DATE} placeholder; correctly follows the descending-version-order convention.

Comments Outside Diff (1)

  1. extensions/ccusage/src/hooks/useCCUsageBlocksCli.ts, line 52-53 (link)

    P2 useCCUsageBlocksCli not updated with polling

    The four CLI hooks in this PR all received the auto-refresh setInterval, but useCCUsageBlocksCli.ts — which follows the exact same pattern — was not updated. If blocks data is also expected to refresh automatically on the configured interval, this hook will remain stale until a manual revalidation. Is this omission intentional?

    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: extensions/ccusage/src/hooks/useCCUsageBlocksCli.ts
    Line: 52-53
    
    Comment:
    **`useCCUsageBlocksCli` not updated with polling**
    
    The four CLI hooks in this PR all received the auto-refresh `setInterval`, but `useCCUsageBlocksCli.ts` — which follows the exact same pattern — was not updated. If blocks data is also expected to refresh automatically on the configured interval, this hook will remain stale until a manual revalidation. Is this omission intentional?
    
    How can I resolve this? If you propose a fix, please make it concise.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: extensions/ccusage/src/hooks/useCCUsageDailyCli.ts
Line: 53-56

Comment:
**`result.revalidate` captured in stale closure**

`result.revalidate` is referenced inside the `setInterval` callback but is not listed in the `useEffect` dependency array. Since `intervalMs` is derived from module-level preferences (effectively constant), the effect runs once on mount and the callback permanently holds the `revalidate` reference from the first render.

In practice this is harmless because `useExec` returns a stable (memoized) `revalidate`, but the lint rule `react-hooks/exhaustive-deps` will flag it. The same pattern is repeated in all four updated hooks.

Or simply add `result.revalidate` to the dependency array (safe since the reference is stable).

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: extensions/ccusage/src/hooks/useCCUsageBlocksCli.ts
Line: 52-53

Comment:
**`useCCUsageBlocksCli` not updated with polling**

The four CLI hooks in this PR all received the auto-refresh `setInterval`, but `useCCUsageBlocksCli.ts` — which follows the exact same pattern — was not updated. If blocks data is also expected to refresh automatically on the configured interval, this hook will remain stale until a manual revalidation. Is this omission intentional?

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "🐛 fix(ccusage): add auto-refresh pollin..." | Re-trigger Greptile

Comment thread extensions/ccusage/src/hooks/useCCUsageDailyCli.ts Outdated
@0xdhrv 0xdhrv self-assigned this Apr 20, 2026
…cluding result.revalidate in dependency arrays
@raycastbot raycastbot added the OP is contributor The OP of the PR is a contributor of the extension label Apr 20, 2026
Copy link
Copy Markdown
Contributor

@0xdhrv 0xdhrv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, approved ✅

@raycastbot raycastbot merged commit c26ee17 into raycast:main Apr 23, 2026
2 checks passed
@github-actions
Copy link
Copy Markdown
Contributor

Published to the Raycast Store:
https://raycast.com/nyatinte/ccusage

@raycastbot
Copy link
Copy Markdown
Collaborator

🎉 🎉 🎉

We've rewarded your Raycast account with some credits. You will soon be able to exchange them for some swag.

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

Labels

AI Extension extension: ccusage Issues related to the ccusage extension extension fix / improvement Label for PRs with extension's fix improvements OP is contributor The OP of the PR is a contributor of the extension platform: macOS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants