Skip to Content

drift check

This command checks for drift between your code and documentation based on the rules in your .drift.yaml file.

To check all files:

drift check

You can also use a custom configuration file with the --config flag:

drift check --config /path/to/your/config.yaml

Checking Changed Files

For faster checks, especially in a CI/CD environment, you can check only the files that have been modified. The --changed-files flag (or -f) allows you to pass a list of file paths to check against.

drift will then compare this list of files against the glob patterns in your rules and only run the assessments for the rules that are “triggered” by a matching file.

# Pass a specific list of files drift check --changed-files "pkg/server/main.go,docs/api/server.md"

This is most powerful when combined with git to automatically check files in a pull request:

# Get a list of changed files from git and pass them to drift CHANGED_FILES=$(git diff --name-only origin/main...HEAD | tr '\n' ',') drift check --changed-files "$CHANGED_FILES"

The drift check command evaluates your code and documentation against the rules defined in your .drift.yaml configuration file. Each rule specifies a set of code files and corresponding documentation files to be assessed for consistency.

If drift detects any discrepancies, it will report them and exit with a non-zero exit code, making it easy to integrate into your CI/CD pipeline. The assessment is performed by an AI model (e.g., Gemini, OpenAI) which analyzes the content and provides a reason for any detected drift.

Example Output

Here’s an example of what you might see if drift is detected:

Loaded 1 rules from .drift.yaml (provider: gemini) - Rule: User API Documentation Found 1 code files, total size: 1234 bytes Found 1 doc files, total size: 567 bytes Result: Out of Sync (Reason: The `GetUser` function in `user.go` now includes a `context.Context` parameter, which is not reflected in the `users.md` documentation.) drift detected

For more details on configuring your rules and LLM providers, refer to the Configuration Guide.

Last updated on