Skip to content

perf: reduce redundant tokens sent per turn for Codex and Claude providers#7

Merged
jwangkun merged 5 commits into
PeakCode-AI:mainfrom
ccbq2010:fix/token-optimization-p0
Jun 13, 2026
Merged

perf: reduce redundant tokens sent per turn for Codex and Claude providers#7
jwangkun merged 5 commits into
PeakCode-AI:mainfrom
ccbq2010:fix/token-optimization-p0

Conversation

@ccbq2010

Copy link
Copy Markdown
Contributor

Summary

  • P0-4: Remove "local" from CLAUDE_SETTING_SOURCES so Claude sessions no longer load CLAUDE.local.md on every session start
  • P0-3: Skip setPermissionMode call when the permission mode hasn't changed between turns (unnecessary SDK round-trip per turn)
  • P0-1 / P1 / P2: Add lastSentTurnParams diff mechanism to CodexAppServerManagercollaborationMode (developer_instructions), approvalPolicy/sandboxPolicy, model, and effort are only sent when they change or on the first turn after a thread open

Background

Codex app-server persists collaborationMode, approvalPolicy, sandboxPolicy, model, and effort across turns on the same thread. PeakCode was re-sending all of these on every turn/start, wasting tokens each turn.

Root cause: interactionMode and runtimeMode in ThreadTurnStartRequestedPayload have Schema.withDecodingDefault, so they are never undefined — all conditional "only send if changed" guards were dead code.

Token savings per turn

Field Default mode Plan mode
collaborationMode / developer_instructions ~504 tokens ~2,255 tokens
approvalPolicy + sandboxPolicy ~19 tokens ~19 tokens
model + effort ~10 tokens ~10 tokens

Changes

  • apps/server/src/codexAppServerManager.tsCodexLastSentTurnParams type + lastSentTurnParams field on context; reset on thread/start / thread/resume; diff in sendTurn
  • apps/server/src/codexAppServerManager.test.ts — 4 new deduplication tests
  • apps/server/src/provider/Layers/ClaudeAdapter.tslastSentPermissionMode field on context; conditional setPermissionMode; remove "local" from CLAUDE_SETTING_SOURCES
  • apps/server/src/provider/Layers/ClaudeAdapter.test.ts — update 2 test assertions for new settingSources value

Test plan

  • First turn after thread open sends all fields (collaborationMode, approvalPolicy, sandboxPolicy, model, effort)
  • Subsequent turns with unchanged params omit all deduped fields
  • interactionMode change re-sends collaborationMode with correct mode
  • runtimeMode change re-sends approvalPolicy / sandboxPolicy
  • bun fmt && bun lint && bun typecheck all pass

@github-actions github-actions Bot added size:L vouch:unvouched PR author is not yet trusted in the VOUCHED list. labels Jun 11, 2026
@jwangkun jwangkun merged commit 358897b into PeakCode-AI:main Jun 13, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants