---
title: "How do I cut the tokens my coding agent burns per turn?"
description: "A turn's input tokens are the context the agent carries. Cut them with a code search tool that returns chunks instead of files, and fewer tool definitions."
last_updated: 2026-11-05
doc_version: "2026-11-05"
canonical: https://cocoindex.io/answers/cut-coding-agent-tokens/
---

# How do I cut the tokens my coding agent burns per turn?

A turn's input tokens are the context the agent carries: the files it read, tool output and tool definitions. Reduce what enters that context. Give the agent a code search tool that returns the matching chunks instead of whole files, keep the result count low, and disable the MCP servers you do not use.

Checked: 2026-11-05 · Canonical: https://cocoindex.io/answers/cut-coding-agent-tokens/

## 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, `/context` shows what consumes the space ([Manage costs](https://code.claude.com/docs/en/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`](https://github.com/cocoindex-io/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

```bash
pipx install 'cocoindex-code[full]'
# or with uv:
uv tool install --upgrade 'cocoindex-code[full]'

cd your-repo
ccc index
```

```bash
# 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:

```json
{
  "mcpServers": {
    "cocoindex-code": {
      "command": "ccc",
      "args": ["mcp"]
    }
  }
}
```

## Other cuts that do not need an index

These come from Claude Code's [cost guide](https://code.claude.com/docs/en/costs).

- **Unused MCP servers.** Run `/mcp` to 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 `ccc` skill follows that route: the agent runs `ccc search` in 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](https://github.com/cocoindex-io/cocoindex-code/blob/main/EMBEDDINGS.md)).
- **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](https://github.com/oraios/serena) or [CocoIndex Code Plus](https://cocoindex.io/cocoindex-code/) (`ccx`), a separate self-hosted product.

## Sources and further reading

- [cocoindex-code README](https://github.com/cocoindex-io/cocoindex-code): MCP tool reference and search options.
- [Manage costs effectively](https://code.claude.com/docs/en/costs): Claude Code's guide to token usage.

## Related questions

- [Why is my coding agent slow on a large codebase or monorepo?](https://cocoindex.io/answers/coding-agent-slow-large-codebase.md)
- [How do I give Claude Code, Cursor or Codex the whole repo as context?](https://cocoindex.io/answers/whole-repo-context.md)
- [What is the best MCP server for code search?](https://cocoindex.io/answers/best-mcp-server-for-code-search.md)

## Sitemap

- [All answers](https://cocoindex.io/answers.md)
- [Site index (llms.txt)](https://cocoindex.io/llms.txt)
- [Markdown sitemap](https://cocoindex.io/sitemap.md)
- [XML sitemap](https://cocoindex.io/sitemap.xml)
