CC-102: Workflow Mastery
Listen instead
Overview: What You Will Learn
Knowing what Claude Code is (Module CC-101) is different from knowing how to use it effectively. This module covers the operational workflows that separate casual users from power users: how to switch between planning and implementation, how to run Claude Code without a terminal attached, how to integrate it into CI/CD pipelines, how to manage multi-session work, and how to write prompts that consistently produce the results you want.
These are not theoretical patterns. Every technique in this module comes from real-world usage at scale -- building production applications, maintaining large codebases, and automating repetitive development tasks.
Plan Mode vs. Implementation Mode
Claude Code supports two distinct operational modes that map to how experienced developers actually work: first you think, then you build.
Plan Mode
Plan mode tells Claude Code to analyze, reason, and propose -- but not to write code or make changes. It is a read-only exploration phase where the agent examines your codebase, identifies patterns, and creates a structured plan of action.
# Activate plan mode with the /plan command or by prompting explicitly:
"In plan mode: analyze the current authentication flow and propose
how to add OAuth2 support. Do not make any changes."
Plan mode is powerful because it forces Claude Code to front-load its reasoning. Instead of diving into code changes and discovering edge cases mid-implementation, it maps out the full scope first. The output is a structured plan you can review, refine, and approve before any code is touched.
Use plan mode when:
- Starting a feature that touches multiple files or systems
- Investigating a bug you do not fully understand yet
- Evaluating architectural decisions before committing to them
- Building a shared understanding before handing off to implementation
Implementation Mode
Implementation mode is the default. Claude Code reads, writes, edits, runs commands, and executes changes. Once you have a plan you are satisfied with, switch to implementation:
# After reviewing the plan:
"Good plan. Implement phase 1: the OAuth2 provider abstraction layer.
Write tests as you go."
The key workflow is: plan first, implement in phases, verify between phases. Do not ask Claude Code to "add OAuth2 support" in a single prompt. Break it into plan, then sequential implementation steps with verification between each.
Headless Mode: claude -p
Headless mode runs Claude Code as a non-interactive process. You pass a prompt, it executes, and it returns the result to stdout. No interactive terminal. No approval prompts. This unlocks automation.
# Basic headless usage
claude -p "What testing framework does this project use?"
# Pipe output to a file
claude -p "Generate a migration for adding a 'roles' table" > migration.sql
# Use in shell scripts
RESULT=$(claude -p "Is there a memory leak in src/cache.ts? Answer yes or no.")
if [ "$RESULT" = "yes" ]; then
echo "Memory leak detected, opening issue..."
fi
CI/CD Integration Patterns
Headless mode is the bridge between Claude Code and your CI/CD pipelines. Here are production-tested patterns:
Automated Code Review
# In a GitHub Actions workflow:
- name: AI Code Review
run: |
claude -p "Review the changes in this PR for:
1. Security vulnerabilities
2. Performance regressions
3. Missing error handling
4. Test coverage gaps
Output as a markdown checklist." > review.md
Automated Test Generation
# Generate tests for changed files
CHANGED=$(git diff --name-only main...HEAD -- '*.ts' | grep -v test)
for file in $CHANGED; do
claude -p "Generate comprehensive unit tests for $file.
Follow existing test patterns in this repo.
Output only the test file content." > "${file%.ts}.test.ts"
done
Commit Message Generation
# Generate conventional commit messages
MSG=$(claude -p "Look at the staged git changes and write a
conventional commit message. Format: type(scope): description.
Output only the message, nothing else.")
git commit -m "$MSG"
Multi-Session Workflows
Complex features often span multiple Claude Code sessions. Context does not automatically carry between sessions (each new session starts fresh), so you need strategies for continuity.
The CLAUDE.md Handoff Pattern
Use your project CLAUDE.md to maintain state across sessions. Before ending a session, ask Claude Code to summarize what was done and what remains:
# End of session:
"Summarize what we accomplished and what remains for the OAuth2
implementation. Format it as a status update I can paste into
CLAUDE.md."
# Start of next session:
"Read the CLAUDE.md and continue the OAuth2 implementation
from where we left off. Start with phase 3: token refresh."
The Git Branch Pattern
Each feature branch serves as a natural session boundary. Claude Code can read git history to understand what happened in previous sessions:
# New session on an existing branch:
"Read the git log for the last 10 commits on this branch and
the current diff against main. Then continue implementation."
Git Integration Best Practices
Claude Code has deep git integration, but using it effectively requires understanding a few critical rules.
- Never use
git add .without review. Claude Code will stage specific files by name. If you see it trying to add everything, that is a red flag. - Always create new commits, never amend. If a pre-commit hook fails, the commit did not happen. Amending would modify the previous commit, potentially destroying work.
- Never force push to main/master. Claude Code knows this rule but it bears repeating. If you need to force push a feature branch, be explicit about it.
- Never skip hooks. No
--no-verify, no--no-gpg-sign. If a hook fails, fix the underlying issue. - Review before committing. Always ask Claude Code to show
git statusandgit diffbefore committing. Verify nothing unexpected is staged.
Slash Commands Reference
Claude Code provides built-in slash commands for common operations. These are not prompts -- they are direct commands to the agent runtime.
/help Show available commands and usage information
/clear Clear the conversation history and start fresh
/compact Compress the conversation context to free up token space
/model Switch the active model (e.g., claude-sonnet-4-20250514)
/compact -- Context Window Management
This is the most important slash command to master. Claude Code has a finite context window. Every file read, every tool result, every message you exchange consumes tokens. When the context fills up, the agent's performance degrades -- it loses track of earlier context, repeats itself, or makes contradictory decisions.
/compact tells Claude Code to summarize the conversation so far and replace the full history with a compressed version. Use it proactively:
- After completing a major phase of work
- When you notice Claude Code repeating itself or forgetting earlier context
- Before starting a new task within the same session
- After reading many large files
# Compact with a focus hint:
/compact focus on the auth refactoring progress and remaining tasks
Effective Prompting Strategies
The quality of Claude Code's output is directly proportional to the quality of your input. Here are tested strategies for writing prompts that consistently produce good results.
Be Specific About Constraints
# Weak:
"Add error handling"
# Strong:
"Add error handling to all API route handlers in src/api/v1/.
Use the existing handleApiError utility from src/lib/api/errors.ts.
Every handler must have a try/catch block. Catch Zod validation
errors, authentication errors, and database connection errors
separately. Return appropriate HTTP status codes."
Provide Acceptance Criteria
"Implement the password reset flow. Acceptance criteria:
1. POST /api/auth/forgot-password accepts email, returns 200 always
2. Reset token is SHA-256 hashed before storage
3. Tokens expire after 1 hour
4. POST /api/auth/reset-password validates token, updates password
5. All existing sessions are invalidated after password change
6. Rate limited to 3 requests per email per hour
7. Full test coverage for all paths"
Reference Existing Patterns
"Create the CRUD API routes for the 'projects' resource.
Follow the exact same patterns used in src/api/v1/agents/.
Same authentication, same pagination, same error handling,
same Zod validation approach. Include tests matching the
style in src/__tests__/api/v1/agents/."
Use Iterative Refinement
Do not try to get everything perfect in one prompt. Use a conversation:
# Prompt 1: Establish direction
"Plan the database schema for a multi-tenant SaaS billing system."
# Prompt 2: Refine
"Good structure, but add support for usage-based billing.
Each plan should support metered features with per-unit pricing."
# Prompt 3: Implement
"Implement the schema. Use Drizzle ORM with PostgreSQL.
Generate the migration file."
# Prompt 4: Verify
"Run the migration against the dev database and verify it applies
cleanly. Then generate seed data for testing."
Best Practices Summary
- Plan before you build. Use plan mode for anything that touches more than two files.
- Phase your implementation. Break large tasks into steps. Verify between each step.
- Manage your context window. Use
/compactproactively. Do not wait for degradation. - Automate with headless mode. Any repetitive Claude Code task can become a CI step or shell script.
- Write prompts like specs. Constraints, acceptance criteria, and pattern references produce better results than vague instructions.
- Use git as your safety net. Commit working states frequently. Claude Code creates new commits, never amends unless told to.
- Maintain session continuity. Use CLAUDE.md and git history to bridge multi-session work.
Official Documentation
For the complete CLI reference and advanced usage patterns:
- Claude Code CLI Usage -- Full command-line reference, flags, and headless mode documentation.
- Claude Code Overview -- Architecture and capabilities reference.
- Settings and Configuration -- Permission configuration for CI/CD environments.