Harness Engineering 6 months ahead, in a few hours.

Module 07 — Optimization & pro workflow

Updated

In this module

You'll learn to keep your context useful and cheap with RTK, /clear and /compact, then to delegate to subagents. You'll also run Claude Code from scripts and CI/CD with claude -p, and manage your sessions, worktrees and scheduled tasks.

7.1 — Context window and tokens: see what your session uses

The context window holds everything Claude can see during a session. That includes your messages, the files it read, command output and Claude's own replies. All of it is counted in tokens.

On every turn, Claude Code sends the whole conversation back to the model. A session that has piled up three unrelated tasks rereads all three on every message of the fourth. You pay for that unused context in tokens, whether you're billed by usage or capped by your plan.

Most current models have a one-million-token window. Claude Code also summarizes the history on its own when the window gets close to its limit. So you're unlikely to run out of room. What matters is cost and accuracy. A context focused on the current task costs less and gets you better answers.

The prompt cache lowers that cost. While it's warm, the start of the conversation, already sent, is billed at a reduced rate. It lasts about an hour on a subscription, and five minutes with an API key. When you come back to a long session after it expires, the whole history is reread at full price.

Three commands show you where you stand:

Command What it shows
/context What fills the window, category by category, with suggestions to free up space
/usage The session's usage and your plan limits (/cost and /stats open the same screen)
/statusline Sets up the status line, which can show how full the context is at all times

/context also lists the CLAUDE.md files and the auto memory loaded at startup. On a subscription, /usage breaks your usage down by skill, subagent, plugin and MCP server. Start with that screen when a session feels expensive.

For the status line, describe what you want to /statusline:

Claude Code
/statusline show the model and the percentage of context used

Claude Code then writes a script that reads the context_window.used_percentage field. You see the percentage under your input box without typing anything.

The rest of the module follows this order. Sections 7.2 to 7.6 keep your session light. Sections 7.7 to 7.9 run Claude Code without you, from a script, in CI/CD or in parallel. Sections 7.10 and 7.11 cover sessions, rewinding and scheduled tasks.

Key takeaways

• Claude Code sends the whole conversation on every turn, so a cluttered context is paid for on every message.

• With a one-million-token window and automatic compaction, you rarely run out of room.

• A context focused on a single task costs less and gets you better answers.

• /context shows what fills the window, and /usage shows what the session uses.

In this module

  1. 7.1 — Context window and tokens: see what your session uses Available
  2. 7.2 — RTK: cut the tokens used by command output in Claude Code
  3. 7.3 — /clear: start from an empty context between two tasks
  4. 7.4 — /compact and auto-compaction: summarize a long session
  5. 7.5 — Explore, plan, code, verify: the method for a long task
  6. 7.6 — Subagents: delegate a search or a parallel task
  7. 7.7 — Headless mode: run Claude Code from a script with claude -p
  8. 7.8 — CI/CD: Claude Code in GitHub Actions and your pipelines
  9. 7.9 — Fan-out and worktrees: run several sessions in parallel
  10. 7.10 — Sessions: name, resume and go back with /rewind
  11. 7.11 — Scheduled tasks, /loop, /goal and Remote Control

Locked content

Unlock the full course to access this module.

€89 excl. VAT

€106.80 incl. VAT for EU customers · One-time payment

Already purchased? Recover access

Go further