Efficiency Hacks
The developer who saves 10 minutes per task does not seem impressive. But across 30 tasks per day, that is 5 hours per week. These efficiency hacks are the small techniques that compound into massive productivity gains.
What You Will Walk Away With
Section titled “What You Will Walk Away With”- Context management techniques that keep sessions lean and fast
- Output format tricks for different workflows
- Shell aliases and functions that reduce keystrokes
- Patterns for avoiding common time sinks
Context Management
Section titled “Context Management”Clear Between Unrelated Tasks
Section titled “Clear Between Unrelated Tasks”The single biggest efficiency win is clearing context when switching tasks:
/rename payment-bug-investigation/clearStale context from a previous task makes every subsequent message more expensive (more tokens processed) and less accurate (Claude uses irrelevant context).
Targeted Compaction
Section titled “Targeted Compaction”When you need to stay in the same session but context is bloated:
/compact Keep: file paths I edited, test results, error traces. Remove: exploratory file reads, discussion about alternatives, my questions.Add Compaction Rules to CLAUDE.md
Section titled “Add Compaction Rules to CLAUDE.md”# Compact instructionsWhen compacting, preserve:- Test results and error output- File paths and code changes made- Key decisions and their rationale
Remove:- Exploratory file reads that did not lead to changes- Verbose command output that has been summarized- Discussion of rejected approachesShell Aliases and Functions
Section titled “Shell Aliases and Functions”Quick Claude Code Shortcuts
Section titled “Quick Claude Code Shortcuts”Add to ~/.zshrc or ~/.bashrc:
# Quick question -- ask Claude without starting a sessionalias cq='claude -p'
# Continue last sessionalias cc='claude -c'
# Review current changesalias cr='git diff | claude -p "Quick review: only flag CRITICAL and HIGH issues."'
# Explain a fileexplain() { claude -p "Explain what $1 does, its key functions, and how it fits into the project."}
# Generate tests for a filegentest() { claude -p "Generate comprehensive tests for $1. Follow existing test patterns in this project."}
# Debug an errordebug() { echo "$@" | claude -p "Analyze this error and suggest a fix. Read the relevant source files."}Output Format Tricks
Section titled “Output Format Tricks”JSON for Script Consumption
Section titled “JSON for Script Consumption”When you need to wire Claude into a shell pipeline, ask for free-form text and read .result. Compare the two workflows for the same task:
# Before: prose answer you have to copy out of the terminal by handclaude -p "List all API endpoints with their HTTP method, path, and handler file"
# After: machine-readable text you can pipe into grep, wc, or another commandclaude -p "List all API endpoints with their HTTP method, path, and handler file" \ --output-format json | jq -r '.result'Use plain --output-format json (read from .result) when you want Claude’s natural-language answer in a script; reach for --json-schema (next section) only when you need the answer parsed into specific fields.
Structured Output with JSON Schema
Section titled “Structured Output with JSON Schema”For guaranteed output structure, pair --json-schema with --output-format json. The schema-conformant result lands in the top-level structured_output field (alongside session metadata), so pipe to .structured_output, not .result:
claude -p "Analyze the test coverage of src/api/" \ --output-format json \ --json-schema '{"type":"object","properties":{"total_files":{"type":"number"},"covered_files":{"type":"number"},"uncovered_files":{"type":"array","items":{"type":"string"}}}}' \ | jq '.structured_output'This is the reliable way to feed Claude’s output into another script: the schema forces shape, and jq '.structured_output' strips the wrapper so you get clean JSON. Without --output-format json, the --json-schema flag is ignored and you get plain text back.
Common Time Sinks and How to Avoid Them
Section titled “Common Time Sinks and How to Avoid Them””Let Me Read Everything First”
Section titled “”Let Me Read Everything First””Claude’s default behavior is to read many files before acting. For focused tasks, constrain the scope:
Fix the null pointer in src/api/users.ts line 42.Only read src/api/users.ts and its direct imports.Do not explore other files.“Let Me Summarize What I Did”
Section titled ““Let Me Summarize What I Did””Claude often spends tokens summarizing changes after making them. Add to your CLAUDE.md:
After making changes, do not provide a summary unless I ask for one.Instead, just show the git diff of what changed.Running Full Test Suites After Every Change
Section titled “Running Full Test Suites After Every Change”# In CLAUDE.mdWhen running tests after a change, run only the tests related to the modified file.Use: npx jest [file] --no-coverageOnly run the full test suite when I ask for it or before committing.Reading Package-Lock or Generated Files
Section titled “Reading Package-Lock or Generated Files”# In CLAUDE.mdNever read these files:- package-lock.json- yarn.lock- any file in dist/ or build/- any file in node_modules/- any .map fileQuick Wins
Section titled “Quick Wins”Use --add-dir for Multi-Repo Work
Section titled “Use --add-dir for Multi-Repo Work”# Work on a frontend app with access to the shared libraryclaude --add-dir ../shared-componentsFallback Model for Overloaded Periods
Section titled “Fallback Model for Overloaded Periods”claude -p "Quick task" --fallback-model sonnetIf the default model (Opus 4.8) is overloaded, this automatically falls back to Sonnet 4.6 instead of failing the run — invaluable inside cron jobs and CI pipelines where an unattended error means a missed deploy. The flag is print-mode only.
PR-Linked Sessions
Section titled “PR-Linked Sessions”# Resume the local session that was linked when you ran gh pr createclaude --from-pr 123This resumes the local session that was automatically linked to the PR when you created it with gh pr create, so you can pick that work back up to address review comments. It does not fetch the PR contents itself — it only works for a PR whose originating session still exists on this machine.
When This Breaks
Section titled “When This Breaks”Aliases conflict with other tools: Check for name conflicts with which cq before adding aliases. Choose unique names that do not shadow existing commands.
Context gets cleared accidentally: Get in the habit of using /rename before /clear. Sessions persist even after clearing, so you can resume them later.
Efficiency rules in CLAUDE.md are too restrictive: If Claude seems unable to explore when needed, use “ignore efficiency rules for this task” to override temporarily. The rules are guidance, not hard blocks.
What is Next
Section titled “What is Next”- Terminal Mastery — Deeper terminal optimization
- Monitoring and Costs — Track the impact of your efficiency improvements
- Setup and Configuration Tips — More configuration optimizations