Contents
  1. 1. The Core Misconception: Terminal Outputs Share Context
  2. 2. High-Risk Blacklist vs. Safe Command Whitelist
  3. 🔴 High-Risk Command Blacklist (Never run directly in agent sessions)
  4. 🟢 Safe Command Whitelist (Targeted, minimal overhead)
  5. 3. Beyond Token Waste: Multi-Agent State Collisions
  6. 4. The Architectural Solution: Git Worktree Isolation
  7. Understanding Git Worktrees
  8. Recommended Parallel Workflow
  9. 5. Summary

Why Running Multiple Claude Code Sessions Drains 25M Tokens: Git Conflicts and Shared Context Pitfalls

When scaling up full-stack engineering with Claude Code, it is tempting to run parallel terminal sessions:

  • Terminal 1 runs npm run dev for local hot-reloading;
  • Terminal 2 handles on-demand npm run build checks;
  • Terminal 3 executes git log and diff inspections.

At first, this multi-terminal setup feels productive. Two hours later, reality hits: the billing dashboard shows 25 million tokens consumed, depleting an entire month's allowance and adding over $100 to the bill.

25 Million Tokens Consumed in 2 Hours Trace

Worse still, as the context window saturated, the agent experienced amnesia—forgetting previously discussed architecture, re-reading files unnecessarily, and overwriting concurrent branch changes until Git hit merge lockups.

Why does running multiple terminals cause such severe token expansion and state drift? And how can you structurally eliminate these risks?


1. The Core Misconception: Terminal Outputs Share Context

A common assumption among developers new to agentic workflows is: Each terminal tab is an isolated sandbox; only the explicit text I type into the prompt consumes tokens.

This assumption is incorrect.

To maintain awareness of your operating environment, all command outputs, build traces, and compiler errors in active workspaces are piped directly into Claude Code's 200K token context window:

Claude Code Shared Terminal Context Mechanism

When a command like npm run dev continuously streams output inside an agent-monitored workspace, every hot module replacement triggers dozens of lines of timestamped logs.

On every subsequent interaction turn, this accumulated log history is re-ingested and charged as input prompt tokens. This compounding effect is how a two-hour session easily consumes 25 million tokens.


2. High-Risk Blacklist vs. Safe Command Whitelist

Controlling token usage requires a clear separation between commands safe for interactive agent sessions and those that must be redirected.

🔴 High-Risk Command Blacklist (Never run directly in agent sessions)

  1. Long-Running Development Servers: npm run dev, vite, python manage.py runserver. Continuous standard output quickly floods the context.
  2. Verbose Compilers and Progress Bars: npm run build --verbose, webpack --progress. Terminal progress animations generate hundreds of redraw lines, filling memory with unhelpful characters.
  3. Continuous Log Streaming: tail -f logs/app.log, watch -n 1 'ps aux'. Unbounded streams will crash your session context.
  4. Unconstrained Directory Traversals: find / -name "*.ts", ls -laR. Traversing large trees like node_modules can feed tens of thousands of lines into the prompt at once.

🟢 Safe Command Whitelist (Targeted, minimal overhead)

  1. Quiet Output Flags: npm run build --quiet, npm test -- --bail --reporter=dot. Return clean output on success and show details only on failure.
  2. Explicit Line Caps: Replace tail -f with tail -n 50 logs/app.log. Replace git log with git log --oneline -5.
  3. Background Daemon Decoupling (Essential): If a local test server must run alongside the agent, redirect its output away from stdout:
    nohup npm run dev > /tmp/dev-server.log 2>&1 &
    

3. Beyond Token Waste: Multi-Agent State Collisions

An even more critical failure mode occurs when running two Claude Code instances concurrently within the same Git repository root:

For example:

  • Session A is assigned to fix an authentication bug;
  • Session B is assigned to build a user profile view.

Within minutes, state collisions appear:

  1. Branch Switching Clashes: Session A runs git checkout feature/auth-fix, changing files across the workspace. Session B, unaware, detects unexpected file modifications and attempts to re-create missing code.
  2. Index Contention & Overwrites: Both agents stage and commit changes to the same .git/index. Uncoordinated writes result in merge conflicts and clobbered work.

This is a textbook case of workspace entropy breakdown caused by uncoordinated concurrent processes sharing a single mutable working directory.


4. The Architectural Solution: Git Worktree Isolation

To safely parallelize tasks, avoid juggling branches in a single directory. Instead, leverage Git's native isolation feature: Git Worktree.

Single Directory Chaos vs Git Worktree Isolation

Understanding Git Worktrees

Standard Git workflows tie your working tree to one branch at a time via git checkout.

Git Worktrees allow you to attach multiple branches to distinct physical directories simultaneously, all linked to a single underlying object database:

Main Project Root/ (main branch)
  ├── .git/ (central Git database)
  └── src/

worktrees/
  ├── feature-auth/    (tracks feature/auth-fix in an isolated path)
  └── feature-profile/ (tracks feature/user-profile in an isolated path)
  1. Create Isolated Workspaces:

    # Create a distinct workspace for authentication bugfixes
    git worktree add ../my-app-auth -b feature/auth-fix
    
    # Create a distinct workspace for profile feature development
    git worktree add ../my-app-profile -b feature/user-profile
    
  2. Launch Independent Agent Instances:

    • Open a terminal in ../my-app-auth and run Claude Code Session A. Edits and test runs are strictly scoped to this path.
    • Open a terminal in ../my-app-profile and run Claude Code Session B. The two sessions run completely decoupled on the file system level: zero conflicts, zero index locks.
  3. Clean Up After Completion: Once pull requests are merged, safely remove the worktrees:

    git worktree remove ../my-app-auth
    git worktree remove ../my-app-profile
    

5. Summary

Agentic coding tools significantly accelerate individual velocity. However, as projects grow in complexity, sustainable output depends on thoughtful context management and solid engineering discipline:

  1. Isolate streaming output: Never run long-lived daemons directly in an interactive agent shell; use quiet flags and background log redirection.
  2. Use worktrees for concurrent work: When running parallel tasks, create dedicated git worktree instances so each agent operates within a clean, predictable workspace.