Skip to main content

Claude Code: Intermediate & Advanced Techniques

AI coding assistants have evolved from simple autocompletion tools into sophisticated development partners. Claude Code represents the next step in this evolution, offering a framework for what can be described as "autonomous programming." It's a tool designed to integrate deeply into your workflow, do jobs what AI coding previously cannot do:

  • Code Understanding & Q&A: Acts as a project expert, explaining how large codebases work, making it invaluable for onboarding new team members.
  • Large-Scale Refactoring: Excels at modifying massive files (e.g., 18,000+ lines) where other AIs fail, thanks to its ability to understand global code relationships.
  • Debugging: Provides step-by-step reasoning to find the root cause of bugs, unlike tools that just offer a fix without context.
  • Complex Feature Generation: Follows an "explore → plan → implement" workflow. It can be prompted to first analyze the problem and create a detailed plan before writing a single line of code.
  • Test-Driven Development (TDD): Can be instructed to write failing tests first, then generate the minimal code required to make them pass, significantly accelerating the TDD cycle.

Let's dive into the techniques that will help you harness this power effectively.

1. Foundational Setup: The Core of Your Workflow

A robust setup is the bedrock of an efficient workflow. Investing time here pays dividends in every subsequent interaction with Claude Code.

  • Project Memory with CLAUDE.md: At the heart of any project is a concise CLAUDE.md file in the root directory. This file acts as the project's short-term memory, containing key architectural principles, coding standards, and testing procedures. To keep this file lean and focused, use imports like @docs/testing.md to reference more detailed documentation. You can quickly add new rules by starting a message with # or edit the memory directly with the /memory command.
  • Monorepo Awareness: Modern development often involves monorepos. To grant Claude access to multiple packages for cross-directory analysis and refactoring, use the --add-dir flag or define additionalDirectories in your .claude/settings.json file. This is crucial for tasks that span multiple parts of your codebase.
  • Keyboard & Terminal Ergonomics: Speed is essential. Master key shortcuts to streamline your interactions. Use Esc Esc to quickly edit your previous message. Enable Shift+Enter for newlines by running /terminal-setup once. For Vim enthusiasts, the /vim command enables familiar Vim-style motions for a more comfortable editing experience.

2. Streamlining Your Day-to-Day Workflow

With a solid foundation, you can introduce practices that reduce friction and boost your daily productivity.

Using the Right Mode

The CLI offers several permission modes to suit different tasks and risk appetites:

  • default: The safest starting point. It prompts you for confirmation before performing potentially risky actions, offering a good balance of safety and speed.
  • acceptEdits: A "live coding" mode that automatically accepts file edits without a prompt. It's ideal for rapid iteration and when you're closely supervising the process.
  • plan: A "safe" mode designed for tasks like code reviews. Claude can analyze and discuss the code but cannot modify any files.
  • bypassPermissions: Skips all permission prompts entirely. Use this mode with extreme caution and only in sandboxed environments where accidental changes have no consequence.

You can set a default mode in .claude/settings.json or specify one for a session with the --permission-mode flag.

Slash Commands & Customization

Repetitive tasks are perfect candidates for automation. Turn your most common prompts into reusable tools by creating custom slash commands. Simply store them as Markdown files with YAML frontmatter in the .claude/commands/ directory.

  • Use allowed-tools in the frontmatter to restrict what a command can do, adding a layer of safety.
  • The ! prefix lets you run shell commands (e.g., !git status -sb) and inject their output directly into your prompt's context.
  • Use $ARGUMENTS to pass parameters to your commands, making them flexible and more powerful.

Resuming and Parallelizing Work

  • claude --continue: Instantly jumps you back into your most recent session.
  • claude --resume: Presents a list of past sessions, letting you pick up exactly where you left off.
  • Git worktrees: For large-scale refactors, use git worktree to create isolated branches. This allows you to run separate Claude sessions in parallel, each with its own context, preventing confusion and collisions.

