Back to handbooks index

Claude Code Practitioner's Handbook

A field-tested reference covering every major feature β€” modes, hooks, agents, SDK, MCP, and multi-model workflows.

Claude Code v2.1+ Opus 4.6 Β· Sonnet 4.6 Β· Haiku 4.5 Ollama / GLM4 / Qwen3.5 March 2026

Install & Setup

# Requires Node.js 18+
npm install -g @anthropic-ai/claude-code
claude --version

# Auth (browser OAuth or API key)
claude              # opens browser auth
export ANTHROPIC_API_KEY=sk-ant-...
claude --api-key $ANTHROPIC_API_KEY

# Update
claude update       # or: npm update -g @anthropic-ai/claude-code

# Run diagnostics
claude /doctor
πŸ’‘
WSL2 tip: On your RTX 5070 / WSL2 setup, ensure CUDA_VISIBLE_DEVICES is set before launching Claude Code when you need it to invoke local GPU workloads via Bash hooks or MCP tools.

IDE Integrations

SurfaceHow to activateDocs
VS CodeInstall Claude Code extension, Ctrl+Shift+C↗ IDE docs
JetBrainsPlugin marketplace β†’ "Claude Code"β†— IDE docs
Terminalclaude in any directory↗ CLI ref
GitHub Actionsuses: anthropic/claude-code-action↗ GHA docs
Web / Desktopclaude.ai → Claude Code tab↗ claude.ai

Model Selection

Switch at any time with /model. Claude Code 2.1+ supports four model slots, including Plan-mode Opus.

ModelBest forSpeedCost
Opus 4.6 Complex architecture, multi-file refactors, research, plan mode on massive codebases (1M context) Slow $$$
Sonnet 4.6 Default daily driver β€” strong balance of capability and speed. Fine-tuning pipeline code, CUDA kernels Fast $$
Haiku 4.5 Explore subagents, CI lint checks, quick file scans, cost-sensitive batch tasks Fastest $
Opus (plan) +
Sonnet (exec)
Option 4 in /model β€” Opus thinks, Sonnet executes. Ideal for large refactors Mixed $$$
# Switch models interactively
/model

# CLI flags
claude --model claude-opus-4-6
claude --model claude-sonnet-4-6
claude --model claude-haiku-4-5-20251001

# Ollama / local model (via OPENAI_BASE_URL compatibility)
ANTHROPIC_BASE_URL=http://localhost:11434/v1 \
ANTHROPIC_API_KEY=ollama \
claude --model qwen3.5:9b

Ollama / GLM4 / Qwen3.5 Local Routing

Claude Code can route to any OpenAI-compatible endpoint. Useful for Arthavidya distillation runs where you want the teacher (Qwen3.5-9B) reviewed locally before pushing to cloud.

# ~/.claude/settings.json β€” environment overrides
{
  "env": {
    "ANTHROPIC_BASE_URL": "http://localhost:11434/v1",
    "ANTHROPIC_API_KEY": "ollama"
  }
}
⚠
Capability gap: Local models (GLM4, Qwen3.5-4B) don't support extended thinking tokens or native tool use. Hooks and subagents that depend on structured JSON tool calls will degrade β€” use them for review/summarization tasks, not orchestration.

All Modes β€” When to Use What

Plan Mode Shift+TabΓ—2  |  /plan

Use when: starting a non-trivial feature, refactor, or architecture change. Claude reads, analyzes, and produces a structured plan β€” no file writes until you approve.

In plan mode Claude only has access to read-only tools: Read, LS, Glob, Grep, Task, TodoRead/Write, WebFetch, WebSearch, NotebookRead. It automatically spawns an Explore subagent to scan the repo so main context stays clean.

Spec-first Safe exploration Token-efficient Human checkpoint
# Activate plan mode then share a spec
Shift+Tab  Shift+Tab
> "Read CLAUDE.md and plan how to add curriculum-based LoRA training to the pipeline"

# Or via command
/plan

# Custom plan command β€” .claude/commands/plan.md
# Runs plan subagent with your project-specific checklist
Extended Thinking (Think Modes) Alt+T  |  Tab toggle  |  "think / think harder / ultrathink"

