Urgent.News

650+ sources. One page. See who else covered it.

Editions

AI

Maximizing the value of your Claude Code sessions

Article URL: https://claude.com/blog/maximizing-the-value-of-your-claude-code-sessions Comments URL: https://news.ycombinator.com/item?id=49300800 Points: 258 # Comments: 138

When using Claude Code for coding tasks, it's essential to understand how costs are calculated and how to optimize token usage. Claude Code is an agentic coding tool that charges based on the number of tokens used. The cost of a token depends on three factors: the model being used, whether the token is an input or output, and if it's cached.

Input tokens are the ones the model reads, such as the system prompt, CLAUDE.md file, user's message, and any files the model has read during the session. Output tokens are the model's responses, including its thinking process and commands it executes. Output tokens are priced at roughly five times the input tokens since the model takes significantly more time to process them.

Claude Code operates in two phases: prefill and decode. During prefill, the model reads the request and context, while during decode, it generates output tokens. The cost of these tokens depends on their position in the conversation. Newly added tokens to the conversation are fully priced, while cached tokens cost only a fraction of the input price (0.1x) when read and up to 2x when written.

To optimize token usage, it's crucial to choose the appropriate model and effort level for the task at hand. A smaller model may suffice for routine work, while a larger model is better suited for complex or ambiguous problems. The /effort command controls the level of thought the model engages in, with options ranging from low (fast but less thorough) to high (more thorough but slower).

Prompt caching is a feature that allows Claude Code to reuse previous conversation history, reducing the cost of processing repeated requests. However, prompt caching can be disrupted if changes are made to the conversation's prefix, such as adding new tool definitions or modifying the system prompt. In such cases, it's more cost-effective to rewind the session to the point before the changes were made rather than compacting the entire conversation, which incurs a cost.

In summary, to maximize the value of Claude Code sessions, consider the following tips:

1. Choose the appropriate model and effort level for your task.

2. Be mindful of the cost implications of prompt caching and avoid disrupting it unnecessarily.

3. Break down complex tasks into smaller, more focused sessions to minimize token usage.

4. Regularly use /rewind to reset the conversation to a desired state and avoid unnecessary costs.

Written by urgent.news from Hacker News Best's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

This story

This is one outlet's version. Read the fullest account.

Read the original at claude.com →

More in AI

More from Friday 14 August →