fix: reduce Captain token consumption by 3x#99
Merged
Conversation
- stop the tool loop as soon as done() succeeds instead of burning a full-context follow-up generation that returns nothing - reinject ARIA-only page context guarded on page_aria, dropping the unconditional full-HTML block (HTML stays available via context()) - trim runCommand tool description to command names; the explicit slash-request guard already enforces pass-through behavior Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Explorbot Self-RegressionCommit
Attempt details
Session analysis — basic (native): Session AnalysisThe Issues feature exploration confirms the core flows work: creating issues, searching by keyword, filtering by status, filtering by label, and handling empty results. All five tests achieved their stated goals. One test had minor automation trouble clearing a filter after verification, but the primary filtering functionality itself is sound. Coverage
What works
Execution Issues
|
DenysKuchma
approved these changes
Jul 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A Langfuse trace of a single read-only Captain request ("whats on this page") consumed 32,821 tokens across two ~16K-input generations. Diagnosis showed three independent sources of waste:
done()— the SDK loop only stopped onstepCount, so afterdone()resolved the request, the full 16.4K context was re-sent for a generation that produced 1 token (an empty assistant message). 50% of the trace.reinjectContextIfNeededguarded onpage_html(which the initial prompt never contains), so it always fired on the first iteration, adding ~4.5K tokens of raw HTML plus a duplicate copy of the ARIA snapshot the initial prompt had just sent.runCommanddescription inlined the entire/helptext (3,720 chars ≈ 1K tokens per call) even thoughisExplicitSlashRequestprogrammatically restricts the tool to verbatim pass-through of user-typed slash commands.Fix
stopWhen: () => isDonetoinvokeConversation— the loop halts the momentdone()succeeds. A rejecteddone()(missing details) doesn't flipisDone, so retries still happen within the same invocation.reinjectContextIfNeedednow guards onpage_ariaand injects URL/title + ARIA only. HTML remains available on demand via the web-modecontext()tool.runCommanddescription trimmed to a one-line rule plus command names.Impact
For the traced request: one generation instead of two, at ~10K input instead of ~16K — ~10K total vs 32.8K. Savings apply to every Captain roundtrip (no prompt caching on this model tier, so context is repaid in full each step).
Testing
bun test tests/unit/captain-artifacts.test.ts tests/unit/captain-mode.test.ts— 19 passbun test tests/integration/— 63 passbun run formatclean🤖 Generated with Claude Code