Use when: debugging gnarly issues, complex algorithm design, security review, architecture trade-offs. Opus 4.6 has thinking enabled by default.

Trigger phraseEffort levelWhen to use
thinkLowSimple reasoning, quick decision
think harder / think moreMediumMulti-step problems, debugging
think a lot / deep thinkHighArchitecture, complex refactor
ultrathinkMaximumHard research, security audit, novel algorithm
Billed by thinking tokens Opus default-on Alt+T toggle
⚠
Cost note: "Think harder" allocates more thinking budget tokens β€” not just a hint. Phrases like "think harder" in prompts without the toggle do not expand budget. Use the keyboard toggle or explicit trigger words. Local models (Ollama) do not support thinking tokens.
Fast Mode /fast  |  "fastMode": true in settings

Use when: running Opus 4.6 for interactive work where you need 2.5Γ— faster responses and accept higher cost-per-token. Available since v2.1.36.

Not useful for local Ollama models β€” latency is bound by hardware, not API inference.

Auto-Accept / YOLO Mode Shift+Tab (from plan)  |  --yes

Use when: you fully trust the plan and want fully autonomous execution β€” Claude runs tool calls without per-step confirmation. Only use on branches, never on main.

Print / Pipe Mode claude -p "..."  |  echo "..." | claude -p

Use when: integrating Claude Code into CI scripts, shell pipelines, GitHub Actions, or MLOps automation. Non-interactive, stdout-only output.

# Print mode in CI
claude -p "Review this diff for security issues" --max-turns 3 < diff.patch

# Budget-capped automation
claude -p "run the test suite and fix failures" --max-budget-usd 2.00 --model haiku

CLAUDE.md β€” Project Memory

CLAUDE.md is the agent's "constitution" β€” loaded at session start. Place at project root, in subdirectories (loaded when Claude touches files there), or globally at ~/.claude/CLAUDE.md.

~/.claude/CLAUDE.md
β†’
<root>/CLAUDE.md
β†’
src/CLAUDE.md
β†’
.claude/rules/ (path-specific)
# CLAUDE.md example β€” Arthavidya project
## Project: Arthavidya Finance LLM

### Architecture
Teacher: Qwen3.5-9B (RTX 5070, 12GB VRAM)
Student: Qwen3.5-4B via curriculum LoRA (4 tiers)
Training stack: HuggingFace PEFT + TRL + Unsloth
Experiment tracking: W&B (project: arthavidya)

### Coding standards
- Python 3.11+, type hints required
- Config-driven: no magic numbers in code, use YAML configs
- All training scripts: pause-and-resume checkpoints mandatory
- Tests: pytest + pytest-torch
- Never hardcode API keys; use .env + python-dotenv

### Build commands
!`cat Makefile`   # live-reads Makefile into context

### Do NOT
- Modify production configs in /configs/prod/
- Run training without first calling validate_dataset.py
- Push to main directly; always use feature branches
πŸ’‘
Keep CLAUDE.md under 200 lines. Use @filename imports for large reference docs. Move library-specific docs into skills. Use !`command` for dynamic context (e.g., !`git log --oneline -5`).
# Auto-generate CLAUDE.md from existing codebase
/init

# Reference another file inline
@./docs/architecture.md
@./configs/base_config.yaml

Settings & Permissions

Settings resolve hierarchically: Enterprise policy β†’ User (~/.claude/settings.json) β†’ Project (.claude/settings.json). Project settings override user, policy overrides all.

# .claude/settings.json β€” project-level
{
  "model": "claude-sonnet-4-6",
  "permissions": {
    "allow": [
      "Bash(git add:*)",
      "Bash(git commit:*)",
      "Bash(make:*)",
      "Bash(python:*)",
      "Write(src/**)",
      "Edit(*.py)",
      "Edit(*.yaml)"
    ],
    "deny": [
      "Bash(rm -rf:*)",
      "Bash(curl * | bash:*)",
      "Write(.env)",
      "Write(configs/prod/**)"
    ]
  },
  "fastMode": false,
  "enableToolSearch": "auto:5"
}
# Interactive permission management
/permissions

# Useful CLI flags
claude --allowedTools "Read,Grep,Glob"      # restrict tools
claude --disallowedTools "Bash,Write"       # deny specific tools
claude --permission-mode acceptEdits        # auto-accept all edits

Custom Slash Commands

Commands are markdown files in .claude/commands/ (project) or ~/.claude/commands/ (global). They're surfaced as /command-name with tab-completion.

# Create a command
mkdir -p .claude/commands
nano .claude/commands/review-pr.md

# Use it
/review-pr
/fix-issue 123          # $ARGUMENTS passes "123"
/deploy-staging main    # $ARGUMENTS passes "main"

Command Anatomy

--- file: .claude/commands/commit.md ---
---
allowed-tools: Bash(git add:*), Bash(git status:*), Bash(git commit:*)
description: Create a semantic git commit from staged changes
---

## Context
- Current status: !`git status`
- Current diff: !`git diff HEAD`
- Branch: !`git branch --show-current`
- Recent commits: !`git log --oneline -5`

Create a conventional commit message (type(scope): description) for these changes.
Stage all relevant files and commit.

Parameterized Commands

--- file: .claude/commands/fix-issue.md ---
Fix GitHub issue #$ARGUMENTS following our coding standards in CLAUDE.md.

1. Read the issue details with gh issue view $ARGUMENTS
2. Identify affected files
3. Implement the fix with tests
4. Open a PR using /review-pr

Built-in Commands Reference

CommandWhat it does
/initScan codebase and auto-generate CLAUDE.md
/clearReset context (use between unrelated tasks)
/compactSummarize and compress context
/continueResume last session
/modelSwitch model interactively
/permissionsView / edit tool permissions
/hooksList configured hooks
/skillsList available skills
/costShow token usage and spend
/contextView context usage as colored grid
/doctorRun diagnostics
/bugReport a bug (sends transcript to Anthropic)
/batchOrchestrate parallelizable changes across codebase
/review-prReview open GitHub PR (built-in)
/pr-commentsFetch and display PR comments
/scheduleSchedule remote Claude Code agents on cron
/fastToggle fast mode (Opus 4.6)
/vimEnter vim keybinding mode
/output-styleSet output verbosity / format

Skills

Skills are packaged workflow libraries β€” directories under .claude/skills/ with a SKILL.md. They're the evolution of commands with richer structure: supporting files, templates, and subagent delegation. They become /skill-name commands.

# Structure
.claude/skills/
  code-review/
    SKILL.md          # entrypoint, metadata
    checklist.md      # supporting doc
    templates/
      review.md
--- .claude/skills/train-eval/SKILL.md ---
---
name: train-eval
description: Run a training evaluation loop for Arthavidya. Use when asked to evaluate, benchmark, or compare model checkpoints.
allowed-tools: [Bash, Read, Write, Grep]
agent: general-purpose
context: fork
---

# Training Evaluation Skill

## Steps
1. Read the active config from configs/active.yaml
2. Run: python scripts/evaluate.py --checkpoint $ARGUMENTS
3. Parse W&B run URL from stdout
4. Summarize eval metrics in a markdown table
5. Compare against baseline in configs/baselines.yaml

Include ultrathink to deeply analyze any regression.
β„Ή
context: fork runs the skill in an isolated subagent. Output returns to main thread cleanly. Add ultrathink anywhere in skill content to enable extended thinking for that skill.

Hooks β€” Deterministic Automation

Hooks intercept Claude Code's lifecycle and run your code β€” shell scripts, HTTP endpoints, LLM prompts, or agents β€” at specific events. They're the "must always happen" layer vs CLAUDE.md's "should do" suggestions.

Event fires
β†’
Matcher regex
β†’
Handler runs
β†’
Decision: allow / block / inject
# .claude/settings.json β€” hooks section
{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [{
          "type": "command",
          "command": "python hooks/block_dangerous.py"
        }]
      }
    ],
    "PostToolUse": [
      {
        "matcher": "Edit|Write",
        "hooks": [{
          "type": "command",
          "command": "ruff format $CLAUDE_TOOL_INPUT_FILE_PATH"
        }]
      }
    ],
    "Stop": [
      {
        "matcher": "*",
        "hooks": [{
          "type": "command",
          "command": "notify-send 'Claude Code' 'Session complete'"
        }]
      }
    ]
  }
}

