{"record":{"id":"b1a1845e0dc37bfd","repo":"eyaltoledano/claude-task-master","slug":"clear-failed","errorCode":"CLEAR_FAILED","errorMessage":"Failed to clear context: ${(error as Error).message}","messagePattern":"Failed to clear context: (.+?)","errorType":"error_code","errorClass":"AuthenticationError","httpStatus":null,"severity":"error","filePath":"packages/tm-core/src/modules/auth/services/context-store.ts","lineNumber":160,"sourceCode":"\tclearUserContext(): void {\n\t\tconst existing = this.getContext();\n\t\tif (existing) {\n\t\t\tconst { selectedContext, ...rest } = existing;\n\t\t\tthis.saveContext(rest);\n\t\t}\n\t}\n\n\t/**\n\t * Clear all context\n\t */\n\tclearContext(): void {\n\t\ttry {\n\t\t\tif (fs.existsSync(this.contextPath)) {\n\t\t\t\tfs.unlinkSync(this.contextPath);\n\t\t\t\tthis.logger.debug('Cleared context from disk');\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tthrow new AuthenticationError(\n\t\t\t\t`Failed to clear context: ${(error as Error).message}`,\n\t\t\t\t'CLEAR_FAILED',\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Check if context exists\n\t */\n\thasContext(): boolean {\n\t\treturn this.getContext() !== null;\n\t}\n\n\t/**\n\t * Get context file path\n\t */\n\tgetContextPath(): string {","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/packages/tm-core/src/modules/auth/services/context-store.ts#L142-L178","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nawait auth.logout(); // CLEAR_FAILED on locked file\n// after\ntry {\n  await auth.logout();\n} catch (e) {\n  if (e instanceof AuthenticationError && e.code === 'CLEAR_FAILED') {\n    console.warn('Remove context file manually:', contextPath);\n  }\n}","handlingStrategy":"try-catch","validationCode":"import fs from 'fs';\nif (fs.existsSync(contextPath)) {\n  fs.accessSync(contextPath, fs.constants.W_OK); // throws early if not deletable\n  fs.unlinkSync(contextPath);\n}","typeGuard":"function isClearFailedError(e: unknown): e is AuthenticationError {\n  return e instanceof AuthenticationError && e.code === 'CLEAR_FAILED';\n}","tryCatchPattern":"try {\n  await auth.logout();\n} catch (e) {\n  if (isClearFailedError(e)) {\n    console.warn('Could not delete context file automatically:', e.message);\n    console.warn(`Remove it manually: rm ${contextPath}`);\n  } else throw e;\n}","preventionTips":["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"],"tags":["filesystem","auth","logout"],"backgroundTag":"context-clear-failed","analyzedSha":"c0c98d367c55296bfe69e65680625b6db437af02","analyzedAt":"2026-08-29T02:56:26.071Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}