MCPcopy Create free account
hub / github.com/codeaashu/claude-code / truncateToTokens

Function truncateToTokens

src/services/compact/compact.ts:1666–1672  ·  view source on GitHub ↗

* Truncate content to roughly maxTokens, keeping the head. roughTokenCountEstimation * uses ~4 chars/token (its default bytesPerToken), so char budget = maxTokens * 4 * minus the marker so the result stays within budget. Marker tells the model it * can Read the full file if needed.

(content: string, maxTokens: number)

Source from the content-addressed store, hash-verified

1664 * can Read the full file if needed.
1665 */
1666function truncateToTokens(content: string, maxTokens: number): string {
1667 if (roughTokenCountEstimation(content) <= maxTokens) {
1668 return content
1669 }
1670 const charBudget = maxTokens * 4 - SKILL_TRUNCATION_MARKER.length
1671 return content.slice(0, charBudget) + SKILL_TRUNCATION_MARKER
1672}
1673
1674function shouldExcludeFromPostCompactRestore(
1675 filename: string,

Callers 1

Calls 1

Tested by

no test coverage detected