CLI Reference
Complete reference for all codehabits CLI commands. Install globally with npm install -g @codehabits/cli or use npx @codehabits/cli.
# Run directly (no install)
npx @codehabits/cli <command>
# Or install globally
npm install -g @codehabits/cli
codehabits <command>enable
Enable codehabits intelligence for the current repository. This is the primary setup command. It registers your repo, scans your codebase, fetches PR history, runs AI analysis, and writes intelligence files.
codehabits enable [options]| Option | Default | Description |
|---|---|---|
| --path <path> | . | Path to the repository root |
| --skip-prs | false | Skip PR fetching (local analysis only) |
| --team <ref> | (none) | Assign repo to this team (id or slug). Required for non-interactive enable on GitHub organization repos. |
| --personal | false | Keep repo unassigned (personal mode). Only allowed for repositories under a personal GitHub account, not organizations. |
⚠Organization-owned repositories
--team in scripts and CI. --personal is rejected for org repos.What it does
- Detects the GitHub repository from git remotes
- Fetches repository info from GitHub (visibility, default branch)
- Registers the repo with codehabits cloud (checks plan limits)
- Scans codebase: tech stack detection, file patterns, code patterns, config rules import, git contributor analysis, repo docs scanning
- Fetches merged and closed PRs (up to 12 months lookback)
- Sends data to the cloud analysis pipeline
- Writes intelligence files to
.codehabits/(conventions.json,anti-patterns.json,knowledge.json,reviewers.json,meta.json),.codehabits/config.json, and the Agent Skill
Output files
| File | Purpose |
|---|---|
| .codehabits/conventions.json | Team coding conventions |
| .codehabits/anti-patterns.json | Anti-patterns to avoid |
| .codehabits/knowledge.json | Domain knowledge graph |
| .codehabits/reviewers.json | Team expertise map |
| .codehabits/meta.json | Sync metadata |
| .codehabits/config.json | codehabits configuration |
| .cursor/skills/codehabits-team-intel/SKILL.md | Agent Skill entry point |
| .cursor/skills/codehabits-team-intel/references/ | Detailed conventions, anti-patterns, knowledge, reviewers |
| AGENTS.md | AI agent entry point (discovered by Claude Code, etc.) |
ℹPlan limits
sync
Incrementally update intelligence with the latest PR data. Only fetches PRs merged since the last sync, then merges new pipeline output with your existing intelligence. The CLI sends your current merged snapshot to the API so the cloud stores the same result you write under .codehabits/ (including MCP-approved conventions).
codehabits sync [options]| Option | Default | Description |
|---|---|---|
| --ci | false | Run in CI mode (non-interactive, no spinners) |
| --path <path> | . | Path to the repository root |
CI mode
When running in CI/CD (e.g., GitHub Actions), use --ci and set the CODEHABITS_TOKEN and GITHUB_TOKEN environment variables:
- name: Sync codehabits intelligence
run: npx @codehabits/cli@latest sync --ci
env:
CODEHABITS_TOKEN: ${{ secrets.CODEHABITS_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}check
Validate a file against your team's conventions and anti-patterns. Runs entirely locally using your .codehabits/ intelligence files: no network required.
codehabits check <file> [options]| Argument / Option | Description |
|---|---|
| <file> | Path to the file to check (required) |
| --path <path> | Path to the repository root (default: .) |
Checks performed
| Check | Severity | Condition |
|---|---|---|
| Named exports | Warning | Default export in non-page/layout files when team uses named exports |
| Path aliases | Info | Deep relative imports (../../..) when path aliases are configured |
| Barrel files | Info | index.ts files that contain logic instead of re-exports |
| console.log | Error / Warning | console.log/debug/info in non-test files (severity from anti-patterns) |
| any type | Warning | Explicit `any` type usage |
Exits with code 1 if any violations have error severity. Useful as a pre-commit hook or CI check.
Checking src/api/client.ts against team conventions...
✗ Catching errors without logging or re-throwing
→ Always log the error with context or re-throw
! Using default export - team convention prefers named exports
→ Use named exports: export function/const instead of export default
1 error, 1 warning, 0 infoshow
Display intelligence data in the terminal. Useful for reviewing what codehabits has learned about your team.
codehabits show <type> [options]| Argument / Option | Description |
|---|---|
| <type> | What to show: conventions, anti-patterns, knowledge, reviewers, or summary |
| --path <path> | Path to the repository root (default: .) |
| --json | Output as JSON instead of formatted text |
Types
summary: High-level overview: repo name, maturity level, counts for all intelligence categories, tech stack, last sync time.
conventions: All conventions grouped by category, with confidence scores, evidence counts, and source attribution.
anti-patterns: Detected anti-patterns sorted by severity, with explanations and correct alternatives.
knowledge: Domain knowledge graph organized by topic (authentication, database, deployment, etc.) with confidence scores.
reviewers: Reviewer expertise map showing who reviews which areas, total reviews, and approval rates.
codehabits show conventions --json | jq '.[] | select(.confidence > 0.9)'login
Authenticate with codehabits using GitHub OAuth. Opens your browser for authorization, then stores credentials locally.
codehabits loginThe CLI uses a device code flow: it displays a verification code, opens the codehabits auth page in your browser, and polls until authentication completes. Credentials are stored securely in your system config directory.
logout
Clear stored credentials from your machine.
codehabits logoutwhoami
Display the currently authenticated user.
codehabits whoamicodehabits CLI - Current User
Login: sriram
Email: sriram@example.com
ID: usr_abc123token
Manage API tokens for CI/CD and programmatic access. Tokens use the codehabits_ prefix and are stored as SHA-256 hashes on the server.
token create
codehabits token create --name <name> [--scope <scope>] [--repo-id <id>]| Option | Default | Description |
|---|---|---|
| --name <name> | (required) | Human-readable token name |
| --scope <scope> | ci | Token scope: cli or ci |
| --repo-id <id> | (none) | Restrict token to a specific repo |
⚠Save your token
CODEHABITS_TOKEN).token list
List all your API tokens with metadata.
codehabits token listtoken revoke
Revoke a token by its ID.
codehabits token revoke <id>mcp-install
Configure the codehabits MCP server for Cursor. This enables real-time AI tool access to your team's intelligence via the Model Context Protocol.
codehabits mcp-install [options]| Option | Default | Description |
|---|---|---|
| --path <path> | . | Path to the repository root |
| --global | false | Install in ~/.cursor/mcp.json (all projects) instead of repo-local |
MCP tools provided
| Tool | Description |
|---|---|
| get_team_context | Returns conventions + anti-patterns + knowledge, optionally filtered by scope or file path |
| check_code | Validates a code snippet against conventions and returns violations with severity |
| get_knowledge | Returns domain knowledge for a topic from the knowledge graph |
| suggest_reviewers | Matches file paths to reviewer expertise areas |
| record_feedback | Appends a pending proposal to local .codehabits/proposals.json (gitignored) |
| approve_proposal | Merges a pending proposal into conventions.json and regenerates skill markdown (creates normal git changes to commit) |
team assign
Assign an already-enabled repository to a team workspace from the CLI (alternative to the dashboard). Detects the repo from git remote and calls the codehabits API.
codehabits team assign [options]| Option | Default | Description |
|---|---|---|
| --path <path> | . | Path to the repository root |
| --team <ref> | (none) | Team id or slug; required when not running in an interactive terminal |
setup-action
Generate a GitHub Actions workflow that automatically syncs intelligence when PRs are merged.
codehabits setup-action [options]| Option | Default | Description |
|---|---|---|
| --path <path> | . | Path to the repository root |
| --branch <branch> | (auto-detected) | Default branch name (e.g., main, master) |
| --force | false | Overwrite existing workflow file |
Generated workflow
Creates .github/workflows/codehabits-sync.yml that:
- Triggers when a PR is closed (merged) on your default branch
- Checks out the repository
- Runs
npx @codehabits/cli@latest sync --ciwith your tokens - Commits updated
.codehabits/and.cursor/skills/files
Setup steps
- Create a token:
codehabits token create --name "CI" - Add it as a repository secret named
CODEHABITS_TOKENin GitHub Settings → Secrets - Run
codehabits setup-actionand commit the workflow file
Environment variables
| Variable | Description |
|---|---|
| CODEHABITS_TOKEN | API token for CI/CD (overrides stored auth) |
| GITHUB_TOKEN | GitHub token for PR fetching in CI |
| CODEHABITS_API_URL | Override the API base URL (default: https://codehabits.dev) |
| CODEHABITS_TELEMETRY_DISABLED=1 | Disable anonymous usage telemetry |
| DO_NOT_TRACK=1 | Alternative way to disable telemetry |