Repository navigation
feat(save-more): find client settings that cost money (#615) - #648
Conversation
Evidence for check 1: our litellm gateway supports tool searchRemoving Result: it works. Users of this gateway do not need Test: 2 sandboxed
What the capture shows (6 main requests):
Earlier runs with the setting off, straight to the gateway: Opus 1M with a subagent, and Sonnet with the same task. Both passed with no errors. Not tested:
Suggestion for the check text: keep the 400-error risk, because other gateways can differ. Add: "If tool search fails on your gateway, set |
… shape (#615) Return, per check, the request count and summed cost_usd of the caller's rows that match the check's request shape. Columns only, no request text. A check with no known shape returns a null cost, never 0. Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID AMID <[email protected]>
Add a "Settings that cost you money" card to save-more, and `save-more settings` alone. Two checks: CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS and the session recap. Detection reads only the named keys from the user's own settings files and env. Cost comes from /api/adapt/settings; an old proxy shows "not measured yet". `apply settings <id>` backs up, edits one key and records the old value. `revert settings <id>` restores it, and refuses if the key changed since. The check list is scripts/costly_settings.json. Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID AMID <[email protected]>
…615) A clean Claude Code 2.1.305 sends its classifier request with 2 system blocks, not 3: the third block ("Session Context") is not always there. The price shape required 3 blocks and 2 dashboard messages, so on a clean install the card showed $0 for 4 billed classifier requests. The shape now keys on model (sonnet), 0 tools, max_tokens 64 and no stream. On a developer proxy and on box 2 production these 4 fields select the same rows as before plus the 2-block ones (box 2: 9,941 rows against 9,793), and no other request. The Go test now seeds both block counts. Also gofmt two test files. Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID AMID <[email protected]>
95b54a9 to
80314db
Compare
End-to-end test on a clean Claude Code, and 2 fixesSetup: Claude Code 2.1.305 in auto mode, with a sandbox Results
Fix 1: the price shape missed a clean install (commit
Fix 2: gofmt on Conflicts with main resolved (rebase on
Tests after the rebase (box 2,
|
amiddavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 2 (bob, user of @amiddavid) | IBM Bob Shell 1.0.3 | offload-review skill, @amiddavid's session | fresh | 2 of 2 | 1 of 2 | 80314db434f8 |
blocking |
Verdict: blocking
Findings
- go.mod:48, go.sum:65-66 — Dependency downgrade appears unintentional
- What fails:
klauspost/compresschanges from v1.18.7 to v1.18.6, which is a downgrade - Proof: The diff shows
go.modline 48 changing fromgithub.com/klauspost/compress v1.18.7 // indirecttogithub.com/klauspost/compress v1.18.6 // indirect. Thego.sumchanges from v1.18.7 checksums to v1.18.6 checksums. This PR adds a settings feature and has no reason to downgrade an unrelated compression library. - Fix: Run
go get github.com/klauspost/[email protected]andgo mod tidyto restore the version, or explain why the downgrade is intentional.
- What fails:
Non-blocking
- The new
/api/adapt/settingsroute is well-designed. It uses metadata only (request shape columns), never reads request text, and returns explicit null for unmeasured checks rather than zero. - The Python code follows good practices: atomic file writes, proper backup handling, symlink preservation, and comprehensive error messages.
- Test coverage is thorough. The Go test
TestCostlyChecksMatchThePluginListensures the proxy and plugin stay synchronized on request shapes. - The feature correctly handles the three-level storage model (off/metadata/everything) and updates
docs/data-dependence.mdas required. - The skill integration is clean. The
settingsword can run alone or withconfigandcache, and the apply/revert commands follow the existing pattern.
What I checked
- Read
CLAUDE.mdanddocs/design.mdfor repo rules - Read the full diff (all changed files)
- Verified the new API route follows the metadata-only principle
- Checked that
CostlyChecksin Go matchescostly_settings.jsonstructure - Reviewed Python test coverage for detection, cost calculation, and file editing
- Confirmed the feature integrates correctly with the save-more skill
- Verified error handling and fail-open behavior
- Checked that the feature respects the storage level rules
- Examined the go.mod/go.sum changes
amiddavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 1 (bob, user of @amiddavid) | IBM Bob Shell 1.0.3 | offload-review skill, @amiddavid's session | fresh | 1 of 2 | 1 of 2 | 80314db434f8 |
blocking |
Verdict: blocking
Findings
-
go.mod:48 — Unintended dependency downgrade
- What fails:
klauspost/compressdowngraded from v1.18.7 to v1.18.6 - Proof: Line 48 in go.mod shows
github.com/klauspost/compress v1.18.6 // indirect, and go.sum confirms the downgrade. The PR description does not mention this change. This is an indirect dependency, so the downgrade likely came from runninggo mod tidyor updating another dependency. - Fix: Revert to v1.18.7 by running
go get github.com/klauspost/[email protected]andgo mod tidy, or document why the downgrade is needed.
- What fails:
-
dash/costlysettings.go:103 — SQL injection risk in dynamic query construction
- What fails:
shapeWherebuilds SQL with string concatenation:col+" = ?". Ifcolcomes from untrusted input, this allows SQL injection. - Proof: Lines 103-104 iterate over a map where keys are column names:
for col, v := range map[string]*int{"r.tools": s.Tools, ...}. The keys are hardcoded here, but the function signature acceptsCostlyShapefrom external input. If a future caller passes aCostlyShapewith a malicious field, the column name goes directly into SQL. - Fix: Use a whitelist. Check that
colis one of the allowed column names before building the query. Or use a fixed set of column builders instead of a map.
- What fails:
-
dash/costlysettings.go:119 — Missing error handling for empty result set
- What fails:
costlyPartcallsQueryRowContextand scans intonandusd. If the query returns no rows,Scanreturnssql.ErrNoRows, but the function returns this error to the caller. The caller inCostlySettings(line 137) returns the error, which makes the whole route fail with 500. - Proof: Line 119 scans the result.
QueryRowContextwithCOUNT(*)always returns one row, so this is safe. But if the query changes, or if a future edit removes theCOUNT(*), the route fails instead of returning zero. - Fix: None needed now, but add a comment that the query must always return one row, or handle
sql.ErrNoRowsexplicitly.
- What fails:
-
context-guru-plugin/scripts/costly.py:285 — Race condition in atomic write
- What fails:
_write_atomiccreates a temp file, writes it, sets its mode, then renames it over the target. Betweenos.chmodandos.replace, another process could read the temp file with the new mode but old content. - Proof: Lines 285-295 show the sequence. The temp file is created with
mkstemp, which gives it mode 0600. Line 292 changes the mode. Line 293 renames it. If the target mode is 0644, the temp file becomes world-readable before the rename completes. - Fix: This is a known limitation of atomic writes on POSIX. The risk is low because the temp file has a random name in the same directory as the target. Document this, or accept it.
- What fails:
-
context-guru-plugin/scripts/costly.py:374 — Backup file not cleaned up on success
- What fails:
applywrites a backup file (line 374) but never deletes it. Over time, the config directory fills with.bakfiles. - Proof: Line 374 writes the backup. Line 378 writes the new file. No code deletes the backup. The user must clean it up manually.
- Fix: This is intentional. The backup is for the user, not for Context Guru. Document that old backups should be cleaned up, or add a cleanup command.
- What fails:
-
dash/costlysettings_test.go:142 — Test does not verify tenant isolation
- What fails:
TestCostlyChecksMatchThePluginListcompares the Go and Python lists, but it does not test that the route enforces tenant isolation. A manager can name another tenant, but a regular user cannot. - Proof:
TestCostlySettingsRouteIsOneAccount(line 99) tests this, but only for the route. The test does not verify thatCostlySettingsitself filters by tenant, or that a malicious caller cannot bypass the filter. - Fix: Add a test that calls
CostlySettingsdirectly with a filter for tenant A, seeds rows for tenant B, and verifies that the result has zero rows.
- What fails:
Non-blocking
- dash/costlysettings.go:42: The comment says "No system_blocks or messages" because the classifier shape varies. This is correct, but it makes the shape match more requests than just the classifier. A future model with the same shape but a different purpose would be counted. Consider adding a comment that this is a known limitation.
- context-guru-plugin/scripts/costly.py:200:
where_wordsjoins locations with semicolons. If a location path contains a semicolon, the output is ambiguous. This is unlikely, but consider using a different separator or quoting paths. - context-guru-plugin/scripts/test_costly.py:28: The test sets
CONTEXT_GURU_STATEto a temp dir, but it does not clean up the state file after each test. If a test fails, the state file stays. Consider usingself.addCleanupto remove it.
What I checked
- Read CLAUDE.md and docs/design.md for repo rules
- Read the full diff (2,000+ lines across 15 files)
- Examined dash/costlysettings.go: SQL query construction, error handling, tenant filtering
- Examined dash/costlysettings_test.go: shape matching, tenant isolation, null handling
- Examined context-guru-plugin/scripts/costly.py: file I/O, atomic writes, backup handling
- Examined context-guru-plugin/scripts/test_costly.py: test coverage, temp file cleanup
- Examined context-guru-plugin/scripts/costly_settings.json: check definitions, price shapes
- Verified that the Go test compares the Python and Go lists (line 142 of costlysettings_test.go)
- Checked go.mod and go.sum for dependency changes
- Verified that the route is mounted in dash/toolapi.go (line 1040)
- Checked that the skill documentation is updated (docs/plugin/save-more.md)
- Verified that the Python tests run in the Go test suite (context-guru-plugin/costly_test.go:18)
- Checked for fail-open violations: the route returns 500 on error, which is correct (no silent data loss)
- Checked for data loss: the apply/revert mechanism backs up before writing, and refuses to revert if the file changed
- Checked for security issues: found SQL injection risk (finding 2), but it is mitigated by hardcoded column names
- Verified that new behavior has tests: Python unit tests, Go integration tests, and golden tests
The first commit of this branch moved klauspost/compress back to v1.18.6. That undid the CVE-2026-63209 bump on main (#645). go.mod and go.sum are now the same as main. Both reviewers found it in round 1. Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID AMID <[email protected]>
Replies to round 1Both reviewers, finding 1 (
Reviewer 1, findings 2–6: rejected, no change. Each one, with the reason:
Non-blocking points: noted, no change. The test cleanup is already done with |
amiddavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 1 (bob, user of @amiddavid) | IBM Bob Shell 1.0.3 | offload-review skill, @amiddavid's session | resumed | 1 of 2 | 2 of 2 | 4d6184285916 |
approve |
Verdict: approve
Findings
None. All round 1 findings have been addressed.
Status of round 1 findings
-
go.mod:48 — Unintended dependency downgrade: FIXED
- The author restored
klauspost/compressto v1.18.7 in commit4d618428. - Verified:
go.modline 48 now shows v1.18.7, andgo.sumhas the correct checksums. - The commit message explains this undid a CVE fix from main (#645).
- The author restored
-
dash/costlysettings.go:103 — SQL injection risk: REJECTED, valid
- The author is correct. Column names come from the hardcoded map literal
{"r.tools": s.Tools, ...}, not fromCostlyShapefields. CostlyShape.ModelContainsis the only string field, and it is bound as a parameter:instr(lower(r.model), ?).- All shapes come from the
CostlyChecksliteral, not from external input. - No change needed.
- The author is correct. Column names come from the hardcoded map literal
-
dash/costlysettings.go:119 — Missing error handling: REJECTED, valid
- The author is correct.
SELECT COUNT(*), COALESCE(SUM(...),0)always returns exactly one row. sql.ErrNoRowscannot occur with this query.- My finding said "this is safe" and asked only for a comment. The author chose not to add one.
- No change needed.
- The author is correct.
-
context-guru-plugin/scripts/costly.py:285 — Race condition: REJECTED, valid
- The author is correct.
mkstempcreates the temp file with mode 0600. os.chmodruns beforeos.replace, so the file is never wider than its target mode before the rename.- A reader of the temp file sees the new content with the new mode, not old content.
- This is standard atomic write behavior on POSIX.
- No change needed.
- The author is correct.
-
context-guru-plugin/scripts/costly.py:374 — Backup not cleaned up: REJECTED, valid
- The author is correct. The backup is for the user, not for Context Guru.
- Each apply writes one timestamped file, and an apply happens only after a yes.
- Revert does not depend on the backup (it uses the recorded old value).
- My finding said "this is intentional". The author confirmed it.
- No change needed.
-
dash/costlysettings_test.go:142 — Tenant isolation not tested: REJECTED, valid
- The author is correct.
TestCostlySettingsMatchesTheClassifierShapeOnlycallsdb.CostlySettingsdirectly withFilter{Tenant: "t1"}andFilter{Tenant: "t2"}. - Lines 70-73 verify that the t1 call does not count the t2 row ($9), and the t2 call gets only its own row.
TestCostlySettingsRouteIsOneAccountcovers the route layer.- No change needed.
- The author is correct.
What I checked
- Last review: round 1, 80314db, 2026-10-22T14:17:29Z
- New commits read: 1 commit
4d618428fix(deps): keep klauspost/compress at v1.18.7 from main (#615)
- Read in full: 2 reviews, 3 comments, 0 inline comments (from the three files)
- New items since my last review:
- Author's comment at 2026-10-22T08:53:54Z: Evidence for check 1 (tool search gateway test). Noted.
- Author's comment at 2026-10-22T14:12:09Z: End-to-end test and 2 fixes. Verified the dependency fix is in commit
4d618428. - Author's comment at 2026-10-22T14:20:49Z: Replies to round 1. Reviewed each rejection and verified the reasoning.
- Verified the dependency fix:
go.modandgo.sumnow match main forklauspost/compress - Reviewed the author's rejections of findings 2-6: all are valid
- Checked that no new code was added in the fix commit: only
go.modandgo.sumchanged - Verified that the fix commit message explains the reason (CVE-2026-63209 bump on main)
- Confirmed that the author ran tests after the fix (mentioned in comment at 2026-10-22T14:12:09Z)
- Checked for new issues introduced by the fix: none found
amiddavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 2 (bob, user of @amiddavid) | IBM Bob Shell 1.0.3 | offload-review skill, @amiddavid's session | resumed | 2 of 2 | 2 of 2 | 4d6184285916 |
approve |
Verdict: approve
Findings
None. My round 1 finding is fixed.
Status of round 1 findings
My finding 1 (go.mod dependency downgrade): fixed in commit 4d61842.
- The commit restores
klauspost/compressto v1.18.7, matching main. - Verified: go.mod line 48 now shows v1.18.7, and go.sum lines 65-66 have the correct checksums.
- The commit message explains this undid a CVE fix from main (#645).
Reviewer 1 findings 2-6: author rejected with detailed reasons.
- I reviewed each rejection. The author's reasoning is sound:
- Finding 2 (SQL injection): column names come from a hardcoded map literal, not from external input.
- Finding 3 (sql.ErrNoRows): COUNT(*) always returns one row.
- Finding 4 (atomic write race): the temp file mode is set before rename, so no race exists.
- Finding 5 (backup cleanup): intentional design, backups are for the user.
- Finding 6 (tenant isolation test): already tested in lines 45-73 of costlysettings_test.go.
Non-blocking
- The author's end-to-end test (comment 2026-10-22T14:12:09Z) demonstrates the feature works correctly on a clean Claude Code install.
- The price shape fix (removing system_blocks and messages requirements) correctly handles the classifier request variation.
- The evidence for check 1 (comment 2026-10-22T08:53:54Z) shows the litellm gateway supports tool search, validating the risk text.
What I checked
- Last review: round 1, 80314db, 2026-10-22T14:17:12Z
- New commits read: 1 commit
- Read in full: 2 reviews, 3 comments, 0 inline comments
- New items since my last review:
- Verified the dependency fix: go.mod and go.sum now match main for klauspost/compress
- Read author's replies to all round 1 findings from both reviewers
- Reviewed author's end-to-end test results showing the feature works correctly
- Checked author's evidence for the tool search gateway compatibility
- Confirmed the price shape fix addresses the clean install case
- Verified no new code changes beyond the dependency fix
- Confirmed all round 1 blocking issues are resolved
|
On the next release's list (#658), by the release owner. |
docs(data-dependence): add the costly settings check (#615) #648 added GET /api/adapt/settings and the save-more settings card, but no row in the features table. The check is metadata only: it counts and prices dashboard rows by model name, tool count, max_tokens and the stream flag. The plugin reads only the named keys of the user's own settings files, on the user's machine, and sends none of them to the proxy. With the dashboard off, the plugin still finds the settings and says the cost is not measured. Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID AMID <[email protected]>
…0.2.4) (#673) chore(plugin): bump the plugins for v0.5.4 (Claude Code 0.5.4, Codex 0.2.4) Both plugins changed in this release, so installed plugins must update. - Claude Code plugin: the new band and pane (#659), one status-line timer and the 12 old commands removed (#660), the Ping header and ping reasons (#667), and the save-more settings card (#648). - Codex plugin: the vendored cg.py and the save-more settings card from #648, #660 and #667. Assisted-By: Claude Signed-off-by: DAVID AMID <[email protected]>
Summary
/context-guru:save-more.CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETASand the session recap.Refs #615.
What changed
context-guru-plugin/scripts/costly_settings.json. Each check has id, what it reads, detection, price shape, fix, risk, and "applicable". A Go test keeps the proxy shapes equal to the file.scripts/costly.py): reads only the named keys from user, user-local, project, project-local and managed settings, and from the process env. It says which file a value came from.GET /api/adapt/settings?since=&until=(dash/costlysettings.go): per check, request count and summedcost_usdfor the caller's tenant. Unknown shape returnsnull.save-moreand insave-more settings. Only checks that fire.apply settings <id>,revert settings <id>. Apply makes a timestamped.bak, edits one key, keeps the file mode, writes atomically, and records the old value. Revert restores that value. It refuses if the key changed since.Apply it?line.SKILL.mdfiles (Claude Code and Codex),docs/plugin/save-more.md, and the vendored Codex copies.How it was tested
On the shared box (
~/cgssh2), Go with-race:go vet ./dash/ ./context-guru-plugin/: clean.go test -race ./dash/...: ok (415 s).go test -race ./context-guru-plugin/...: only the 2 known box-only failures (TestInstallRefusesAnUnverifiedDownload,TestInstallReportsPATHFromTheSourceFallbackToo). One more,TestUserScopeAdoptHandlesAProjectPathWithASpace, failed once on/tmp/context-guru-proxy-*.log: Permission denied(a log file owned by another session on the shared box). It did not fail in the second full run.Costly|SaveMore|CG|Docs|Skill|Vendored): ok.scripts/test_costly.py, 32 tests, all pass (local, Python 3.13, and on the box, Python 3.9).Open questions
messages = 2rule right for rows written before the dashboard counted the system prompt?Technical notes
awaySummaryEnabled. For the env key it reports every file that sets it.envblock into its own env).save-more settingsandapply|revert settingsneed no proxy. A read with no proxy shows "not measured yet".🤖 Generated with Claude Code