On this page
Documentation as code (also written docs as code) is the practice of treating documentation like source code: plain-text files in the same repository, changed through pull requests, built and checked by CI, and published on merge. Teams adopt it so docs get the same review and history as the code they describe. It solves where docs live. It does not solve whether they are still true.
What docs as code means in practice
The idea is old and simple. Docs are Markdown or reStructuredText files in the repo, next to the code or in a docs/ folder. A static site generator such as MkDocs, Docusaurus or Sphinx turns them into a site. Whoever changes a behaviour edits the page in the same pull request.
That gives you four things a wiki or a shared drive never did: version history tied to commits, review by the people who know the change, branches for work in progress, and a build that can fail.
The standard workflow
Most docs-as-code setups have the same four steps.
- Write Markdown in the repo. One file per topic, in version control, reviewed like any other file.
- Review in the pull request. The docs change sits in the same diff as the code change, so a reviewer can ask "where is the doc update?"
- Build in CI. The site generator runs on every pull request. A broken build blocks the merge.
- Lint the prose. Vale enforces a style guide, markdownlint enforces Markdown structure, and a link checker such as lychee catches dead URLs.
Publishing is a deploy step on the main branch. If you want worked examples of what ends up in those files, see technical documentation examples.
The failure mode: stale docs pass every check
Here is the gap. A developer renames parse_config to load_settings and updates every caller. The compiler is happy and the tests pass. The Markdown build is green because the docs did not change. Vale is green because the prose is fine. The page that says "call parse_config()" ships to production, and a reader trusts it.
Every tool in the standard workflow checks the docs as a document. None of them checks the docs against the code. That is doc drift: the code moved, and the doc under it did not. Keeping docs in the repo makes drift easier to fix. It does nothing to make it visible. The longer version of that argument is in stale documentation: how to detect and fix it.
Fail CI when docs drift from code
Most of what a doc says about code is checkable, because the repository can settle it. repowise doc-drift checks five kinds of reference against the tree:
| Kind | The doc claims | Refuted when |
|---|---|---|
path | a file or directory exists | nothing is at that path |
link | another document exists | the target is gone |
anchor | a heading exists | the heading was renamed or removed |
command | you can run something | the manifest does not declare it |
symbol | a function, class or method exists | it was defined when the line was written and is defined nowhere now |
Scroll the table sideways to see every column.
The symbol kind is conservative on purpose. A backticked word is often just a word, so a token is flagged only when git blame shows that, at the commit that last wrote the line, a source file defined a symbol with exactly that name. A name that never was a symbol is not reported. Anchors are the case that surprises people: rename a heading and every link into it breaks silently.
In CI the check reads the working tree. It needs git, no index, no model and no API key, and it takes a few seconds on a large repository. It exits 1 when a finding at or above the confidence threshold (0.7 by default) is present, and 2 when it cannot evaluate.
repowise doc-drift --check --format github
A clean run does not claim your docs are true. It claims the references it could resolve, resolved. That is the point: a checker that guessed would be wrong often enough that nobody would trust it. Findings that name a likely replacement (a renamed file, a similar heading) carry it, and repowise never edits your documents. The full behaviour is in the doc-drift reference.
A short practical setup
1. Install and look. Run it locally first to see what you have.
pip install repowise
repowise doc-drift --min-confidence 0.9
2. Record a baseline if the repo already has drift. Fail only on new findings, and fix the old ones at your own pace.
repowise doc-drift --check --write-baseline .doc-drift-baseline.json
git add .doc-drift-baseline.json
3. Gate pull requests. Add --baseline .doc-drift-baseline.json in CI, and --fail-on-baseline-growth to stop the baseline from quietly growing. Or skip the baseline and gate only the drift a change is answerable for:
repowise doc-drift --check --since auto --format github
--since auto diffs from the merge-base with the target branch and keeps a finding when the change edits its document, deletes or renames the file it names, or edits the file that defined its symbol. Use fetch-depth: 0 in the checkout.
4. Or use the Action. The GitHub Action runs the same check beside your other gates, and a GitLab template does the same for merge requests. Setup is in repowise in CI.
5. Mark deliberate exceptions in the doc. A tutorial that invents a path can carry <!-- repowise-drift-ignore --> above the line, and the decision travels with the text. Silenced references are counted in the report, never dropped quietly.
Keep Vale, markdownlint and your site build. They answer a different question. If you are comparing drift tools beyond this one, best documentation drift detection tools covers the field, and what makes code documentation worth keeping covers the writing side.
FAQ
- What is documentation as code?
- Documentation as code is the practice of writing and maintaining documentation with the same tools and workflow as source code. Docs are plain-text files in version control, changed through pull requests, built in CI and published automatically on merge.
- Is "docs as code" the same as "documentation as code"?
- Yes. Both names describe the same practice. "Docs as code" is the shorter form most writers and teams use, and "docs-as-code" is the hyphenated spelling you will see in tool documentation.
- What tools do you need for a docs-as-code workflow?
- You need a Git host, Markdown or reStructuredText files, a static site generator such as MkDocs, Docusaurus or Sphinx, and a CI service to build on each pull request. Most teams add Vale for style, markdownlint for structure and a link checker. A drift check such as
repowise doc-driftcovers claims about the code itself. - How do you stop docs from going stale in a docs-as-code setup?
- Check the references your docs make against the repository on every pull request. Paths, links, headings, commands and function names can all be verified automatically, and CI can fail when one no longer resolves. Reviewers still need to confirm that prose describing behaviour is accurate.
- Do docs as code still need a technical writer?
- Yes. The workflow changes where docs live and how they ship, not who shapes them. Writers often own the style guide, the structure and the review, while engineers update pages in the same pull request as their change.
- Can I fail a build on doc drift without an index or a model?
- Yes.
repowise doc-drift --checkreads the working tree and needs only git. Thesymbolkind is the exception: it needs an index and full git history, and runs in CI only when you pass--kind symbol.



