Skip to content

fix(hooks): eliminate redundant disk reads on every hook invocation#2051

Open
rosschurchill wants to merge 1 commit into
rtk-ai:developfrom
rosschurchill:fix/c08-config-cache
Open

fix(hooks): eliminate redundant disk reads on every hook invocation#2051
rosschurchill wants to merge 1 commit into
rtk-ai:developfrom
rosschurchill:fix/c08-config-cache

Conversation

@rosschurchill
Copy link
Copy Markdown

Every rtk hook claude call unconditionally reads config.toml and settings.json before doing any work, even when nothing has changed.

Two fixes:

  1. In telemetry.rs and hook_check.rs: move the cheap day-marker stat() check before the Config::load() / settings.json read. If the marker is fresh, skip the disk read entirely.
  2. Cache Config in a std::sync::OnceLock<Config> so multiple calls within the same process reuse the loaded value. Hook entry points updated to use Config::load_cached().

Free to use as-is.

… OnceLock

telemetry.rs: day-marker stat is now checked before config::Config::load(). On
the hook hot-path the marker is almost always fresh, so the config.toml disk
read is skipped on 99% of invocations.

hook_check.rs: warn_marker is now checked before status(), which reads
settings.json unconditionally. Moving the rate-limit check first means
settings.json is read at most once per day, not on every hook call.

config.rs: adds Config::load_cached() backed by OnceLock<Config> so multiple
call sites within a single process share one config read.

hook_cmd.rs: hot-path callers (run_claude_inner, run_cursor_inner context) updated
to use load_cached(); also sets RTK_HOOK_MODE=1 at the top of each hook entry
function (C-07 fix for these entry points).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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.

2 participants