Output Styles for Collaboration

  • /output-style explanatory: Enriches responses with an "Insights" section, making it perfect for mentoring junior developers or explaining complex changes in a pull request.
  • /output-style learning: Structures responses with TODO(human) placeholders, actively inviting you to collaborate and fill in the gaps.

3. Incorporating Quality & Safety

True autonomy requires guardrails. Integrate quality checks and safety nets directly into your workflow to build with confidence.

Hooks for Guardrails

Hooks are shell commands that automatically run at specific lifecycle events, offering a deterministic way to enforce standards. Configure them in .claude/settings.json.

  • PreToolUse: Run checks before a tool is used. For example, you can block edits to sensitive files or require a corresponding test file to exist before allowing a write operation.
  • PostToolUse: Automate cleanup tasks after a tool is used. This is perfect for running formatters like prettier or gofmt, as well as linters and quick tests after every edit.
  • Notification: Send a desktop alert when Claude requires your input, so you can switch tasks without losing your place.

For example, let Mac notify you once the job is done - code ~/.claude/settings.json

{
"hooks": {
"Stop": [
{
"hooks": [
{
"type": "command",
"command": "say \"job's done!\""
}
]
}
]
}
}

Permissions and Security

Define explicit allow, ask, and deny rules in your settings to manage tool access without constant prompting.

  • Allow: Safe, routine operations like Bash(npm run test:*).
  • Ask: Potentially risky actions you want to approve manually, such as Bash(git push:*).
  • Deny: Critical security rules to prevent catastrophes, such as Read(./.env) or Read(./secrets/**).

Specialist Subagents

For complex projects, you can define project-scoped agents with specific roles, like a code-reviewer, test-runner, or debugger. Each agent is configured with a limited toolset, preventing it from overstepping its purpose. Claude can either delegate tasks to the appropriate agent automatically or you can invoke one explicitly. See this repository for examples.

4. Advanced Workflows & Integrations

Elevate your workflow by integrating visual context and external services, moving beyond basic file access.

Visual Context with Screenshots and Images

A picture is worth a thousand words, especially when debugging UI issues. There are three reliable ways to provide images to Claude Code:

  1. Paste from Clipboard: Take a screenshot to your clipboard and paste it directly into the terminal with Ctrl+V (note: on macOS, this is Ctrl+V, not Cmd+V).
  2. Drag & Drop: Drag an image file (PNG, JPEG, GIF, WebP) from your file explorer directly into the CLI window.
  3. Reference File Path: Simply include the local file path in your prompt, e.g., Analyze this screenshot: /path/to/screenshot.png.

Model Context Protocol (MCP) Integrations

MCP enables Claude to connect to external services like Jira, GitHub, Notion, or Sentry. After adding and authenticating an MCP server, you can reference external resources in your prompts, such as Implement the feature described in JIRA-ENG-4521.

Non-Interactive & CI/CD Use

For automation and scripting, use print mode with the -p flag.

  • Combine it with --output-format json or --output-format stream-json to produce machine-readable output that can be piped to other tools like jq for further processing.
  • Use --max-turns to set a hard limit on interactions, preventing runaway loops in your automated scripts.

5. Cost & Performance Hygiene

Powerful models require mindful usage. Adopt these habits to manage your spend and optimize performance.

  • Watch Spend: Use the /cost command at any time to get a real-time summary of your current session's cost.
  • Intentional Model Selection: Use the most powerful model, like Opus, for high-level planning, complex reasoning, and initial strategy. Then, switch to a faster, more cost-effective model like Sonnet or Haiku for implementation, testing, and other routine tasks.
  • Status Line: A popular community tip is to add a custom status line to your terminal that displays live cost and other useful information, such as the current Git branch. The ccusage tool is a common choice for this.

6. Starter Pack: A Ready-to-Use Configuration

Here are several copy-pasteable configuration files to get you started quickly.

.claude/settings.json (Project-Shared)

This file establishes project-wide permissions, hooks, and monorepo settings.

{
"defaultMode": "acceptEdits",
"permissions": {
"allow": [
"Read(**/*)",
"Edit(src/**)",
"Bash(npm run test:*)",
"Bash(npm run lint:*)",
"Bash(go test:*)",
"Bash(git status:*)",
"Bash(git diff:*)"
],
"ask": [
"Bash(git push:*)",
"Bash(pnpm publish:*)",
"Bash(npm publish:*)"
],
"deny": [
"Read(./.env)",
"Read(./.env.*)",
"Read(./secrets/**)"
],
"additionalDirectories": ["../apps", "../packages", "../services"]
},
"hooks": {
"PreToolUse": [
{
"matcher": "Edit|MultiEdit|Write",
"hooks": [
{
"type": "command",
"command": "python3 - <<'PY'\nimport json,sys\np=json.load(sys.stdin).get('tool_input',{}).get('file_path','')\nblock=['.env','/secrets/','.git/']\nsys.exit(2 if any(b in p for b in block) else 0)\nPY"
}
]
}
],
"PostToolUse": [
{
"matcher": "Edit|MultiEdit|Write",
"hooks": [
{ "type": "command", "command": "npx prettier --write . --loglevel silent || true" },
{ "type": "command", "command": "npm run -s lint || true" },
{ "type": "command", "command": "npm run -s test || true" }
]
}
],
"Notification": [
{ "matcher": "", "hooks": [ { "type": "command", "command": "command -v terminal-notifier >/dev/null && terminal-notifier -message 'Claude needs input' -title 'Claude Code' || true" } ] }
]
},
"statusLine": { "type": "command", "command": "~/.claude/statusline.sh" }
}