Hook Events

SessionStart Session begins or resumes β€” load dev context, env vars Once/session
PreToolUse Before any tool call β€” block dangerous commands, audit, inject secrets Per tool call
PostToolUse After tool returns β€” auto-format, lint, log, transform outputs Per tool call
PostToolUseFailure Tool failed β€” structured error logging, alerting Per failure
UserPromptSubmit User submits prompt β€” validate/enhance before Claude sees it Per message
Notification Permission dialog shown β€” audit, auto-allow read-only ops Per dialog
SubagentStart Subagent spawned β€” log spawn, TTS announcement Per spawn
Stop Session ends (exit / sigint / error) β€” git checkpoint, cleanup, notify Once/session
Idle Agent waiting β€” send updates, run background checks Periodic

Hook Handler Types

command
Shell script. JSON input on stdin. Returns decision via exit code + stdout. Most common. Full OS access.
http
HTTP POST to your endpoint. Same JSON in/out contract as command. Useful for external audit systems or webhooks.
prompt
Sends prompt to a Claude model for yes/no evaluation. Returns structured JSON decision. Use for nuanced condition checks.
agent
Spawns a subagent with Read/Grep/Glob tools to verify conditions. Most powerful β€” full code analysis before decision.

Practical Hook Patterns

--- hooks/block_dangerous.py ---
import json, sys, re

data = json.load(sys.stdin)
cmd = data.get("tool_input", {}).get("command", "")

BLOCKED = [r"rm\s+-rf", r"curl.*\|\s*bash", r":(){:|:&};:"]
for pattern in BLOCKED:
    if re.search(pattern, cmd):
        print(json.dumps({"decision": "block", "reason": f"Blocked: {pattern}"}))
        sys.exit(0)

sys.exit(0)  # allow
--- hooks/pre-commit-gate.sh (block-at-submit pattern) ---
#!/bin/bash
# Fires on PreToolUse matching Bash(git commit:*)
# Only allows commit if /tmp/agent-pre-commit-pass exists
if [[ ! -f /tmp/agent-pre-commit-pass ]]; then
  python -m pytest tests/ --tb=short -q
  if [[ $? -eq 0 ]]; then
    touch /tmp/agent-pre-commit-pass
  else
    echo '{"decision":"block","reason":"Tests failed β€” fix before commit"}'
    exit 0
  fi
fi
πŸ’‘
Block-at-submit, not block-at-write. Blocking on every Edit/Write confuses Claude mid-plan. Let it finish writing, then validate at commit time. "Hint hooks" on PostToolUse that return non-blocking feedback are great for coaching without interrupting flow.

Agent System Overview

Claude Code has a layered agent architecture. Understanding it lets you route tasks to the right level.

Main session (Opus/Sonnet)
β†’
Spawns subagents via Task tool
β†’
Subagent runs, returns result
β†’
Main thread continues cleanly
β„Ή
Subagents keep main context clean. In plan mode, Claude Code automatically delegates repo scanning to an Explore-style subagent β€” so your 200K context isn't consumed by file dumps. Up to 10 simultaneous subagents in Claude Code 2.1+.

Built-in Agents

Explore
Haiku-powered. Scans codebase structure, searches files, returns distilled map. Auto-spawned in plan mode. Cost-efficient for large repos.
Plan (enhanced)
Runs the plan mode analysis pipeline. Produces structured task breakdown with dependencies and execution order. Creates plan.md.
General-purpose
Default subagent. Searches, analyzes, edits code across codebase. Reports findings concisely to caller.

Custom Subagents

# Create a custom subagent
mkdir -p .claude/agents
--- .claude/agents/distill-reviewer.md ---
---
name: distill-reviewer
description: Reviews knowledge distillation training logs and checkpoints. Use proactively after any training run completes, or when asked to review, compare, or audit model checkpoints.
tools: Read, Grep, Glob, Bash
model: sonnet
---

You are an expert MLOps reviewer specializing in LLM knowledge distillation.

