The Deska blog
Claude Code: How to Cut Token Usage by 40% Using Better Context Tips
Learn specific strategies for Claude Code token usage optimization to reduce API costs while maintaining high quality code generations and terminal output.
· 10 min read
Managing Claude Code token usage optimization is becoming a critical skill for developers who want to leverage high performance AI agents without incurring massive API bills. As a terminal based tool that interacts directly with your filesystem and execution environment, Claude Code can quickly consume tokens by ingesting large amounts of file context or terminal output. By refining how you provide context and how you structure your workspace, you can significantly reduce overhead while improving the accuracy of the agent responses.
Understanding the Token Cost of Context
Every time you initiate a command in a tool like Claude Code, the system evaluates the state of your project to provide a relevant answer. This process involves sending file contents, recent command history, and directory structures to the model. If you are working in a large monorepo or a project with many large log files, the default behavior might include thousands of unnecessary tokens in every turn of the conversation.
The primary cost drivers in CLI based agents include:
- Recursive directory listings that explore deep nested folders.
- Large build artifacts or dependency folders like
node_modulesthat are not ignored. - Long terminal outputs from test runners or build logs being piped back to the LLM.
- Excessive historical context from long running sessions.
To mitigate these, you must be intentional about what the agent sees. Instead of letting the agent explore freely, you should use specific flags or structured project files to limit the scope of the search.
Strategies for Reducing Input Tokens
The most effective way to achieve Claude Code token usage optimization is to prune the input before it reaches the API. Most users forget that the LLM pays attention to everything in the current buffer.
Use Ignore Files Aggressively
Just as you use .gitignore to keep your repository clean, you should ensure that Claude Code is not reading binary files, large datasets, or sourcemaps. Check your configuration to see if you can exclude specific paths that the agent never needs to touch. This prevents the tool from indexing files that contribute nothing to code generation but add significantly to the prompt size.
Targeted File Injection
Instead of asking a general question that forces the agent to search your entire project, identify the specific files relevant to your task. Explicitly mentioning files in your prompt helps the agent focus. If you know the bug is in auth.ts, start your session by referencing only that file. This limits the "context window" usage and ensures the model does not get distracted by unrelated logic in other modules.
Session Management
Long sessions naturally accumulate tokens. Each new message includes the history of the previous messages to maintain context. For distinct tasks, it is often cheaper to start a new session. If you have finished refactoring a component and now want to work on CSS, closing the current thread and starting fresh will wipe the previous code snippets from the active context, saving thousands of tokens over the course of a day.
Using Deska for Context Visibility
When using Claude Code, visibility into what the agent is doing can help you spot token waste. Deska provides an environment where you can run Claude Code alongside other tools in a unified workspace. By placing your terminal in one panel and your file explorer or notes in another, you can better coordinate what information you are feeding into the agent.
In Deska, the canvas allows you to organize multiple coding agents side by side. You can have one terminal running Claude Code with a strict context filter, while another panel displays the documentation or the code editor. This spatial organization helps you keep track of which files are currently "active" in the agent memory.
The Ask Deska feature can also help drive the workspace without burning tokens in your main Claude Code session. You can ask the assistant to open specific terminals or find files, allowing you to prepare the environment before you even start the expensive CLI agent session.
Effective Prompt Engineering for CLI Agents
The way you phrase your instructions determines how much "thinking" the model does and how much code it outputs.
- Be specific about the output format. Asking for "only the changed lines" rather than the whole file can save output tokens.
- Use incremental steps. Instead of asking for a full feature, ask for the interface definition first.
- Limit search depth. When asking the agent to find something, specify a directory rather than the root.
Technical Comparison of Workspace Approaches
Different tools handle context in various ways. Traditional IDE extensions often index the entire project in the background, which might lead to hidden costs if the indexing logic is not efficient. CLI tools like Claude Code give you more direct control but require more manual oversight to keep costs down.
| Feature | CLI Agents (Manual) | IDE Extensions | Deska Workspace |
|---|---|---|---|
| Context Control | High | Low | High |
| Visual Oversight | Minimal | Moderate | High |
| Session Isolation | Manual | Automatic | Panel Based |
| Multi-Agent Use | Sequential | Limited | Side-by-Side |
Deska follows a local-first approach where your files and sessions stay on your machine. This means the overhead of managing these files does not add to your cloud costs. You can manage your data and storage locally and only send what is necessary to the API provider.
FAQ for Token Optimization
How do I check my current token usage in Claude Code?
Most CLI tools provide a summary at the end of a session or via a specific command. You should also monitor your Anthropic dashboard to see real time billing data. Integrating this check into your workflow every few hours helps prevent surprise bills.
Can I limit the number of files Claude Code reads?
Yes, you can use specific flags during startup or create a configuration file that defines the scope of the agent. Restricting the agent to specific subdirectories is the most effective way to ensure it does not ingest your entire codebase.
Does using a GUI like Deska increase token usage?
No, Deska is a workspace that hosts the tools you already use. It does not add extra tokens to your Claude Code sessions. In fact, by using the notes notebook to draft your prompts before sending them, you can refine your instructions to be more token efficient.
Get Started with Efficient Coding
Reducing your API costs does not mean sacrificing the power of AI. By being mindful of your context and using a workspace designed for visibility, you can maintain a high velocity at a fraction of the cost.
You can download the Deska app for Mac, Windows, and Linux to start organizing your AI agents more effectively. Whether you are using the mobile app to monitor your long running builds or managing your API keys for a lifetime tier, having a dedicated workspace is the first step toward professional AI integration.