claude-code - 💡(How to fix) Fix [FEATURE] Hook which fires when you run out of tokens; expose time when they will be available again [2 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#55945Fetched 2026-05-05 06:02:14
View on GitHub
Comments
2
Participants
2
Timeline
6
Reactions
0
Timeline (top)
commented ×2labeled ×2renamed ×2
RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing requests and this feature hasn't been requested yet
  • This is a single feature request (not multiple features)

Problem Statement

I would like for there to be a mechanism to run a hook when Claude runs out of tokens, with machine-readable information about when they will be replenished.

The concrete use case I have in mind is to send myself a Slack message when my hard-working agent is unable to proceed, so that I can decide whether I want to authorize additional spend or otherwise plan my other work accordingly.

There is an earlier related issue which however has been closed; it is slightly different in scope and ask:

  • #26551 asks for a hook which fires when a limit is approaching so it is different in that mine fires a single time at a well-defined boundary. It was closed as stale a few weeks ago.

It has links to other issues about user visibility and management of hitting the token limit, but none of those are about exposing this information via a hook or making the resume date and time available in machine-readable format.

Proposed Solution

When you are about to display the "You've hit your limit · resets Apr 1 at 9pm (America/New_York)" notification, fire a NotificationUsageLimit hook. Pass in the date and time when the tokens will be reset as a hook parameter, or perhaps as an environment variable, expressed as a Unix time stamp.

Alternative Solutions

I suppose you could write a wrapper which identifies this situation, but it would have to be updated each time the localization of this notification message changes, and contain somewhat contorted logic to convert the human-readable time stamp (which can be relative or absolute) into a machine-readable time stamp.

Priority

Medium - Would be very helpful

Feature Category

Other

Use Case Example

  • As in the near-duplicate, play a sad sound when the usage limit is hit.
  • Send a Slack message (or Discord, Telegram, SMS, etc) to notify the user when running in headless mode.
  • As part of a larger system to manage resources, run scripts which need for Claude to be idle while they are running. Capture the session before compacting? Save a backup?
  • Suggest the user to take a well-deserved break? Display the time until you can resume in a screen saver?

Additional Context

No response

extent analysis

TL;DR

Implement a NotificationUsageLimit hook that fires when Claude runs out of tokens, passing the token reset date and time as a Unix timestamp.

Guidance

  • Identify the point in the code where the "You've hit your limit" notification is displayed and insert the hook call at that location.
  • Pass the reset date and time as a parameter to the hook, converting it to a Unix timestamp for machine readability.
  • Consider using an environment variable to store the reset timestamp for easier access in the hook handler.
  • Evaluate the proposed solution against the alternative of writing a wrapper, weighing the trade-offs between maintainability and complexity.

Example

import time
from datetime import datetime

# Assuming 'reset_date' is the date and time when tokens will be reset
reset_timestamp = int(datetime.strptime(reset_date, "%Y-%m-%d %H:%M:%S").timestamp())
# Fire the NotificationUsageLimit hook with the reset timestamp
fire_hook("NotificationUsageLimit", reset_timestamp)

Notes

The implementation details may vary depending on the programming language and framework used by Claude. The example provided is a simplified illustration of the concept.

Recommendation

Apply the proposed solution by implementing the NotificationUsageLimit hook, as it provides a straightforward and maintainable way to notify users when the token limit is reached.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix [FEATURE] Hook which fires when you run out of tokens; expose time when they will be available again [2 comments, 2 participants]