Skip to content

[FEATURE]: Move git/PR instructions out of bash tool description to save ~1.7K tokens per request #21345

@DrDexter6000

Description

@DrDexter6000

Feature hasn't been suggested before.

  • I have verified this feature I'm about to request hasn't been suggested before.

Describe the enhancement you want to request

I was profiling why a fresh OpenCode session starts at ~40K tokens. I downloaded all 16 tool .txt files from packages/opencode/src/tool/ and measured them.

bash.txt is 9,288 characters (~2,654 tokens). But 63% of it has nothing to do with running bash commands. The git commit workflow and PR creation instructions account for 5,874 characters (~1,678 tokens) — those are procedural guides, not bash execution semantics.

Here's the thing: tool descriptions are sent with every single API request and are not cacheable. System prompt text, on the other hand, is cacheable (Anthropic prompt caching, OpenAI cached prefix). So those git/PR instructions are being paid for on every turn, even when the user never asks for a commit or PR.

The fix is straightforward: move the # Committing changes with git and # Creating pull requests sections from bash.txt into the system prompt template. The model still sees the same instructions — just through a cacheable channel instead of a non-cacheable one.

For reference, here's the full breakdown I measured:

  • bash.txt: 9,288 chars (~2,654 tokens) — 63% git/PR instructions
  • task.txt: 3,799 chars (~1,085 tokens)
  • multiedit.txt: 2,406 chars (~687 tokens)
  • edit.txt: 1,369 chars (~391 tokens)
  • apply_patch.txt: 1,092 chars (~312 tokens)
  • read.txt: 1,158 chars (~331 tokens)
  • lsp.txt: 1,040 chars (~297 tokens)
  • websearch.txt: 976 chars (~279 tokens)
  • batch.txt: 998 chars (~285 tokens)
  • codesearch.txt: 802 chars (~229 tokens)
  • webfetch.txt: 750 chars (~214 tokens)
  • question.txt: 657 chars (~188 tokens)
  • grep.txt: 689 chars (~197 tokens)
  • write.txt: 623 chars (~178 tokens)
  • glob.txt: 545 chars (~156 tokens)
  • ls.txt: 314 chars (~90 tokens)

Total: ~26,500 chars (~7,573 tokens) across all built-in tool descriptions.

This is complementary to the MCP lazy loading work in #12520 — that PR addresses dynamic MCP tools, while this addresses the static built-in tool overhead. Related: #11995, #17482, #20922.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions