Anatomy of an Efficient Session
An efficient agentic coding session has three phases:
Phase 1 - Setup (zero or near-zero tokens)
- CLAUDE.md loaded automatically (cached on first message)
- Session scope defined (one task, one area)
- .claudeignore excludes noise directories
Phase 2 - Execution (targeted token use)
- Agent uses Grep + targeted Read (not broad cat)
- Tool calls return minimal, relevant results
- You provide trimmed error messages, not full logs
- No irrelevant topic switches in this session
Phase 3 - Handoff (minimal output)
- Ask for diff not full rewrite
- Review change, confirm correctness
- Start new session for next task
Before You Start
Three things to do before opening Claude Code for a task:
- Define the task boundary - write one sentence: "Fix the email validation bug in UserModel::create() that allows empty strings through." This keeps you from scope-creeping inside the session.
- Identify the relevant files - know which 1-3 files the task touches. Add them to your initial message instead of asking the agent to explore.
- Check your CLAUDE.md - is it up-to-date for this area? Does it point to the right directory/file for this type of task?
# Template for a focused first message:
"Task: [one sentence]
File: [path, lines if known]
Error: [exact error or failing test name]
Constraint: [e.g. must not break existing tests]
Output: [diff / new function / explanation]"
# Example:
"Task: Fix empty-string validation bypass in user email field.
File: app/models/UserModel.php, create() method ~line 45
Error: UserTest::testCreateWithEmptyEmail passes when it should fail
Constraint: do not change the method signature
Output: diff of the changed validation lines only"
During the Session
Rules for staying efficient once a session is running:
- One topic per session - resist the temptation to ask a quick unrelated question mid-session
- Trim before pasting - if you need to paste an error, trim it to 10-20 relevant lines
- Guide the tool calls - if you see the agent about to read a large file, redirect it: "Read only lines 40-80 of that file"
- Verify each step - confirm the output of each change before the agent moves forward, to avoid cascading bad changes that generate more output tokens correcting them
- End decisively - once the task is done, stop. Do not add "while we're here..." requests
Hooks for Automated Context
Claude Code supports hooks - shell commands that run automatically at certain events. Use them to inject focused context without manual effort:
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"command": "echo 'REMINDER: pipe long output to | tail -30'"
}
]
}
],
"PostToolUse": [
{
"matcher": "Edit",
"hooks": [
{
"type": "command",
"command": "php -l \"$CLAUDE_TOOL_OUTPUT_FILE\" 2>&1 | tail -5"
}
]
}
]
}
}
Common hook patterns for token efficiency:
- PreToolUse on Bash - remind the agent to pipe output
- PostToolUse on Edit - auto-run PHP lint on edited files (catches errors immediately, preventing expensive debug loops)
- UserPromptSubmit - auto-prepend git status to every message so the agent always knows what changed
Memory System
The memory system stores facts that persist across sessions and projects. For token efficiency, use it to remember your preferences so you do not have to repeat them:
# Tell Claude Code to remember:
"Remember: always show diffs not full file rewrites"
"Remember: use Grep tool not bash grep"
"Remember: pipe all bash output to | tail -30"
"Remember: I prefer 3-column layouts in all PHP lesson files"
"Remember: no em dash in content, always hyphen"
# These get stored in ~/.claude/projects/[path]/memory/
# and are loaded as context at session start
# Cost: ~500-1000 tokens added to system prompt (cheap vs. repeated corrections)
Daily Workflow Pattern
A professional daily workflow that minimizes token usage while maximizing throughput:
Morning planning (no agent, zero tokens):
1. List today's tasks in a text file
2. Group by feature area (auth, billing, frontend)
3. Order by dependency (models before controllers)
Per-task session:
1. Open new Claude Code session
2. State the task clearly in first message (use template)
3. Let agent work - guide tool calls if needed
4. Review and confirm output
5. Close session
Batch similar tasks:
- All model changes -> one session (shared context valid)
- All test writes -> one session
- All CSS fixes -> one session
(Don't mix concerns - context stays focused)
End-of-day review (one short session):
"Show me a git diff summary of today's changes.
List only files changed, not the full diff."
-> 1-2 messages, ~500 tokens
If you are writing tests for 5 PHP models, do them in one session. The system prompt (cached) stays warm across all 5 calls. Each model test adds minimal new input tokens. You get 5 tasks done for roughly 1.5x the cost of one task - because caching pays for the common context.