CLAUDE.md — dipstick #
What this is #
A KDE Plasma 6 plasmoid showing how much Claude Max quota is left, in the
panel. Scope, non-goals and the data-source contract: README.md.
Constraints #
- Target: Plasma 6 on Wayland. No X11, no other desktop environments.
The plasmoid runs inside
plasmashell: no heavy work (parsing, blocking network calls) in that process, or it takes the user's panel down with it. - Never touch
~/.claude/.credentials.json. The project runs its own OAuth flow with its own token. Touching that file risks invalidating the user's Claude Code session. - Never modify the desktop session. KDE configuration, panel, shortcuts, compositor: document how to install the plasmoid, do not do it. Installation is the user's to run.
- No network beyond
api.anthropic.comand the OAuth hosts used for login. No telemetry, no analytics, no crash reporter, no third-party endpoints. - Credentials never in the repository and never in the logs. The token lives only in the user's configuration directory.
~/.claude/projects/is READ-ONLY. Those are the user's real session logs, and Claude Code is writing to them while dipstick reads. Always open them read-only; any cache or state file belongs in dipstick's own configuration directory, never inside that tree.- The quota endpoint is undocumented: treat it as unstable. Every path that uses it must have a fallback onto local data.
Language #
All code is in English: identifiers, comments, error messages, logs, CLI output and interface source strings. Documentation and commit messages too.
Italian survives only where it is a translation: translations/it.po and the
localised package descriptions in the spec (Summary(it),
%description -l it).
Working on it #
Build, installation, code layout and diagnostic commands: README.md.
In short: make test for the tests (they never touch the network), make vet
before committing, and plasmawindowed org.kde.plasma.dipstick to try the
plasmoid without putting it in the panel — its QML errors go to the user
journal, not to the terminal.
Traps already hit #
plasmashelldoes NOT re-read the QML afterkpackagetool6 --upgrade. It keeps in memory the version loaded when the widget was added to the panel. It needssystemctl --user restart plasma-plasmashell.service, which has to be asked of the user because it makes their panel disappear for a few seconds.plasmawindowedis a fresh process every time and always sees the latest version: hence the risk of believing a change has landed while the user is still looking at the old one. Before calling a UI change done, make sure the user is looking at the same build. The restart only works if plasmashell runs under that unit. One started by hand (plasmashell --replacefrom a terminal) is outside systemd: the restart launches a second instance that finds the first, exits at once with status 0, and leaves the old build on screen — a silent no-op. Checksystemctl --user is-active plasma-plasmashell.serviceand the start time inps -o lstart= -C plasmashell; if the unit is inactive, the way back iskquitapp6 plasmashell; systemctl --user start plasma-plasmashell.service.XMLHttpRequestonfile://does not work in QML. Qt 6 disables it. The state is read throughPlasma5Support.DataSource(executable) instead.- Transcripts contain duplicate messages, in quantity: ~3900 lines with
usagefor ~2000 distinctmessage.id. Deduplicate bymessage.idor the token counts nearly double. The<synthetic>model is not a real call. - Duplicates are not identical copies: they are progressive snapshots of the same message, so keep the largest. Keeping the first one seen understates the total.
seven_day_opusandseven_day_sonnetcome backnull. The per-model breakdown lives inlimits[], with the name the server chooses: it is not a closed set.- The token must be taken under a lock. The daemon and the CLI share
auth.json: withoutflock, two concurrent refreshes can spend the refresh token twice and force a logout. It is the same risk for which this project refuses to touch~/.claude/.credentials.json, so it must not inflict it on itself. - Window boundaries for the totals are CALENDAR boundaries, not rolling
ones. The chart is made of days, so
MonthTokensand the per-model breakdown must start from the same midnight the series starts from. With a rolling boundary a sliver of messages was counted in the totals but drawn in no column. LDFLAGSin the Makefile must be calledGO_LDFLAGS. The former is a standard environment variable thatrpmbuildfills with C linker flags: with?=the environment wins, Go gets flags it does not understand, and the build fails only inside rpmbuild, never locally.xgettextmarks strings containing%1dor%1hasjavascript-format. They are not:%1and%2are KDE's placeholders and the letter after them is a unit of measure. With those flagsmsgfmtrejects a translation that changes the letter (%1dbecoming%1gfor "days").translations/extract.shstrips them.- A refresh round is not instant, and its length varies.
dipstick refreshonly sendsSIGUSR1and returns at once; the wait the user actually feels is the daemon's round. The first round after the daemon starts reads every transcript (~9 s on 1.6 GB); later ones read only what was appended, and are left with the quota call (~0.5 s). Any "loading" state in the plasmoid must therefore be tied tostate.jsonchanging, never to the lifetime of the command that was launched. - The full rescan grew with the history. At 316 files and 1.5 GB every
transcript had been touched within the month, so the mtime filter skipped
nothing and each round re-parsed everything (~11 s, 93% in
json.Unmarshalover tool output).transcript.Scannerkeeps, per file, the offset past the last complete line and that file's deduplicated messages, and reopens only files that grew. The cache lives in the daemon's memory, never on disk: one more file to invalidate would buy nothing a running process does not already have, and it could never go under~/.claude/projects/anyway. The one-shottranscript.Scan(the CLI) still reads everything. Iconinmetadata.jsonis resolved against the icon THEME, not against the package. Putting the SVG incontents/icons/and naming it there is not enough: KPackage does not look inside the package for it, and the widget turns up with a blank page in the "Add Widgets" list — worse than the generic theme icon it replaced. The same file has to be installed intoshare/icons/hicolor/scalable/apps/as well, which theMakefiledoes. It only shows up in the widget explorer, so it survives every check made on the popup alone.- Screenshots for the docs are taken against a made-up
state.json. The popup shows the e-mail of the logged-in account, and the real numbers are usually a quiet afternoon: mostly zeroes and half an empty chart. Stop the daemon, back upstate.json, write a demo state, shoot, restore, restart. Never retouch the image instead — that leaves the original in the file's metadata. Three things bite:- A day in
local.dailyneeds its ownmodelsmap, not justtokens. The chart stacks per model, so days carrying only a total draw nothing and the chart comes out empty while every figure above it looks right. severityis the server's word, not ours. "normal" is the only value ever observed, so a demo state must not invent "warning" to colour a bar.- Shoot under
LANG=en_GB.UTF-8, or the chart's date labels come out in the session language while the README is in English. Say in the caption that the data is made up: a screenshot of invented figures presented as a real reading is a small lie that costs nothing to avoid.
- A day in
plasmashellruns with a PATH that does NOT include~/.local/bin. The session gives it/usr/lib64/ccache:/usr/local/bin:/usr/bin:/binand nothing else, so a plaindipstick refreshfrom the QML exits 127 after amake installinto the home — while the very same command works from a terminal. A system/RPM install lands in/usr/binand hides the bug entirely. Anything the plasmoid launches has to carry the path with it.- Kirigami does not resolve the theme for a hidden item. An
Itemwithvisible: falsereads everyKirigami.Themecolour as black until it is shown, soLook.qmlis visible with no size — and therefore must never sit directly inside a layout, where it would take a cell (DailyChartandModelBreakdownwrap their layout in anItemfor this). - Inside plasmashell the theme has fewer roles than in an app. Plasma's
Kirigami theme gives
alternateBackgroundColorequal to the background and ignores theSelectioncolour set, while an app underorg.kde.desktopgets both: a preview outside the panel can look right on roles the panel does not have. Draw only with text, inactive text, background, highlight and the semantic colours; derive everything else from them. - Plasma remembers the popup's size per applet and reapplies it. It lives
as
popupWidth/popupHeightin the applet's configuration, clamped only by the representation'sLayoutminimum and maximum. The redesign shipped with a minimum and a preferred width but no maximum, and a width stretched under the old popup (1042px) came back and spread the cards across the screen. Pin all three, width and height alike. It never shows inplasmawindowedor in an offscreen render: only in the panel of someone who has used it. - No
parent.*in a Repeater delegate. The Repeater creates the delegate before parenting it, and unparents it on teardown, soparentis null on those evaluations: the chart'swidth: parent.widthlogged a TypeError per segment on every change ofstate.json(227 lines in one morning of~/.cache/plasmashell.log) while drawing correctly, so nothing on screen gave it away. Reach the container by id. An offscreen render with one state never shows it; replace the state a few times to catch it. state.jsoncarries no interface strings. Localisation belongs to the plasmoid; the daemon runs with no locale context.