Skip to content

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.

  • 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

The single biggest efficiency win is clearing context when switching tasks:

/rename payment-bug-investigation
/clear

Stale context from a previous task makes every subsequent message more expensive (more tokens processed) and less accurate (Claude uses irrelevant context).

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.
# Compact instructions
When 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 approaches

Add to ~/.zshrc or ~/.bashrc:

Terminal window
# Quick question -- ask Claude without starting a session
alias cq='claude -p'
# Continue last session
alias cc='claude -c'
# Review current changes
alias cr='git diff | claude -p "Quick review: only flag CRITICAL and HIGH issues."'
# Explain a file
explain() {
claude -p "Explain what $1 does, its key functions, and how it fits into the project."
}
# Generate tests for a file
gentest() {
claude -p "Generate comprehensive tests for $1. Follow existing test patterns in this project."
}
# Debug an error
debug() {
echo "$@" | claude -p "Analyze this error and suggest a fix. Read the relevant source files."
}

When you need structured output:

Terminal window
claude -p "List all API endpoints with their HTTP method, path, and handler file" \
--output-format json | jq '.result'

For guaranteed output structure:

Terminal window
claude -p "Analyze the test coverage of src/api/" \
--json-schema '{"type":"object","properties":{"total_files":{"type":"number"},"covered_files":{"type":"number"},"uncovered_files":{"type":"array","items":{"type":"string"}}}}'

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.

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.md
When running tests after a change, run only the tests related to the modified file.
Use: npx jest [file] --no-coverage
Only run the full test suite when I ask for it or before committing.
# In CLAUDE.md
Never read these files:
- package-lock.json
- yarn.lock
- any file in dist/ or build/
- any file in node_modules/
- any .map file
Terminal window
# Work on a frontend app with access to the shared library
claude --add-dir ../shared-components
Terminal window
claude -p "Quick task" --fallback-model sonnet

If Opus is overloaded, this automatically falls back to Sonnet instead of failing.

Terminal window
# Create a session linked to a PR
claude --from-pr 123

This loads context from the PR, making it easy to address review comments.

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.