控制 Claude Code 成本

出处: Keeping Claude Code costs under control

发布: 2026年3月17日

📄 中文摘要

管理 Claude Code 成本的关键在于识别主要成本驱动因素。首先,长的 CLAUDE.md 文件会在每条消息中加载上下文,建议将其控制在 100 行以内,以避免每条消息产生过多的 token 费用。其次,避免不必要地读取大文件,如果只需修改少量行,应明确告知 Claude 关注特定的函数或部分。此外,在大型代码库上进行长时间会话会导致上下文过时,建议更频繁地开始新会话,以保持上下文的相关性和新鲜感。

📄 English Summary

Keeping Claude Code costs under control

Managing Claude Code costs hinges on identifying the main cost drivers. Long CLAUDE.md files load context with every message, so it's advisable to keep them under 100 lines to avoid excessive token costs per message. Additionally, avoid unnecessarily reading large files; if only a few lines need changing, specify the exact function or section for Claude to focus on. Long sessions on large codebases can lead to stale context, so starting fresh sessions more frequently is recommended to maintain relevance and freshness in context.

Powered by Cloudflare Workers + Payload CMS + Claude 3.5

数据源: OpenAI, Google AI, DeepMind, AWS ML Blog, HuggingFace 等