Skip to content

fix: stop forcing autocompact to 50% and stop reconcile overwriting user hooks - #31

Open
1aifanatic wants to merge 1 commit into
scaledown-team:mainfrom
1aifanatic:fix/reconcile-user-config
Open

1aifanatic wants to merge 1 commit into
scaledown-team:mainfrom
1aifanatic:fix/reconcile-user-config

Conversation

@1aifanatic

Copy link
Copy Markdown

Closes #29

Problem

  1. dietcode setup silently wrote CLAUDE_AUTOCOMPACT_PCT_OVERRIDE=50 to ~/.claude/settings.json and the shell rc file. reconcileAll() runs daily from the status line, and it put the key back whenever the user deleted it. On a 1M-context model that means compaction at ~500K tokens rather than Claude Code's default.
  2. reconcileClaude() (and setup's writeHooks()) assigned whole new arrays to hooks.UserPromptSubmit, hooks.PostToolUse, hooks.PreCompact and statusLine. Any user hook on those events was silently deleted, including one placed in the same matcher group as DietCode's (the reporter's setup).

Changes

  • Autocompact is opt-in. Setup writes CLAUDE_AUTOCOMPACT_PCT_OVERRIDE (settings.json and shell rc) only when SCALEDOWN_COMPACT_THRESHOLD is explicitly set, and prints a line when it does. Reconcile never touches the key.
  • New applyClaudeHooks() in src/reconcile.ts, used by both setup and reconcile:
    • removes only DietCode's own commands, never whole matcher groups;
    • keeps user hooks, including ones sharing a group with DietCode's;
    • appends a single DietCode entry per event, so repeated runs stay idempotent;
    • keeps a user-configured statusLine and installs DietCode's only when none exists or the existing one is already DietCode's.
  • A command counts as DietCode's when its path names dietcode/scaledown and one of the hook scripts, or when it exactly matches the command being installed. The second case covers checkouts whose path doesn't name the package.
  • Uninstall uses the same per-command filter, so user hooks that share a group with DietCode's survive it. The broader isOurHookEntry, which matched any group mentioning "dietcode", is removed.
  • The compaction imminent progress hint defaults to 95% when no threshold is configured, instead of warning at 50% when nothing happens there.
  • README and dietcode help text are updated.

Not changed (needs a maintainer decision)

Existing installs keep the "50" that older versions wrote. Reconcile can't tell it apart from a value the user chose, so this PR leaves it in place rather than guess. The README uninstall section now explains where that line comes from. If you'd rather migrate (e.g. remove "50" when _dietcodeVersion ≤ 0.5.0 and the env var is unset), I can add that.

Tests

New src/reconcile.test.ts (10 tests):

  • user hooks in shared and separate groups survive reconcile, and DietCode's entry isn't duplicated across runs;
  • a user statusLine is kept, while DietCode's own statusLine path gets refreshed;
  • the autocompact key is not re-added after the user removed it, and a user-chosen value is untouched;
  • a user who never ran setup is left alone;
  • uninstall removes only DietCode's commands from shared groups.

The test mocks os.homedir(), because jest's ESM sandbox doesn't propagate process.env.HOME to it (see note below).

node --experimental-vm-modules node_modules/jest/bin/jest.js src/reconcile.test.ts
Tests: 10 passed, 10 total

hooks/user-prompt-submit.test.ts, hooks/post-tool-use.test.ts, src/niah.test.ts: 57 passed.

Note: src/proxy/store.test.ts sandboxes by setting process.env.HOME, which under jest's ESM VM does not change os.homedir(). That test therefore reads and writes the developer's real ~/.scaledown. This is out of scope here, but worth a follow-up.

🤖 Generated with Claude Code

…ser hooks

Setup wrote CLAUDE_AUTOCOMPACT_PCT_OVERRIDE=50 to settings.json and the
shell rc file without asking, and reconcileAll() (run daily from the status
line) re-added it whenever the user removed it. On a 1M-context model that
compacts at ~500K tokens instead of Claude Code's default.

The same reconcile replaced the whole UserPromptSubmit/PostToolUse/
PreCompact arrays and statusLine, silently deleting user hooks on those
events, including user hooks sharing a matcher group with DietCode's.

- Only write CLAUDE_AUTOCOMPACT_PCT_OVERRIDE (settings.json and shell rc)
  when SCALEDOWN_COMPACT_THRESHOLD is explicitly set; reconcile never
  touches it.
- Add applyClaudeHooks(), shared by setup and reconcile: strip only
  DietCode's own hook commands, keep user hooks (even in shared groups),
  append DietCode's entry, and keep a user-configured statusLine.
- Uninstall uses the same per-command filter, so it no longer drops user
  hooks that share a group with DietCode's.
- The "compaction imminent" hint defaults to 95% when no threshold is set.

Closes scaledown-team#29

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant