Model selection

Switch models with /model based on task complexity

Task Model
Reading files, boilerplate, quick edits Haiku 4.5 (cheapest)
General development Sonnet 4.6 (balanced)
Complex reasoning, architecture Opus (only when needed)

Context management

Command When to use
/compact Session is long — preserves context, reduces tokens
/clear Switching to a completely different task

Start a new conversation for each distinct task. Avoid long mega-sessions.


CLAUDE.md

Keep under 200 lines. Adherence drops and token cost rises beyond that.

Include:

  • Build/test commands
  • Project architecture and file layout
  • Coding conventions and naming patterns
  • Anything Claude needs in every session

Leave out:

  • Multi-step procedures → use Skills instead
  • Instructions scoped to one subdirectory → use a subdirectory CLAUDE.md
  • Task-specific steps → put those in the conversation

Load order (each overrides the last):

  1. ~/.claude/CLAUDE.md — user-level
  2. ./CLAUDE.md — project root
  3. subdir/CLAUDE.md — lazy-loaded per directory, no startup cost
  4. ./CLAUDE.local.md — gitignored, personal overrides

HTML comments (<!-- ... -->) are stripped before context injection — use them for maintainer notes without paying token cost.


Scaling CLAUDE.md past 200 lines

Split into .claude/rules/ with path-scoped files

---
paths:
  - "glob/pattern/**"
  - "another/pattern/*.ext"
---
# Rules here

Rules with paths load only when Claude touches a matching file. Rules without paths load at startup.

.claude/rules/testing.md

---
paths:
  - "**/*.test.js"
  - "**/*.spec.js"
---

- Use describe/it blocks
- Mock external HTTP calls

.claude/rules/styling.md

---
paths:
  - "_sass/**/*.scss"
  - "assets/css/**/*.scss"
---

- Variables live in `_sass/minima/`
- Follow existing Monokai color variable naming
- No inline styles; use existing variables

.claude/rules/content.md

---
paths:
  - "_dev_notes/**/*.md"
  - "_musings/**/*.md"
  - "_posts/**/*.md"
---

- Frontmatter must include layout, title, categories, tags
- Code blocks use fenced syntax with a language tag
- References section goes at the bottom after a --- divider

Path rule notes:

  • paths is the only supported frontmatter field — no priority, when, or conditionals
  • Brace expansion works: **/*.{ts,tsx} matches both extensions
  • Files in .claude/rules/ without paths load at startup, same as CLAUDE.md
  • Subdirectories inside .claude/rules/ are discovered automatically

Targeted prompts

  • Give Claude the specific file path or symbol name upfront — avoid “look around and figure it out”
  • Read partial files when possible: “read lines 50–100 of X” instead of the whole file
  • Batch related requests into one message instead of multiple back-and-forth turns

Explore subagent

Use the Explore subagent for codebase research — results stay out of the main context window. Only the answer returns, not intermediate tool output.


Reduce permission prompts

Run /fewer-permission-prompts — analyzes the session and adds common read-only operations to the allowlist.


Auto-memory

Memory persists project preferences across sessions — no need to re-explain context each time.


Filter command output before it hits context

npm test 2>&1 | tail -30                                      # only last 30 lines
npm test 2>&1 | grep -E "FAIL|PASS|Error"                     # only relevant lines
bundle exec jekyll build 2>&1 | grep -v "^  Generating"       # strip noisy lines

Whatever gets piped is what lands in context — filter at the shell level.


Background commands

Use run_in_background for slow builds or long test suites. The process starts and returns a notification on completion. Streaming output never enters the context window; only the final result does.


Subagents for multi-step tasks

Describe the full task end-to-end — Claude delegates internally and returns only the final summary. No intermediate bash output, file reads, or retries appear in the main context.

"Run the tests, fix any failures, and report back with what changed."
"Explore the _dev_notes/ folder and tell me which files are missing a References section."

To be explicit: "Use an agent to do this so it doesn't flood the main context."


References: