eyaltoledano/claude-task-master · error · AuthenticationError
CLEAR_FAILED
CLEAR_FAILED
Error message
Failed to clear context: ${(error as Error).message} What it means
ContextStore.clearContext deletes the context file (unlinkSync) when it exists. Any filesystem error during deletion is wrapped as AuthenticationError with code CLEAR_FAILED including the OS message. It is invoked by the logout flow.
Source
Thrown at packages/tm-core/src/modules/auth/services/context-store.ts:160
clearUserContext(): void {
const existing = this.getContext();
if (existing) {
const { selectedContext, ...rest } = existing;
this.saveContext(rest);
}
}
/**
* Clear all context
*/
clearContext(): void {
try {
if (fs.existsSync(this.contextPath)) {
fs.unlinkSync(this.contextPath);
this.logger.debug('Cleared context from disk');
}
} catch (error) {
throw new AuthenticationError(
`Failed to clear context: ${(error as Error).message}`,
'CLEAR_FAILED',
error
);
}
}
/**
* Check if context exists
*/
hasContext(): boolean {
return this.getContext() !== null;
}
/**
* Get context file path
*/
getContextPath(): string {View on GitHub (pinned to c0c98d367c)
Solutions
- Check/fix permissions on the context file and its directory (chown/chmod)
- Close other processes holding the file and retry logout
- If only permissions block it, delete the file manually and rerun
- Catch AuthenticationError code CLEAR_FAILED and fall back to manual cleanup instructions
Example fix
// before
await auth.logout(); // CLEAR_FAILED on locked file
// after
try {
await auth.logout();
} catch (e) {
if (e instanceof AuthenticationError && e.code === 'CLEAR_FAILED') {
console.warn('Remove context file manually:', contextPath);
}
} Defensive patterns
Strategy: try-catch
Validate before calling
import fs from 'fs';
if (fs.existsSync(contextPath)) {
fs.accessSync(contextPath, fs.constants.W_OK); // throws early if not deletable
fs.unlinkSync(contextPath);
} Type guard
function isClearFailedError(e: unknown): e is AuthenticationError {
return e instanceof AuthenticationError && e.code === 'CLEAR_FAILED';
} Try / catch
try {
await auth.logout();
} catch (e) {
if (isClearFailedError(e)) {
console.warn('Could not delete context file automatically:', e.message);
console.warn(`Remove it manually: rm ${contextPath}`);
} else throw e;
} Prevention
- Keep context files owned by the same user running the CLI (avoid sudo mixing)
- Close concurrent CLI instances that may lock the file on Windows
- Check filesystem writability before logout/cleanup in containers
- Treat CLEAR_FAILED as recoverable via manual file removal
When it happens
Trigger: Calling clearContext (e.g. during logout) when unlinkSync fails: permission denied on the file or parent directory, file locked by another process, or read-only filesystem.
Common situations: Context file owned by another user (ran as sudo earlier); Windows file lock from another CLI instance; read-only mounted config dir in containers/CI.
Related errors
AI-assisted analysis of eyaltoledano/claude-task-master@c0c98d367c (2026-08-29).
Data as JSON: /api/errors/b1a1845e0dc37bfd.
Report an issue: GitHub.