Isolation Rules to Save 80% of Session Tokens When Fixing Legacy Code with Claude Code
When a solo developer with under a year of experience attaches Claude Code to a massive legacy codebase, the token budget depletes in under an hour. With no senior developer in the office to ask, and armed only with basic CLI commands, opening the terminal leads to nothing but a continuous stream of credit card charge alerts.
Claude Code does not persist conversation state on the server. The system prompt, the CLAUDE.md project configuration file, accumulated conversation history, and tool call results are bundled into a single payload every turn and sent back to the Anthropic API. In the first 1 or 2 turns right after session start, it stays around 15,000 tokens, but the moment the agent starts exploring and reads build outputs or tens of thousands of lines of logs, the payload balloons up to 80,000 tokens. Beyond 6 to 10 turns, 120,000 to 200,000 tokens fly back and forth every turn. It is a structure where costs compound with every turn.
The cause becomes clearer when looking at Anthropic's official prompt caching pricing. If the same prefix context is maintained, you only pay 10% of the cost compared to base input tokens. On the other hand, if the agent irregularly reads tens of thousands of lines of code, breaking the cache prefix, a cache creation cost 1.25 times higher with a 5-minute TTL is newly applied. This is why just a few searches run up fees that are difficult for a solo developer to handle.
.claudeignore Does Not Work
Many developers create a .claudeignore file in the root directory and feel relieved. To cut straight to the conclusion, such a configuration file does not exist in the official Claude Code CLI engine. The approach of writing "Do not read the logs folder" in CLAUDE.md is simply ignored if the model decides it is necessary.
To physically cut off the agent's file access at the engine level, you must use the permissions.deny setting in the .claude/settings.json file.
First, bundle build outputs and security files together in .claude/settings.json at the project root.