When reviewing a training run:
1. Parse the W&B run logs or local log file passed to you
2. Check for loss divergence, gradient norm spikes, or NaN values
3. Compare student vs teacher KL divergence across curriculum tiers
4. Flag any checkpoint where eval loss > train loss by >0.3 (overfitting signal)
5. Output a structured markdown report with: status, key metrics, recommendations

Return only the report β€” no preamble.
# Invoke a custom agent directly
@distill-reviewer check the run from last night

# Or from a command/skill, the agent is auto-matched by description
> "Review the training logs"  # Claude delegates if description matches

Multi-Agent Patterns

Builder + Validator

--- .claude/agents/validator.md ---
---
name: validator
description: Validates code changes for correctness, security, and test coverage. Use after implementation is complete.
tools: Read, Bash, Grep
model: sonnet
---
Run: pytest, ruff, mypy, bandit
Return: PASS or FAIL with specific findings.
# In a session
> "Implement the data augmentation module, then validate it"
# Claude builds β†’ spawns validator β†’ reports consolidated result

Parallel Worktree Agents

# Run 3 agents on different features simultaneously
claude -w feature-tokenizer &
claude -w feature-curriculum &
claude -w feature-eval-harness &
wait
# Each works in isolated git worktree β€” no conflicts
git merge feature-tokenizer feature-curriculum feature-eval-harness

Meta-Agent (Agent that builds agents)

--- .claude/agents/meta-agent.md ---
---
name: meta-agent
description: Generates new subagent definitions from natural language descriptions. Use when asked to "build a new agent" or "create a subagent for..."
---

