If your README is always one feature behind and your TSDoc looks like archaeology, you are in the target audience. This guide shows exactly how to use OpenClaw for documentation generation from code: install it, point it at a repository, prompt it for different doc formats, and tell cron to keep everything fresh.
Prerequisites and why OpenClaw instead of yet-another-doc-tool
I used to juggle three generators: typedoc for TypeScript, readme-md-generator for README stubs, and a half-broken bash script that glued it all together. OpenClaw replaces the glue because it can:
- Read the entire repo context (not just headers) through its code ingestion pipeline.
- Generate markdown, HTML, or comments in situ via the tool integration hooks.
- Persist its own memory so the next run knows what changed.
- Run locally or on ClawCloud — same commands, zero lock-in.
You’ll need:
- Node 22+ (
node -vshould printv22.xor newer). - Git repository with readable source.
- OpenAI, Anthropic, or local model credentials exported as
OPENCLAW_PROVIDER_KEY. (OpenClaw acts as an agent, not a model provider.) - For cron jobs: Unix-ish environment or GitHub Actions.
Quick setup: install and point OpenClaw at your repo
Local install
The daemon is now a global.
npm install -g openclaw@2.4.1 # 2.4.1 works with Node 22.2+
openclaw daemon start # spawns in ~/.openclaw
Grab the web UI (the gateway) in another shell so you can inspect tokens:
openclaw gateway serve --port 4040
Sign-in on ClawCloud (optional)
curl -s https://cli.clawcloud.ai/install.sh | bash
clawcloud login --token <your-token>
clawcloud agent create my-doc-bot --repo https://github.com/you/project.git
The CLI wraps the same commands; the only difference is the --cloud flag that streams logs to the dashboard.
Bootstrapping a README from scratch
OpenClaw ships with a cookbook recipe called docs/readme.cjs. Copy it and tweak prompts.
# inside repo root
echo "module.exports = require('@openclaw/recipes').readme" > .clawrc.cjs
openclaw run docs:readme --out README.md
What happens under the hood:
- OpenClaw indexes source files (AST + embeddings).
- The recipe sends a prompt chain: "Summarize the public API", "List install commands", "Add a 30-second example".
- The output is streamed and written to
README.md, overwriting existing content between the markers<!-- claw:start -->and<!-- claw:end -->. Anything outside survives.
If you already have a README, add markers manually so OpenClaw only controls a section:
## Auto-generated API overview
<!-- claw:start -->
<!-- claw:end -->
Next time you run openclaw run docs:readme, only that block updates.
Prompt tweaks that improved accuracy
- Preload context with your project philosophy: "Prefer functional utilities over classes". The model then stops inventing OO examples.
- Add docstring priority: "When available, use JSDoc comments verbatim".
- Use
strictJSONoutput mode if you feed the result to another linter.
Generating API reference via JSDoc / TSDoc
Typed code already carries half the documentation. The trick is to let OpenClaw fill the other half without erasing hand-written nuggets.
One-shot generation
openclaw run docs:tsdoc --source src/**/*.{ts,tsx} --mode fill-gaps
fill-gaps means:
- If a function/class already has JSDoc, leave it.
- If not, insert above the declaration.
- Do not touch private members (saves token budget).
The node script behind this run roughly looks like:
module.exports = async (agent) => {
const files = await agent.fs.glob('src/**/*.{ts,tsx}');
for (const f of files) {
const source = await agent.fs.readFile(f, 'utf8');
const updated = await agent.llm.docstringFill(source, {
language: 'typescript',
visibility: 'public',
style: 'tsdoc'
});
if (source !== updated) await agent.fs.writeFile(f, updated);
}
};
Prompt engineering for API accuracy
Two practical rules:
- Feed the type signature, not the entire file, when token pressure is high. A simple regex to cut the right chunk suffices.
- Ask for 100-character summaries and unit test examples in a second pass. Splitting keeps hallucination rate low and cost predictable.
I keep this at the top of my prompt file:
{
"system": "You are an expert TypeScript documentarian. Strictly follow TSDoc.",
"user": "Generate docstring for the given public symbol. Do not mention private fields. Return ONLY TSDoc markup.",
"format": "notags"
}
Scheduling documentation updates with cron
Docs drift. Automate or perish.
Unix cron
# crontab -e
# Re-index and regenerate every midnight
0 0 * * * /usr/local/bin/openclaw run docs:all --repo /opt/project | tee -a /var/log/claw-docs.log
GitHub Actions
# .github/workflows/claw-docs.yml
name: Claw Docs
on:
schedule:
- cron: '0 0 * * *'
workflow_dispatch:
jobs:
update-docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Node 22
uses: actions/setup-node@v4
with:
node-version: 22
- run: npm install -g openclaw@2.4.1
- run: openclaw run docs:all --commit --push
env:
OPENCLAW_PROVIDER_KEY: ${{ secrets.OPENCLAW_PROVIDER_KEY }}
The --commit --push flags add and push changes on a branch named claw/docs-auto-YYYYMMDD. Use a protected branch rule so human review still happens.
Workflow tips and caveats
- Token cost: For a 30k-line codebase, the first index run cost me roughly 0.60 USD on GPT-4o-mini. Subsequent diffs are cheap.
- Binary files: Exclude them with
.clawignore(same syntax as.gitignore). - Non-JS languages: Recipes exist for Go (
docs/godoc.cjs) and Rust (docs/rustdoc.cjs), but expect rough edges. - Security: Run under a low-privilege user. The
shelltool is powerful; disable it viatools.deny = ['shell']in.clawrc.cjswhen generating docs on CI. - Model choice: Users reported better Markdown tables with Claude 3 Sonnet; code snippet accuracy was higher with GPT-4o. Mix and match using
agent.useModel()per task. - Human overrides: If you hand-edit auto sections, the next run will overwrite. Instead, annotate with
<!-- claw:skip-line -->on the lines you want preserved.
Where to go from here
You now have a bot that writes and maintains your documentation without human babysitting. The next step is to add a Slack integration so your team can request on-demand diagrams (/claw docs diagram models/user.ts). That and recipe sharing live on #docs-automation in the OpenClaw Discord — see you there.