.claude/commands/commit.md

This custom command uses shell output to draft a Conventional Commit message.

---
allowed-tools: Bash(git add:*), Bash(git status:*), Bash(git commit:*)
description: Create a conventional commit from current changes
---

## Context
- Status: !`git status -sb`
- Diff: !`git diff --staged; git diff`

## Task
Write a Conventional Commit subject (<= 72 chars) and a concise body.
Call out BREAKING CHANGE if needed. Stage relevant files and commit.

.claude/agents/code-reviewer.md

An agent definition for a specialist code reviewer.

---
name: code-reviewer
description: Senior review with focus on correctness, security, tests, readability, performance.
tools: Read, Grep, Glob, Bash
---

Return a checklist grouped by **Critical**, **Warnings**, and **Suggestions**.
Propose minimal patches where possible. Include test guidance for each critical item.

CLAUDE.md (Memory)

A sample memory file defining working style, quality standards, and key project documents.

# Working style
- Start in **Plan mode**; outline approach, tests, and risks. Wait for approval.
- Execute in **small, reversible steps**; propose staged commits with diffs.
- Place generated docs in `docs/ai/`. Avoid ad-hoc files elsewhere.

# Code quality
- Prefer pure functions and dependency injection.
- JS/TS: strict TS, eslint + prettier; tests via vitest/jest.
- Go: table-driven tests; `gofmt`/`golangci-lint`.
- Security: never read `.env*` or `./secrets/**`; do not write tokens to disk.

# Project map
@README.md
@docs/architecture.md
@docs/testing.md

7. Troubleshooting and Final Thoughts

  • Image Paste Issues: If pasting from the clipboard doesn't work (a common issue in some Linux terminals), fall back to the reliable drag-and-drop or file path methods.
  • Over-Eager Edits: Avoid the bypassPermissions(started by claude --dangerously-skip-permissions) mode in your daily workflow. A better approach is to use acceptEdits combined with well-defined allow/ask/deny rules. Always review diffs before merging.
  • Memory Bloat: If you notice Claude starting to miss instructions, your CLAUDE.md may have grown too large. Shorten it by moving details into imported doc files. You can also restate key rules during a session to bring them back into focus, or use the /compact command to clean up session history.

Claude Code is more than just a code generator; it's a platform for building a highly effective, AI-augmented development process. By moving beyond basic prompts and adopting these intermediate and advanced techniques, you can establish a workflow that is faster, safer, and more collaborative. Experiment with these features, tailor them to your projects, and discover a new paradigm of software development.

Want to keep learning more?