feat(claude-code): configurable SessionStart and post-compaction context byte budget

Open Beginner friendly
#2,416 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
74/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
bash, markdown, shell
Domain
tooling

Research direction

Start with plugin/claude-code/scripts/session-start.sh around lines 141-145 and plugin/claude-code/scripts/post-compaction.sh line 30, where max_bytes=16384 is passed to the context endpoint; check the endpoint and mem_context to confirm the accepted upper bound. Add a single ENGRAM_CONTEXT_MAX_BYTES read in both hooks: default to 16384 when unset, fall back on non-positive/non-integer values, clamp at the endpoint limit, and leave compact=1 and pinned=20 untouched. Run the existing hook/endpoint tests with a 6144-byte override and invalid values, then document the variable and its survival across plugin upgrades and gentle-ai sync.

Written by the indexing model from the issue text.

Description

status:needs-review type:feature
Existing Issue Search
  • I searched existing issues and will add evidence to a canonical tracker when applicable.

No existing tracker for the Claude Code hook context budget (searched max_bytes, context budget). Related but distinct: #1373 (Pi mem_context options, closed), #1075 (mem_context budget follow-ups, closed).

🔍 Observed Consequence

Both Claude Code hooks request a literal max_bytes=16384 from the context endpoint, so every session start and every compaction injects up to 16 KiB of memory context, and users cannot lower it:

The endpoint and mem_context already accept per-call byte budgets, but the hooks expose no override. Editing the installed plugin scripts is overwritten by plugin updates and gentle-ai sync.

💡 Desired Outcome

One documented environment override honored by both hooks (suggested name: ENGRAM_CONTEXT_MAX_BYTES):

  • Unset keeps today's default of 16384.
  • A valid positive integer (e.g. 6144, set through Claude Code's settings env) is passed as max_bytes; invalid values fall back to the default; values above the endpoint's upper bound are clamped.
  • compact=1 and pinned=20 stay unchanged.
  • Docs state that it bounds the context field only, not the protocol or hook wrapper text, and how it survives plugin upgrades and gentle-ai sync.

Acceptance: both hooks honor a valid override and keep the default when unset; tests cover a 6144-byte override, invalid values, the upper bound, and UTF-8-safe truncation through the existing endpoint. Proactive saves, conflict judgments, passive capture and tools are unaffected.

📦 Affected Area

Other

Release Context

engram v3.7.2 (Claude Code plugin hooks), managed by gentle-ai v4.6.0

🔄 Workarounds and Constraints

None that survive updates; patching the plugin scripts is overwritten.

📎 Additional Context

Related, not requested here: ENGRAM_NUDGE_COOLDOWN_SECS already debounces repeat save reminders, but the first reminder's 15-minute threshold and wording are hard-coded (user-prompt-submit.sh#L554-L565).

Dominant language
Go
Stars
7.1k
Forks
729
Avg merge
1h 35m
Merged PRs (30d)
154

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Gentleman-Programming/engram

All issues in Gentleman-Programming/engram

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.