Skip to content

Claude Code ​

Claude Code is Anthropic's official CLI tool for AI-assisted development. In this documentation system, it serves as the primary orchestration layer.

Overview ​

Model Hierarchy ​

ModelRoleUse Case
Claude OpusOrchestratorComplex decisions, context merging, final quality control
Claude SonnetWorker AgentParallel source reading, chapter writing, code generation

Installation ​

bash
# Install Claude Code CLI
npm install -g @anthropic-ai/claude-code

# Authenticate
claude auth login

# Verify installation
claude --version

Project Configuration ​

Create .claude/CLAUDE.md in your project root:

markdown
# Claude Code Project Configuration

## Project Overview
This is a documentation generation project using LaTeX.

## Key Files
- `latex/main.tex` - Main document
- `latex/bibliography.bib` - References
- `latex/chapters/` - Chapter files
- `agents/AGENT_GUIDELINES.md` - Writing guidelines

## Agent Usage

### For Chapter Writing
Use **Opus** model for complex chapters:
- Max pages: X
- Sources: [list]
- Style: flowing prose, not bullets

### For Quick Tasks
Use **Sonnet** for:
- Bibliography fixes
- Simple corrections
- Code examples

Orchestration Pattern ​

Spawning Parallel Agents ​

The orchestrator (Opus) can spawn multiple Sonnet agents to work simultaneously:

User: "Analyze all source documents"

Opus (thinking):
- I have 3 PDFs in sources/
- I'll spawn 3 agents to read them in parallel
- Each agent will return a summary
- I'll merge the summaries

Opus → Task: "Read sources/thesis1.pdf and summarize" (Sonnet)
     → Task: "Read sources/thesis2.pdf and summarize" (Sonnet)
     → Task: "Read sources/report.pdf and summarize" (Sonnet)

[Agents work in parallel]

Opus receives: Summary1, Summary2, Summary3
Opus merges: Combined context for next phase

Agent Task Invocation ​

When the orchestrator delegates a task:

Task agent invocation:
├── Agent type: Sonnet (efficient for well-defined tasks)
├── Context: Relevant source excerpts only
├── Instructions: Specific chapter requirements
├── Constraints: Page limit, style guidelines
└── Output format: Complete LaTeX chapter

Best Practices ​

1. Context Management ​

Keep Context Focused

Don't pass entire documents to worker agents. Extract only relevant sections to keep context windows efficient.

Good:
- "Read pages 10-25 of thesis.pdf about security threats"

Bad:
- "Read the entire thesis.pdf"

2. Task Granularity ​

Break large tasks into parallelizable units:

Instead of:
- "Write the entire document"

Use:
- "Write chapter 1: Introduction (4 pages)"
- "Write chapter 2: Background (8 pages)"
- "Write chapter 3: Methodology (10 pages)"
[Parallel execution]

3. Quality Checkpoints ​

Build in review stages:

Configuration Files ​

.claude/settings.json ​

json
{
  "model": "claude-opus-4-20250514",
  "agentModel": "claude-sonnet-4-20250514",
  "maxTokens": 8192,
  "temperature": 0.7
}

Project Context File ​

The .claude/CLAUDE.md file provides project context to Claude Code:

markdown
# Project: AI Security Documentation

## Goal
Generate 150-page research document on AI security.

## Source Files
- sources/thesis1.pdf - ML attack research
- sources/thesis2.pdf - Defense mechanisms
- sources/report.pdf - Industry analysis

## Output
- latex/chapters/*.tex - Chapter files
- latex/main.tex - Main document

## Style Guidelines
- Academic prose, not bullet lists
- Proper language with correct accents
- Max 2-3 code blocks per chapter
- Citations using \cite{}

Workflow Commands ​

Starting a Session ​

bash
# Start Claude Code in project directory
cd your-project/
claude

# Claude will read CLAUDE.md and understand project context

Common Operations ​

bash
# Ask Claude to analyze sources
> Analyze all documents in sources/ and create a synthesis

# Generate a chapter
> Write chapter 05 following the chapter-writer prompt

# Review a chapter
> Review latex/chapters/05-security.tex for quality

Integration with External Tools ​

Claude Code can generate prompts for external AI services:

The orchestrator generates research prompts, you run them on external platforms, then paste results back for integration.

Error Handling ​

Common Issues ​

ErrorSolution
Context too longSplit into smaller tasks
Rate limit exceededWait or use lower tier
Agent timeoutReduce task complexity

Recovery Pattern ​

If agent fails:
1. Log the error
2. Reduce scope
3. Retry with simpler task
4. Escalate to orchestrator if repeated failures

Multi-Agent Documentation Generation System