What a turn pays for
A client sends the conversation to the model again on each turn: the system prompt, the tool definitions, the earlier messages, every file the agent read and every tool result. A file that the agent opened to find one function is counted again on each later turn, until the client compacts the conversation.
Two actions follow from this:
- Keep text that the agent does not need out of the context.
- Find out what is in the context now. In Claude Code,
/contextshows what consumes the space (Manage costs).
Return chunks instead of files
When an agent opens a file to find one function, the whole file enters the context. A code index does the search outside the context window.
cocoindex-code is an open-source (Apache 2.0) code search tool with a ccc CLI and an MCP server. It parses files with Tree-sitter, tries to split them at function and class boundaries, and embeds the chunks. Chunks target about 1,000 characters, which is about 300 tokens.
The agent calls the MCP search tool with a description of what it needs. A default call returns up to 5 chunks, so the code in the result is at most about 1,500 tokens (5 chunks of about 300 tokens), plus file paths, line numbers and scores. A file read costs the full length of the file.
The ccc search CLI, which the skill runs, returns up to 10 results by default. Pass --limit 5 for the same size.
These parameters limit what a call returns:
| MCP parameter | CLI flag | Effect |
|---|---|---|
limit | --limit | Number of results. MCP: 1 to 100, default 5. CLI: default 10. |
offset | --offset | Skips results, so the agent can ask for the next page only when it needs it. |
paths | --path | Path glob such as src/utils/*, to search one part of the repository. |
languages | --lang | Language filter such as python or typescript. |
Install and connect
pipx install 'cocoindex-code[full]'
# or with uv:
uv tool install --upgrade 'cocoindex-code[full]'
cd your-repo
ccc index
# Claude Code: skill (recommended in the README)
npx skills add cocoindex-io/cocoindex-code
# Claude Code: MCP
claude mcp add cocoindex-code -- ccc mcp
# OpenAI Codex CLI
codex mcp add cocoindex-code -- ccc mcp
Cursor and other MCP clients that launch a stdio server take the generic entry. The client must start ccc mcp with the project as its working directory:
{
"mcpServers": {
"cocoindex-code": {
"command": "ccc",
"args": ["mcp"]
}
}
}
Other cuts that do not need an index
These come from Claude Code’s cost guide.
- Unused MCP servers. Run
/mcpto see the configured servers and turn off the ones you do not use. - CLI tools. The guide calls CLI tools more context-efficient than MCP servers. The
cccskill follows that route: the agent runsccc searchin the shell. - Symbol navigation. The guide notes that code intelligence plugins give precise symbol navigation instead of text-based search.
Limits, and when another tool fits better
- Task type. Search saves tokens when the agent would otherwise read files to find code. When the agent has the exact identifier, a regular-expression search for it already returns few lines.
- Savings figure. The saving depends on the repository and the task. Measure on yours: run the same task with and without the search tool, and compare the token usage that your client reports.
- Indexing cost. With the local model the cost is compute time on your machine. With a cloud embedding provider you pay that provider per token (embedding guide).
- Output tokens. Search reduces what the agent reads. It does not change how much the agent writes.
- Callers and references. Questions about callers and references need a symbol tool such as Serena or CocoIndex Code Plus (
ccx), a separate self-hosted product.
Sources and further reading
- cocoindex-code README: MCP tool reference and search options.
- Manage costs effectively: Claude Code’s guide to token usage.