This document targets both humans and AI/agents. It covers every implemented command with usage, descriptions, examples, and exit codes. For automation, prefer --output json; add --debug when diagnosing issues.
Global Options (apply to all commands)
--repo <path>: explicit Git repo root (default: auto-detect from CWD)--output json|text: output format (defaulttext; automation should usejson)--debug: print underlyinggitcommands to stderr--timeout <ms>: per-command timeout in milliseconds (default 30000)
Conventions
- Concurrency lock: commands acquire
.git/diffkeeper/lock; on contention, exit code isLOCKED(14). .gitignore: both auto-snapshot (init --dirty commit) and regularcommithonor.gitignore.- Errors & JSON: when failing, JSON includes
error.errorCode(e.g.,NOT_GIT,NO_SESSION,DIRTY_WORKTREE,LOCKED,PATCH_APPLY_FAILED, etc.).
Usage
diffk status [--repo <path>] [--output json|text]Description- Prints repo info and session state (current branch, dirty/untracked, in-session).
- If
.gitignoreis missing, aNO_GITIGNOREwarning may appear indata.warnings. Examples diffk statusdiffk status --output jsonExit codes20/NOT_GIT: not a git repo
Usage
diffk init --mode new-branch|current [--source <branch>] [--branch <name>] [--install-hooks] [--no-upstream] [--dirty commit|stash|block|keep] [--if-missing] [--snapshot-message "<msg>"|--snapshot-message-file <path>] [--output json]Description- Initialize a session on a new or the current branch; records base commit.
- Idempotent:
--if-missingreturns existing session if present. - Dirty policy
--dirty:commit(default, only when not switching source): autogit add -Aand commit a snapshot;stash:stash pushbefore switching,stash popafter; if changes remain, commit a snapshot;block: block and suggest cleaning;keep: attempt to keep and switch (may fail; not recommended).
- Auto snapshot commit message can be customized:
--snapshot-message,--snapshot-message-file(file takes priority); applied only if a snapshot commit actually occurs; no prefix added automatically;- Environment overrides for defaults:
DIFFK_SNAPSHOT_MESSAGE,DIFFK_SNAPSHOT_MESSAGE_STASH.
- Others:
--install-hooksinstalls a pre-push hook blockingdiffkeeper/*;--no-upstreamskips setting an upstream. Examples - Current branch auto snapshot:
diffk init --mode=new-branch --source main --if-missing --dirty commit --snapshot-message "Warmup snapshot" --output json
- Switching source with a dirty worktree (stash policy):
diffk init --mode=new-branch --source main --if-missing --dirty stash --snapshot-message-file .snapshot-msg.txt --output jsonExit codes
11/SESSION_EXISTS: session exists (without--if-missing)13/DIRTY_WORKTREE: switching source blocked due to a dirty worktree14/LOCKED: concurrent operation20/NOT_GIT: not a git repo
Usage
diffk commit --title "<msg>" [--paths <p1,p2,...>] [--signoff] [--no-verify] [--gpg-sign] [--co-author "Name <email>,..."] [--message-file <path>] [--allow-empty] [--output json]Description- On the session branch:
- Without
--paths: performsgit add -A(honors.gitignore) then commits. - With
--paths: commit only listed files. --message-file: read full commit message from file;--allow-empty: allow empty commit. Examples
- Without
- All changes:
diffk commit --title "AI: update" --output json - Selected files:
diffk commit --title "AI: partial" --paths "a,b" --output json - Long message:
diffk commit --message-file COMMIT_MSG.txt --output jsonExit codes 12/NO_SESSION,14/LOCKED,15/NOTHING_TO_COMMIT,20/NOT_GIT
Usage
diffk stage --stdin | --patch-file <path> [--three-way] [--unidiff-zero] [--recount] [--whitespace nowarn|warn|error] [--reverse] [--check-only] [--output json]Description- Applies unified diff hunks to the staging area (index) only; working tree remains unchanged.
- Performs a pre-check (
git apply --cached --check);--check-onlyvalidates without writing. - Defaults enable
--three-way,--unidiff-zero,--recountfor better tolerance;--reverseif your patch direction is inverted. - TTY:
--stdinon an interactive terminal waits for input or EOF (Ctrl-D); use pipe/redirect or--patch-filein automation. Examples - Pre-check:
diffk stage --stdin --check-only --output json < patch.diff - Apply:
diffk stage --stdin --output json < patch.diff - From file:
diffk stage --patch-file patch.diff --output jsonExit codes 12/NO_SESSION,20/NOT_GIT,41/PATCH_APPLY_FAILED,50/INTERNAL (read failure)
Usage
diffk squash --strategy reset-soft|merge-squash [--message "<msg>"] [--output json]Description- Squash all commits since the session base.
merge-squashcurrently behaves likereset-soft(simplified). Examplesdiffk squash --message "Squash: AI session summary" --output jsonExit codes12/NO_SESSION,20/NOT_GIT
Usage
diffk merge --to <branch> --strategy squash|no-ff|ff-only [--dry-run] [--message "<msg>"|--message-file <path>] [--output json]Description- Merge the session branch back (default to source).
--dry-run: usemerge-treeto detect conflicts without modifying working tree.- Messages:
squash: if no message provided, default isSquash merge from <session-branch>;no-ff: with message uses-m; without message uses--no-editto accept Git default;ff-only: fast-forward; no merge commit. Examples
- Dry-run:
diffk merge --to main --strategy=squash --dry-run --output json - Merge:
diffk merge --to main --strategy=squash --message "Squash: session" --output jsonExit codes 10/CONFLICT,12/NO_SESSION,14/LOCKED,20/NOT_GIT,2/INVALID_ARGS
Usage
diffk end [--keep-branch] [--force-delete] [--output json]Description- Cleanup metadata; default safe branch delete (
-d);--force-deleteuses-D. Examples diffk end --output jsonExit codes12/NO_SESSION,20/NOT_GIT
Usage
diffk abort [--hard] [--output json]Description- new-branch: switch back to source and delete session branch (
--hardto force). - current-branch: reset to base commit (
--harddiscards working tree changes). Examples diffk abort --hard --output jsonExit codes12/NO_SESSION,20/NOT_GIT
Usage
diffk help/diffk help <command>/diffk help codes[optionally--output json] Description- Top-level / per-command help / exit codes overview.
--output jsonreturns structured help (name, usage, options, examples, exitCodes, seeAlso). Examplesdiffk helpdiffk help merge --output json
Usage
diffk version [--output json]Description- Show CLI version; supports JSON output. Examples
diffk version --output json
Usage
diffk doctor [--output json]Description- Scan for common issues and suggestions (e.g.,
.gitignorepresence). Examples diffk doctor --output json
Appendix: Error Codes → Actions (quick list)
20/NOT_GIT: run from repo root or use--repo12/NO_SESSION: rundiffk initfirst13/DIRTY_WORKTREE: retryinitwith--dirty=stash(or clean first)14/LOCKED: serialize operations, short back-off retry; if a crash left a stale lock, remove.git/diffkeeper/lockonce nodiffkis active15/NOTHING_TO_COMMIT: modify files or pass--paths41/PATCH_APPLY_FAILED: recompute/align patch or sync working tree10/CONFLICT: resolve conflicts and commit, then retry merge2/INVALID_ARGS: check command signature; usediffk help <command>100/50/INTERNAL: add--debugand inspect stderr