To maximize the efficiency of Claude Code sessions and minimize token costs, developers should focus on managing the conversation context and leveraging prompt caching. Claude Code uses prompt caching to reduce costs, allowing cached input tokens to be read at 0.1x the standard input price, whereas output tokens (including thinking and tool calls) cost approximately 5x more. To maintain high cache hit rates, users should avoid switching models or effort levels mid-conversation, as these changes invalidate the cache and trigger full-price prefilling for the entire history. Users can optimize sessions by using /clear between distinct tasks to prevent irrelevant context from inflating costs, and /compact or /rewind to prune long histories. Using @-mentions for files is more efficient than providing paths, as it avoids extra Read tool calls. For noisy command outputs, developers should utilize quiet flags or specific test runners to prevent thousands of lines of text from becoming permanent, expensive context. Finally, delegating high-output tasks like log analysis to subagents can isolate large amounts of data to a separate context window, ensuring only the relevant summary is returned to the main session.
Read original
hackernews