eyaltoledano/claude-task-master · error

working tree is not clean: ${this.projectPath} Staged: ${sum

Error message

working tree is not clean: ${this.projectPath}
Staged: ${summary.staged}, Modified: ${summary.modified}, Deleted: ${summary.deleted}, Untracked: ${summary.untracked}
Please commit or stash your changes before proceeding.

What it means

ensureCleanWorkingTree() reads simple-git status() and throws when status.isClean() is false, listing counts of staged, modified, deleted, and untracked files. Branch operations (createBranch with checkout, checkoutBranch, createAndCheckoutBranch) and startWorkflow() require a clean tree to avoid mixing uncommitted work into new branches. The error includes the project path and a per-category summary.

Source

Thrown at packages/tm-core/src/modules/git/adapters/git-adapter.ts:328

		};
	}

	/**
	 * Ensures the working tree is clean before performing operations.
	 * Throws an error with details if there are uncommitted changes.
	 *
	 * @returns {Promise<void>}
	 * @throws {Error} If working tree is not clean
	 *
	 * @example
	 * await git.ensureCleanWorkingTree();
	 * // Safe to perform git operations that require clean state
	 */
	async ensureCleanWorkingTree(): Promise<void> {
		const status = await this.git.status();
		if (!status.isClean()) {
			const summary = await this.getStatusSummary();
			throw new Error(
				`working tree is not clean: ${this.projectPath}\n` +
					`Staged: ${summary.staged}, Modified: ${summary.modified}, ` +
					`Deleted: ${summary.deleted}, Untracked: ${summary.untracked}\n` +
					`Please commit or stash your changes before proceeding.`
			);
		}
	}

	/**
	 * Gets the name of the current branch.
	 *
	 * @returns {Promise<string>} Current branch name
	 * @throws {Error} If unable to determine current branch
	 *
	 * @example
	 * const branch = await git.getCurrentBranch();
	 * console.log(`Currently on: ${branch}`);
	 */

View on GitHub (pinned to c0c98d367c)

Solutions

  1. Commit your work: git add -A && git commit -m 'wip before workflow'.
  2. Or stash it: git stash -u (includes untracked files).
  3. For checkoutBranch specifically, pass options.force to skip the clean-tree check.
  4. Add generated files to .gitignore so untracked artifacts don't count as changes.
  5. Check the counts in the error message to see which category (e.g. untracked) is blocking and clean accordingly.

Example fix

// before
await git.checkoutBranch('feature/x'); // throws: working tree not clean
// after
const clean = await git.isWorkingTreeClean();
if (!clean) await git.git.raw(['stash', '-u']); // or commit first
await git.checkoutBranch('feature/x');
Defensive patterns

Strategy: validation

Validate before calling

const summary = await git.getStatusSummary();
const dirty = summary.staged + summary.modified + summary.deleted + summary.untracked;
if (dirty > 0) {
  console.warn(`Tree not clean: ${JSON.stringify(summary)} — commit or stash first`);
}

Try / catch

try {
  await git.createAndCheckoutBranch('feature/x');
} catch (e) {
  if (e instanceof Error && e.message.startsWith('working tree is not clean')) {
    // offer stash: git stash -u, then retry
    throw e;
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling createBranch(name, {checkout:true}), checkoutBranch(name), createAndCheckoutBranch(name), or startWorkflow() while the working tree has any staged/unstaged changes or untracked files (and options.force is not set for checkoutBranch).

Common situations: Untracked log/build files flagged as changes; developer forgot to commit WIP; CI running on a checkout where the build step generated files before invoking the workflow; .gitignore missing for generated artifacts.

Related errors


AI-assisted analysis of eyaltoledano/claude-task-master@c0c98d367c (2026-08-29). Data as JSON: /api/errors/116c5867fb4c2dbb. Report an issue: GitHub.