Given a description, produce a properly formatted .claude/agents/*.md file
following the project's agent standards. Ask clarifying questions if needed.
> "Build a new sub-agent that monitors VRAM usage during training runs"
# meta-agent creates .claude/agents/vram-monitor.md automatically

MCP Servers β€” External Integrations

Model Context Protocol gives Claude Code access to databases, APIs, and services through a standardized interface. Over 300 integrations available.

# .claude/mcp.json β€” project MCP config
{
  "mcpServers": {
    "github": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-github"],
      "env": { "GITHUB_TOKEN": "${GITHUB_TOKEN}" }
    },
    "wandb": {
      "command": "python",
      "args": ["-m", "wandb_mcp_server"],
      "env": { "WANDB_API_KEY": "${WANDB_API_KEY}" }
    },
    "postgres": {
      "command": "npx",
      "args": ["@modelcontextprotocol/server-postgres", "${DATABASE_URL}"]
    }
  }
}
# Manage MCP servers interactively
/mcp                         # list connected servers
claude --mcp-server github   # enable specific server

# Use in prompts naturally
> "Create a GitHub issue for the tokenizer bug and assign it to me"
> "Pull my last 5 W&B runs for the arthavidya project and compare metrics"
MCP ServerUse caseInstall
GitHubPRs, issues, code review@modelcontextprotocol/server-github
PostgreSQLQuery prod/dev databases@modelcontextprotocol/server-postgres
FilesystemExtended file access outside project@modelcontextprotocol/server-filesystem
PlaywrightBrowser automation, regression testing@executeautomation/playwright-mcp
SlackSend notifications, read messages@modelcontextprotocol/server-slack
W&BExperiment tracking, run comparisonwandb-mcp-server (community)
MLflowExperiment and model registryCommunity server

Agent SDK

The Agent SDK lets you build custom agent orchestrators in TypeScript or Python β€” with full control over tool access, hooks, subagents, and permissions. Use when Claude Code's interactive mode isn't enough.

TypeScript SDK

import { query, type ClaudeCodeOptions } from "@anthropic-ai/claude-code";

const options: ClaudeCodeOptions = {
  maxTurns: 10,
  allowedTools: ["Read", "Write", "Bash", "Grep"],
  systemPrompt: "You are an MLOps specialist for Arthavidya...",
  hooks: {
    PreToolUse: async (input) => {
      if (input.tool_name === "Bash" && input.tool_input.command.includes("rm -rf")) {
        return { decision: "block", reason: "Destructive command blocked" };
      }
    },
    Stop: async (input) => {
      console.log(`Session ended: ${input.session_id}`);
    }
  }
};

for await (const message of query({
  prompt: "Review training logs in ./logs/ and flag any anomalies",
  options
})) {
  if (message.type === "text") process.stdout.write(message.text);
}

Python SDK

import anyio
from claude_code_sdk import query, ClaudeCodeOptions, PreToolUseHookInput

async def block_destructive(inp: PreToolUseHookInput):
    if inp.tool_name == "Bash":
        cmd = inp.tool_input.get("command", "")
        if "rm -rf" in cmd:
            return {"decision": "block", "reason": "blocked"}

async def main():
    options = ClaudeCodeOptions(
        max_turns=20,
        allowed_tools=["Read", "Write", "Bash"],
        hooks={"PreToolUse": block_destructive},
        system_prompt="MLOps assistant for Arthavidya distillation pipeline"
    )
    async for msg in query(
        prompt="Run evaluate.py on the latest checkpoint",
        options=options
    ):
        print(msg)

anyio.run(main)

SDK Docs Links

CI/CD & GitHub Actions

--- .github/workflows/claude-code-review.yml ---
name: Claude Code Review
on: [pull_request]

jobs:
  review:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: anthropic/claude-code-action@v1
        with:
          prompt: |
            Review this PR for:
            1. Security vulnerabilities (SQL injection, path traversal)
            2. Missing error handling
            3. Hardcoded credentials
            4. Test coverage gaps
            Report findings as PR comments.
          model: claude-sonnet-4-6
          max-turns: 8
          allowed-tools: Read,Grep,Glob,Bash(pytest:*)
        env:
          ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Trigger from Slack/Jira/CloudWatch β€” returns a tested PR
$ query-claude-gha-logs --since 5d | \
  claude -p "see what the other Claudes were getting stuck on and fix it, then put up a PR"
πŸ’‘
GHA logs = agent logs. Full tool call history is preserved. Build a periodic review of your GHA Claude logs to catch patterns: common bash errors, repeated permission requests, misaligned behavior β€” then fix CLAUDE.md. This is the MLOps-style feedback loop for your agent.

Ollama / Local Model Integration

Use local models (GLM4, Qwen3.5, Mistral) for sensitive codebase analysis, cost-zero summarization, or Arthavidya student model self-review.

# Start Ollama with your model
ollama serve
ollama pull qwen2.5-coder:7b
ollama pull glm4:9b

# Route Claude Code to Ollama (OpenAI-compat API)
export ANTHROPIC_BASE_URL=http://localhost:11434/v1
export ANTHROPIC_API_KEY=ollama
claude --model qwen2.5-coder:7b

# Or per-session alias
alias claude-local='ANTHROPIC_BASE_URL=http://localhost:11434/v1 ANTHROPIC_API_KEY=ollama claude'
claude-local --model qwen3.5:4b "Review this config file"
TaskRecommended local modelNotes
Code review / summarizeQwen2.5-Coder:7BGood instruction following
Finance domain Q&A (Arthavidya)Arthavidya student (custom)Your fine-tuned 4B
Doc generationGLM4:9BStrong Chinese+English
Complex reasoningQwen3.5:9B (teacher)Best local quality
⚠
Limitations with local models: No extended thinking tokens. No structured tool use (JSON function calling unreliable on 4B models). Hooks requiring structured JSON decisions may fail. Use local models for conversational tasks; route back to Sonnet/Opus for agentic work.

Context Management

Claude Code has a 200K token context window. Mismanage it and tasks fail from exhaustion. Manage it well and you can sustain 100+ turn workflows.

/compact
Compresses current context with a smart summary. Use mid-session when the token grid turns red.
/clear
Full context reset. Use between completely unrelated tasks.
--continue
Resume previous session with its context. Avoids re-establishing state from scratch.
Context editing (2026)
Auto-clears stale tool call outputs while preserving conversation. Reduced token use by 84% in a 100-turn evaluation.
# Monitor context usage
/context        # colored grid: green β†’ yellow β†’ red
/cost           # token count + spend

# Force context limit per run
claude -p "..." --max-turns 5
claude -p "..." --max-budget-usd 1.50

# Use subagents for verbose operations
# Their output stays in subagent context, not main thread
> "Run the full test suite and tell me what failed"
# Claude spawns subagent β†’ only summary returns

# Limit context bloat from MCP
ENABLE_TOOL_SEARCH=auto:5  # auto-defer tool defs > 5% of context

Workflow Patterns

Specification-First Pattern

Write spec in CLAUDE.md
β†’
Plan Mode review
β†’
You approve plan
β†’
Sonnet executes
β†’
Validator subagent
β†’
Commit (hook gated)

PR-from-Anywhere Pipeline

Slack / Jira trigger
β†’
GitHub Action fires
β†’
Claude Code (print mode)
β†’
Tests pass (hook)
β†’
PR opened

Multi-Agent Production Pipeline (3-stage)

pm-spec agent
Read+Write docs only
β†’
architect-review agent
validates constraints
β†’
implementer-tester agent
Bash+Edit+Write

Orchestrator coordinates all three. Each has minimal tool access β€” principle of least privilege for AI agents.

Ralph Loop (autonomous completion)

# Run agent against a prompt file until task marked complete
# or iteration limit reached

# prompt.md
Task: Implement LoRA fine-tuning for curriculum tier 2 of Arthavidya.
Done when: tests pass, W&B shows loss < 0.5, PR is open.
Limit: 20 iterations.

claude --headless -p "$(cat prompt.md)"

MLOps Workflows with Claude Code

Specific patterns for your Arthavidya / model-fine-tuner-template work.

Training Run Review Hook

--- hooks/post-train-review.sh ---
#!/bin/bash
# PostToolUse hook on Bash β€” triggers after any python training script
INPUT=$(cat)
CMD=$(echo "$INPUT" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d.get('tool_input',{}).get('command',''))")

if echo "$CMD" | grep -q "train.py"; then
  # Trigger distill-reviewer subagent after training completes
  echo '{"systemMessage": "Training complete. Run distill-reviewer on ./logs/latest/"}'
fi

Curriculum-Aware Slash Command

--- .claude/commands/train-tier.md ---
---
allowed-tools: Bash(python:*), Read, Write
description: Run curriculum training for a specific LoRA tier
---

Train curriculum tier $ARGUMENTS for Arthavidya:
1. Load configs/tier_$ARGUMENTS.yaml
2. Validate dataset: !`python scripts/validate_dataset.py --tier $ARGUMENTS`
3. Run: python train.py --config configs/tier_$ARGUMENTS.yaml --resume
4. After completion, invoke distill-reviewer on the latest checkpoint
5. Log results to W&B project arthavidya

DVC + Claude Code Integration

# Give Claude access to DVC commands via permissions
{
  "permissions": {
    "allow": [
      "Bash(dvc add:*)",
      "Bash(dvc push:*)",
      "Bash(dvc pull:*)",
      "Bash(dvc repro:*)"
    ]
  }
}

# In session
> "Add the new training dataset to DVC, push to remote, and update dvc.yaml"

Troubleshooting

SymptomFix
Context limit hit mid-task/compact then continue; use subagents for verbose ops
Claude ignoring CLAUDE.md rulesMove critical rules to Hooks (deterministic); CLAUDE.md is probabilistic
Hook not firing/hooks to verify; check matcher regex with /debug
Ollama tool calls brokenLocal models lack structured tool use; use for conversational tasks only
Subagent context bleedEnsure skill uses context: fork in frontmatter
Slow Opus responsesEnable /fast (2.5Γ— faster, higher cost); or switch to Sonnet
Plan mode not exitingShift+Tab once to toggle back; or explicitly approve plan
Permissions errors/permissions β†’ add allow rule; use --allowedTools flag
Session lost after crashclaude --continue or claude --resume <session-id>
MCP server not connectingCheck mcp.json, run /mcp, verify env vars are exported
# Useful debug commands
/doctor          # full diagnostics
/debug           # session debug info
/context         # token grid
claude --version # verify version
claude update    # update to latest

# Read raw session transcripts
ls ~/.claude/projects/
cat ~/.claude/projects/<project-hash>/<session-id>.jsonl | jq .

Reference Links

Official Docs

Community Resources

Prompt Engineering for Claude Code