How to Write Documentation with Claude Code
Documentation is the part of software development everyone knows matters and nobody wants to do. README files go stale within weeks of being written. API docs either don't exist or describe endpoints that were refactored three sprints ago. Architecture decisions live only in someone's head, and when that person leaves, the knowledge goes with them. The first draft is always the hardest part -- staring at a blank file, trying to figure out where to start and what to include.
Claude Code eliminates that pain entirely. It reads your actual codebase, understands the intent behind your functions and modules, and generates accurate, well-structured documentation in seconds. You don't need to explain your code to it -- it reads the source files directly. The result is a solid first draft that you refine and polish, rather than a blank page you have to fill from scratch.
Why Claude Code Writes Good Documentation
Most documentation fails because it's written from memory. A developer finishes a feature, opens a blank Markdown file, and tries to recall what they built and why. Details get lost. Edge cases get forgotten. The docs describe what the developer intended, not what the code actually does.
Claude Code takes a fundamentally different approach. It reads the actual source code -- every function signature, every data flow, every module boundary. The documentation it produces matches reality, not aspirations. When your createUser function actually accepts five parameters but your hand-written docs only mention three, Claude catches that because it read the function definition directly.
Beyond accuracy, Claude Code understands the full spectrum of documentation formats. It generates proper Markdown with correct heading hierarchies, JSDoc annotations with typed parameters and return values, Python docstrings following Google or NumPy conventions, and OpenAPI specifications with complete request and response schemas. It can write at different levels too -- user-facing guides that assume no code knowledge, API references packed with technical detail, and architecture overviews that explain how the pieces fit together.
But the most valuable capability is updating existing documentation when code changes. This is where manual documentation always breaks down. Nobody remembers to update the README after refactoring. Claude Code does, because you can simply tell it to.
README Generation
The README is your project's front door. It's the first thing anyone sees on GitHub, and it sets the tone for whether someone will use your project or move on. Despite its importance, READMEs are notoriously neglected -- either they're a stub from project creation or they describe a version of the software that no longer exists.
With Claude Code, generating a comprehensive README takes a single prompt: "Generate a README.md for this project. Include: overview, features, installation, quick start, configuration, and contributing guidelines." Claude reads your package.json or setup.py for project metadata, scans your source code for feature coverage, inspects your configuration files for setup requirements, and examines your directory structure for project organization.
The result is a complete, properly formatted README with sections that reflect your actual project. Installation instructions reference the real dependencies. Quick start examples use actual API calls or CLI commands from your codebase. Configuration documentation lists real environment variables and options, not placeholders. If your project has a Dockerfile, Claude includes Docker-based setup instructions. If you have a Makefile, it documents the available targets.
The code examples in Claude-generated READMEs actually work because they're derived from reading your source code and tests, not invented from scratch. That alone makes them more valuable than most hand-written examples.
API Documentation
API documentation is one of the highest-value and most tedious forms of documentation to maintain. Every route needs its path, method, parameters, request body shape, response schema, authentication requirements, and error responses documented. Doing this manually for dozens or hundreds of endpoints is a recipe for incomplete, outdated docs.
Claude Code handles this systematically. Ask it to "Generate OpenAPI/Swagger documentation for all API routes in this project," and it reads every route handler in your codebase. It extracts path parameters, query parameters, and request body schemas from your code. It identifies response shapes from your return statements and serializers. It detects authentication middleware and documents which endpoints require auth and what kind.
The output is a complete API specification with realistic request and response examples. If your Express route handler validates the request body with Zod or Joi, Claude reads the validation schema and generates the correct OpenAPI types. If your Django view uses a serializer, Claude reads the serializer fields and produces matching documentation.
For inline documentation, try: "Add JSDoc comments to all exported functions in the services directory." Claude doesn't just add parameter names -- it generates meaningful descriptions that explain what each function does, what each parameter controls, what the return value represents, and what exceptions might be thrown. These are the kinds of comments that actually help the next developer understand your code.
Architecture Documentation
Architecture documentation is the hardest to write and the most valuable to have. It's the kind of knowledge that usually exists only in the heads of the engineers who built the system. When they leave, that knowledge evaporates. New team members spend weeks or months piecing together how the system works from code archaeology and tribal knowledge.
Claude Code can produce this documentation because it does what no human practically can -- it reads every file in the codebase and synthesizes a coherent picture. Ask it to "Write an architecture document for this project. Cover: system overview, directory structure, data flow, key design decisions, and deployment architecture." Claude identifies the layers of your application, maps the dependencies between modules, traces data flows from input to output, and documents integration points with external services.
The result is an architecture guide that covers how the request lifecycle works end to end, what the major modules are and how they interact, where state is managed and how it's persisted, what external services the system depends on, and how the deployment pipeline is configured. This is documentation that provides real onboarding value.
Architecture Docs That Surprise Even the Authors
Claude Code generates architecture documentation that even the original developers would struggle to write from scratch -- because it reads every file, not just the ones you remember. It catches cross-cutting concerns, implicit dependencies, and design patterns that are obvious in the code but invisible when you try to describe the system from memory.
Code Comments and Docstrings
There's a spectrum of opinion on code comments, from "every line should be commented" to "good code is self-documenting." The practical truth is somewhere in the middle: public APIs need documentation, complex algorithms need explanation, and non-obvious design decisions need rationale. Everything else is noise.
Claude Code understands this balance. Ask it to "Add docstrings to all public functions in the Python codebase" and it generates meaningful documentation where it adds value. For a simple getter, it writes a brief one-line docstring. For a complex data transformation function, it explains the algorithm, documents each parameter with its type and purpose, describes the return value, includes usage examples, and notes any edge cases or exceptions.
The same applies to TypeScript with JSDoc: "Add JSDoc comments to all exported TypeScript functions." Claude generates @param tags with types and descriptions, @returns with the return type and meaning, @throws for functions that raise errors, and @example blocks with working code snippets. It doesn't over-comment -- it skips obvious utility functions and focuses on the interfaces that other developers will actually consume.
This targeted approach is what makes Claude-generated comments useful rather than annoying. Nobody needs a comment that says "increments counter by one." Everyone benefits from a comment that explains why a particular retry strategy was chosen or what invariant a validation function enforces.
Keeping Docs Up to Date
Writing documentation once is hard enough. Keeping it current is where most teams fail completely. Code evolves sprint after sprint, but the docs stay frozen at whatever state they were in when someone last had the energy to update them. Within months, the documentation becomes not just incomplete but actively misleading -- describing behaviors the system no longer exhibits.
Claude Code makes incremental documentation updates trivial. After making code changes, tell it: "Update the README to reflect the new authentication flow." After modifying API endpoints, say: "Update the OpenAPI spec for the /users endpoints." Claude reads both the current code and the current documentation, identifies what changed, and updates only the affected sections. It doesn't rewrite the entire document -- it surgically updates the parts that are now out of date.
This changes the economics of documentation entirely. Updating docs is no longer a thirty-minute chore you put off until it becomes a three-hour project. It's a thirty-second prompt at the end of a coding session.
Pro Tip: Make "Update Docs" Part of Your Commit Workflow
After finishing a feature or fix, add one more step before committing: ask Claude Code to update the relevant documentation. It takes seconds, and it means your docs never drift more than one commit behind your code. Over time, this single habit eliminates the "stale docs" problem entirely.
Changelogs and Release Notes
Changelogs and release notes are documentation that users and stakeholders actually read. They want to know what's new, what's fixed, and what might break. Writing good release notes requires reading through all the commits since the last release, categorizing them, and translating technical changes into language that makes sense to your audience.
Claude Code does this in one step: "Generate a changelog for all commits since the last tag." It reads your commit messages, groups them by type -- features, bug fixes, performance improvements, breaking changes -- and produces a properly formatted CHANGELOG.md entry with the version number, date, and categorized items. If your commit messages follow Conventional Commits, the categorization is even more precise.
For user-facing release notes, follow up with: "Write release notes for v2.0 based on the changelog -- make them user-friendly." Claude translates the technical changelog into language that non-developers can understand. "Refactored authentication middleware to use JWT" becomes "Sign-in is now faster and more secure." "Fixed race condition in WebSocket handler" becomes "Resolved an issue where real-time updates could occasionally be delayed." The technical accuracy is preserved, but the presentation is appropriate for the audience.
The Documentation Workspace
Documentation work has its own rhythm, distinct from feature development. You're generating content, previewing it, refining the language, and committing the results. Having a dedicated workspace for this flow keeps it clean and efficient.
In Beam, set up a "Docs" workspace with three tabs:
- Tab 1: Claude Code -- This is where you generate and update documentation. All your prompts for README generation, API docs, architecture guides, and changelog creation happen here.
- Tab 2: Preview -- Run a Markdown previewer or local docs site here. After Claude generates or updates a file, switch to this tab to see how it looks rendered. Catch formatting issues before they hit production.
- Tab 3: Git -- Stage and commit your documentation updates here. Keep doc commits separate from code commits when possible -- it makes the git history cleaner and makes it easy to see when docs were last updated.
The workflow becomes generate, preview, refine, commit. With Beam's workspace switching (⌘⌥←→), you can jump between your documentation workspace and your development workspace without losing context in either one.
Stop Putting Off Documentation
Download Beam and let Claude Code write the first draft. You just refine.
Download Beam for macOSSummary
Documentation doesn't have to be the thing you perpetually plan to do and never get around to. With Claude Code, the hardest part -- the first draft -- is handled for you. Here's what you can generate:
- README files that accurately describe your project, with working code examples and real installation steps
- API documentation with complete OpenAPI specs, parameter descriptions, and response schemas extracted from your actual code
- Architecture guides that capture system design, data flows, and integration points -- knowledge that usually lives only in people's heads
- Code comments and docstrings that explain the why, not just the what, added only where they provide value
- Changelogs and release notes generated from your commit history, formatted for both developers and users
- Incremental updates that keep all of the above current as your code evolves
The documentation workflow in Beam -- generate in one tab, preview in another, commit in a third -- makes the whole process feel lightweight instead of burdensome. When writing docs takes thirty seconds instead of thirty minutes, you actually do it. And that changes everything.