gk ai compose commit
Create commits from a plan you authored over collected hunks (no AI)
Synopsis
Create commits from a plan that you (the calling agent) authored over the hunks listed by “gk ai compose collect”. No AI model is called and no AI credits are spent.
This differs from two similarly named commands: “gk ai commit” asks AI to write one commit message for one commit, and “gk ai compose apply” has AI plan and apply the grouping. Here the grouping and messages are yours.
The plan is passed with –input-json, inline or - for stdin:
{“commits”:[{“message”:”feat: add x”,”hunkIndices”:[0,1],”explanation”:”why”}]}
Every collected hunk must appear in exactly one commit; commits are created in the order given (dependencies first). message is the full commit message (subject, then a blank line and an optional body; use \n in JSON). explanation is an optional note about the grouping and is NOT written to the commit. Unknown fields are rejected. Show the user the plan before committing unless they already asked for these commits.
–dry-run validates the plan against the collection (the same checks as a real commit) and prints the commit/file layout without changing anything. It is this command’s own validation, not the generic dry-run preview.
If the changes were edited since collect, commit fails with details.reason “stale_collection” and modifies nothing: run collect again. Other reasons: invalid_plan (the message says what to fix), signing_failed, timed_out. Commits are signed when the repository sets commit.gpgsign.
–json returns {commits[{id,sha,subject}], undo_id, signed, undo_hint,
warnings?}; with –dry-run, {dry_run, commits[{id,message,hunkIndices,files}]}.
Undo with “gk ai compose undo
gk ai compose commit [flags]
Examples
gk ai compose commit --based-on <token> --input-json '{"commits":[{"message":"feat: add x","hunkIndices":[0,1]}]}' --workdir /path/to/repo
echo '{"commits":[...]}' | gk ai compose commit --based-on <token> --input-json - --workdir /path/to/repo
gk ai compose commit --based-on <token> --input-json - --dry-run --workdir /path/to/repo
Options
--based-on string Token printed by collect, verbatim (required)
--dry-run Validate the plan against the collection and show the commit/file layout without creating commits
-h, --help help for commit
--input-json string The plan as JSON, inline or - for stdin (required): {"commits":[{"message":"...","hunkIndices":[0,1],"explanation":"..."}]}. message is the full commit message (subject, blank line, optional body; use \n in JSON); explanation is an optional note about the grouping and is NOT written to the commit
Options inherited from parent commands
--json Emit machine-readable JSON on stdout (GK_OUTPUT=json sets it session-wide)
--no-telemetry Disable telemetry (OTel spans, Sentry) for this invocation
--session string (Optional) Isolate auth and cache under a named session
--workdir string Path to the git repository to operate on (default: current directory)
SEE ALSO
- gk ai compose - Plan and create clean, atomic commits from your working tree changes using AI