{"id":"7f3eec38-68d4-4472-a7be-aa8c58b55cef","shortId":"MAtuDT","kind":"skill","title":"context-recovery","tagline":"Automatically recover working context after session compaction or when continuation is implied but context is missing. Works across Discord, Slack, Telegram, Signal, and other supported channels.","description":"# Context Recovery\n\nAutomatically recover working context after session compaction or when continuation is implied but context is missing. Works across Discord, Slack, Telegram, Signal, and other supported channels.\n\n**Use when**: Session starts with truncated context, user references prior work without specifying details, or compaction indicators appear.\n\n---\n\n## Triggers\n\n### Automatic Triggers\n- Session begins with a `<summary>` tag (compaction detected)\n- User message contains compaction indicators: \"Summary unavailable\", \"context limits\", \"truncated\"\n\n### Manual Triggers\n- User says \"continue\", \"did this happen?\", \"where were we?\", \"what was I working on?\"\n- User references \"the project\", \"the PR\", \"the branch\", \"the issue\" without specifying which\n- User implies prior work exists but context is unclear\n- User asks \"do you remember...?\" or \"we were working on...\"\n\n---\n\n## Recovery Workflow\n\n### Step 1: Detect Active Channel\n\nExtract from runtime context:\n- `channel` — discord | slack | telegram | signal | etc.\n- `channelId` — the specific channel/conversation ID\n- `threadId` — for threaded conversations (Slack, Discord threads)\n\n### Step 2: Read Channel History (Adaptive Depth)\n\n**Initial fetch:**\n```\nmessage:read\n  channel: <detected-channel>\n  channelId: <detected-channel-id>\n  limit: 50\n```\n\n**Adaptive expansion logic:**\n1. Parse timestamps from returned messages\n2. Calculate time span: `newest_timestamp - oldest_timestamp`\n3. If time span < 2 hours AND message count == limit:\n   - Read an additional 50 messages (using `before` parameter if supported)\n   - Repeat until time span ≥ 2 hours OR total messages ≥ 100\n4. Hard cap: 100 messages maximum (token budget constraint)\n\n**Thread-aware recovery (Slack/Discord):**\n```\n# If threadId is present, read thread messages first\nmessage:read\n  channel: <detected-channel>\n  threadId: <thread-id>\n  limit: 50\n\n# Then read the parent channel for broader context\nmessage:read\n  channel: <detected-channel>\n  channelId: <parent-channel-id>\n  limit: 30\n```\n\n**Parse for:**\n- Recent user requests (what was asked)\n- Recent assistant responses (what was done)\n- URLs, file paths, branch names, PR numbers\n- Incomplete actions (promises made but not fulfilled)\n- Project identifiers and working directories\n\n### Step 3: Read Session Logs (if available)\n\n```bash\n# Find most recent session files for this agent\nSESSION_DIR=$(ls -d ~/.clawdbot-*/agents/*/sessions 2>/dev/null | head -1)\nSESSIONS=$(ls -t \"$SESSION_DIR\"/*.jsonl 2>/dev/null | head -3)\n\nfor SESSION in $SESSIONS; do\n  echo \"=== Session: $SESSION ===\"\n  \n  # Extract user requests\n  jq -r 'select(.message.role == \"user\") | .message.content[0].text // empty' \"$SESSION\" | tail -20\n  \n  # Extract assistant actions (look for tool calls and responses)\n  jq -r 'select(.message.role == \"assistant\") | .message.content[]? | select(.type == \"text\") | .text // empty' \"$SESSION\" | tail -50\ndone\n```\n\n### Step 4: Check Shared Memory\n\n```bash\n# Extract keywords from channel history (project names, PR numbers, branch names)\n# Search memory for relevant entries\ngrep -ri \"<keyword>\" ~/clawd-*/memory/ 2>/dev/null | head -10\n\n# Check for recent daily logs\nls -t ~/clawd-*/memory/202*.md 2>/dev/null | head -3 | xargs grep -l \"<keyword>\" 2>/dev/null\n```\n\n### Step 5: Synthesize Context\n\nCompile a structured summary:\n\n```markdown\n## Recovered Context\n\n**Channel:** #<channel-name> (<platform>)\n**Time Range:** <oldest-message> to <newest-message>\n**Messages Analyzed:** <count>\n\n### Active Project/Task\n- **Repository:** <repo-name>\n- **Branch:** <branch-name>\n- **PR:** #<number> — <title>\n\n### Recent Work Timeline\n1. [<timestamp>] <action/request>\n2. [<timestamp>] <action/request>\n3. [<timestamp>] <action/request>\n\n### Pending/Incomplete Actions\n- ⏳ \"<quoted incomplete action>\"\n- ⏳ \"<another incomplete item>\"\n\n### Key References\n| Type | Value |\n|------|-------|\n| PR | #<number> |\n| Branch | <name> |\n| Files | <paths> |\n| URLs | <links> |\n\n### Last User Request\n> \"<quoted request that may not have been completed>\"\n\n### Confidence Level\n- Channel context: <high/medium/low>\n- Session logs: <available/partial/unavailable>\n- Memory entries: <found/none>\n```\n\n### Step 6: Cache Recovered Context\n\n**Persist to memory for future reference:**\n\n```bash\n# Write to daily memory file\nMEMORY_FILE=~/clawd-*/memory/$(date +%Y-%m-%d).md\n\ncat >> \"$MEMORY_FILE\" << EOF\n\n## Context Recovery — $(date +%H:%M)\n\n**Channel:** #<channel-name>\n**Recovered context for:** <project/task summary>\n\n### Key State\n- <bullet points of critical context>\n\n### Pending Items\n- <incomplete actions>\n\nEOF\n```\n\nThis ensures context survives future compactions.\n\n## Safety Boundaries\n\n- Do not scan unrelated channels, projects, or workspaces when the active thread already gives enough context.\n- Do not overwrite memory files; append a short recovery note instead.\n- Do not persist secrets, tokens, or private message content that is not necessary for continuity.\n- Do not claim recovery is complete when the available history, logs, or memory sources are partial.\n\n### Step 7: Respond with Context\n\nPresent the recovered context, then prompt:\n\n> \"Context recovered. Your last request was [X]. This action [completed/did not complete]. Shall I [continue/retry/clarify]?\"\n\n---\n\n## Channel-Specific Notes\n\n### Discord\n- Use `channelId` from the incoming message metadata\n- Guild channels have full history access\n- Thread recovery: check for `threadId` in message metadata\n- DMs may have limited history\n\n### Slack\n- Use `channel` parameter with Slack channel ID\n- Thread context requires `threadId` — always check for thread context first\n- Parent channel fetch provides surrounding conversation context\n- May need workspace-level permissions for full history\n\n### Telegram / Signal / Others\n- Same `message:read` interface\n- History depth may vary by platform\n- Group vs. DM context may differ\n\n---\n\n## Constraints\n\n- **MANDATORY:** Execute this protocol before responding \"insufficient data\" or asking clarifying questions when context appears missing\n- Adaptive depth: start with 50, expand to 100 max\n- Time-based goal: capture at least 2 hours of context when possible\n- Session log extraction: last 3 session files maximum\n- Memory cache: append to daily file, do not overwrite\n- If recovery fails, state what was attempted and what data sources were unavailable\n\n---\n\n## Auto-Trigger Detection\n\nAt session start, scan for compaction indicators:\n\n```python\n# Pseudocode for trigger detection\nif message contains \"<summary>\":\n    trigger_context_recovery()\nelif message contains any of [\"Summary unavailable\", \"context limits\", \"truncated\", \"compacted\"]:\n    trigger_context_recovery()\nelif message matches continuation_patterns:\n    # \"continue\", \"where were we\", \"did this happen\", etc.\n    trigger_context_recovery()\n```\n\n**Do not wait for user to ask** — if compaction is detected, proactively recover and present context.\n\n---\n\n## Example\n\n**Scenario:** Session starts with compaction summary\n\n```\nUser message: \"<summary>Summary unavailable due to context limits...</summary>\"\nUser message: \"did this happen?\"\n```\n\n**Agent executes:**\n1. Detects compaction via `<summary>` tag\n2. `message:read channel=discord channelId=1460342116516364533 limit=50`\n3. Calculates time span: 2.5 hours — sufficient, no expansion needed\n4. Parses messages, finds last action: \"Now let me extract the key orchestration decisions...\"\n5. Checks session logs — extracts recent user requests\n6. Writes context summary to `memory/YYYY-MM-DD.md`\n7. Responds:\n\n> \"Context recovered. Your last request was to extract orchestration decisions from Nexus archived sessions for PR #137 (Skills & Agents System). This action did not complete before context was truncated.\n>\n> **Recovered state:**\n> - PR #137: 15,053 additions, 91 files, CONFLICTING merge state\n> - Spec location: `content/spec-skills-agents-system.md` (2,067 lines)\n> - Nexus sessions: `~/.clawdbot-duke-leto/archive/nexus-sessions/` (96 files)\n>\n> Shall I proceed with the extraction?\"\n\n## Privacy Guardrails (Required)\n\n- Default to minimum retrieval scope:\n  - last 24h or last 50 messages (whichever is smaller), unless user asks for more.\n- In DMs/private channels, require explicit user confirmation before broad history scans.\n- Do not persist recovered summaries to memory files without explicit approval.\n- Never include secrets/tokens in recovered summaries; replace with `[REDACTED]`.","tags":["context","recovery","agent","skills","jdrhyne","agent-skills","agentic-ai","ai-agents","automation","claude-code","clawdbot","codex"],"capabilities":["skill","source-jdrhyne","skill-context-recovery","topic-agent-skills","topic-agentic-ai","topic-ai-agents","topic-automation","topic-claude-code","topic-clawdbot","topic-codex","topic-cursor","topic-developer-tools","topic-gemini-cli","topic-github-copilot","topic-llm-agents"],"categories":["agent-skills"],"synonyms":[],"warnings":[],"endpointUrl":"https://skills.sh/jdrhyne/agent-skills/context-recovery","protocol":"skill","transport":"skills-sh","auth":{"type":"none","details":{"cli":"npx skills add jdrhyne/agent-skills","source_repo":"https://github.com/jdrhyne/agent-skills","install_from":"skills.sh"}},"qualityScore":"0.565","qualityRationale":"deterministic score 0.56 from registry signals: · indexed on github topic:agent-skills · 230 github stars · SKILL.md body (8,444 chars)","verified":false,"liveness":"unknown","lastLivenessCheck":null,"agentReviews":{"count":0,"score_avg":null,"cost_usd_avg":null,"success_rate":null,"latency_p50_ms":null,"narrative_summary":null,"summary_updated_at":null},"enrichmentModel":"deterministic:skill-github:v1","enrichmentVersion":1,"enrichedAt":"2026-04-22T06:54:18.127Z","embedding":null,"createdAt":"2026-04-18T22:04:54.513Z","updatedAt":"2026-04-22T06:54:18.127Z","lastSeenAt":"2026-04-22T06:54:18.127Z","tsv":"'-1':336 '-10':423 '-20':369 '-3':346,437 '-50':392 '/.clawdbot-':330 '/.clawdbot-duke-leto/archive/nexus-sessions':982 '/agents':331 '/clawd-':418,431,517 '/dev/null':334,344,421,435,442 '/memory':419,518 '/memory/202':432 '/sessions':332 '0':364 '053':967 '067':978 '1':147,191,468,879 '100':234,238,744 '137':949,965 '1460342116516364533':890 '15':966 '2':174,197,209,229,333,343,420,434,441,470,753,884,977 '2.5':897 '24h':1000 '3':205,311,472,763,893 '30':276 '4':235,395,903 '5':444,917 '50':187,218,262,741,892,1003 '6':499,925 '7':611,931 '91':969 '96':983 'access':653 'across':21,49 'action':299,372,475,629,908,954 'action/request':469,471,473 'activ':149,460,562 'adapt':178,188,737 'addit':217,968 'agent':325,877,951 'alreadi':564 'alway':679 'analyz':459 'appear':75,735 'append':573,769 'approv':1034 'archiv':945 'ask':135,284,730,847,1010 'assist':286,371,383 'attempt':782 'auto':790 'auto-trigg':789 'automat':4,32,77 'avail':316,602 'available/partial/unavailable':494 'awar':246 'base':748 'bash':317,399,509 'begin':80 'boundari':551 'branch':119,294,409,463,481 'broad':1021 'broader':269 'budget':242 'cach':500,768 'calcul':198,894 'call':376 'cap':237 'captur':750 'cat':524 'channel':29,57,150,155,176,184,259,267,273,403,454,489,533,556,637,649,669,673,686,887,1015 'channel-specif':636 'channel/conversation':164 'channelid':161,185,274,642,889 'check':396,424,656,680,918 'claim':596 'clarifi':731 'compact':10,38,73,84,89,549,798,821,849,862,881 'compil':447 'complet':599,632,957 'completed/did':630 'confid':487 'confirm':1019 'conflict':971 'constraint':243,720 'contain':88,807,813 'content':587 'content/spec-skills-agents-system.md':976 'context':2,7,17,30,35,45,64,93,131,154,270,446,453,490,502,528,535,546,567,614,618,621,676,683,691,717,734,756,809,818,823,839,856,870,927,933,959 'context-recoveri':1 'continu':13,41,100,593,828,830 'continue/retry/clarify':635 'convers':169,690 'count':213 'd':329,522 'daili':427,512,771 'data':728,785 'date':519,530 'decis':916,942 'default':994 'depth':179,709,738 'detail':71 'detect':85,148,792,804,851,880 'differ':719 'dir':327,341 'directori':309 'discord':22,50,156,171,640,888 'dm':716 'dms':662 'dms/private':1014 'done':290,393 'due':868 'echo':352 'elif':811,825 'empti':366,389 'enough':566 'ensur':545 'entri':415,496 'eof':527,543 'etc':160,837 'exampl':857 'execut':722,878 'exist':129 'expand':742 'expans':189,901 'explicit':1017,1033 'extract':151,355,370,400,761,912,921,940,990 'fail':778 'fetch':181,687 'file':292,322,482,514,516,526,572,765,772,970,984,1031 'find':318,906 'first':256,684 'found/none':497 'fulfil':304 'full':651,699 'futur':507,548 'give':565 'goal':749 'grep':416,439 'group':714 'guardrail':992 'guild':648 'h':531 'happen':103,836,876 'hard':236 'head':335,345,422,436 'high/medium/low':491 'histori':177,404,603,652,666,700,708,1022 'hour':210,230,754,898 'id':165,674 'identifi':306 'impli':15,43,126 'includ':1036 'incom':645 'incomplet':298 'indic':74,90,799 'initi':180 'instead':578 'insuffici':727 'interfac':707 'issu':121 'item':542 'jq':358,379 'jsonl':342 'key':476,539,914 'keyword':401 'l':440 'last':484,624,762,907,936,999,1002 'least':752 'let':910 'level':488,696 'limit':94,186,214,261,275,665,819,871,891 'line':979 'locat':975 'log':314,428,493,604,760,920 'logic':190 'look':373 'ls':328,338,429 'm':521,532 'made':301 'mandatori':721 'manual':96 'markdown':451 'match':827 'max':745 'maximum':240,766 'may':663,692,710,718 'md':433,523 'memori':398,412,495,505,513,515,525,571,606,767,1030 'memory/yyyy-mm-dd.md':930 'merg':972 'messag':87,182,196,212,219,233,239,255,257,271,458,586,646,660,705,806,812,826,865,873,885,905,1004 'message.content':363,384 'message.role':361,382 'metadata':647,661 'minimum':996 'miss':19,47,736 'name':295,406,410 'necessari':591 'need':693,902 'never':1035 'newest':201 'nexus':944,980 'note':577,639 'number':297,408 'oldest':203 'orchestr':915,941 'other':703 'overwrit':570,775 'paramet':222,670 'parent':266,685 'pars':192,277,904 'partial':609 'path':293 'pattern':829 'pend':541 'pending/incomplete':474 'permiss':697 'persist':503,581,1026 'platform':713 'possibl':758 'pr':117,296,407,464,480,948,964 'present':252,615,855 'prior':67,127 'privaci':991 'privat':585 'proactiv':852 'proceed':987 'project':115,305,405,557 'project/task':461,537 'promis':300 'prompt':620 'protocol':724 'provid':688 'pseudocod':801 'python':800 'question':732 'r':359,380 'rang':456 'read':175,183,215,253,258,264,272,312,706,886 'recent':279,285,320,426,465,922 'recov':5,33,452,501,534,617,622,853,934,962,1027,1039 'recoveri':3,31,144,247,529,576,597,655,777,810,824,840 'redact':1043 'refer':66,113,477,508 'relev':414 'rememb':138 'repeat':225 'replac':1041 'repositori':462 'request':281,357,486,625,924,937 'requir':677,993,1016 'respond':612,726,932 'respons':287,378 'retriev':997 'return':195 'ri':417 'runtim':153 'safeti':550 'say':99 'scan':554,796,1023 'scenario':858 'scope':998 'search':411 'secret':582 'secrets/tokens':1037 'select':360,381,385 'session':9,37,60,79,313,321,326,337,340,348,350,353,354,367,390,492,759,764,794,859,919,946,981 'shall':633,985 'share':397 'short':575 'signal':25,53,159,702 'skill':950 'skill-context-recovery' 'slack':23,51,157,170,667,672 'slack/discord':248 'smaller':1007 'sourc':607,786 'source-jdrhyne' 'span':200,208,228,896 'spec':974 'specif':163,638 'specifi':70,123 'start':61,739,795,860 'state':540,779,963,973 'step':146,173,310,394,443,498,610 'structur':449 'suffici':899 'summari':91,450,538,816,863,866,928,1028,1040 'support':28,56,224 'surround':689 'surviv':547 'synthes':445 'system':952 'tag':83,883 'tail':368,391 'telegram':24,52,158,701 'text':365,387,388 'thread':168,172,245,254,563,654,675,682 'thread-awar':244 'threadid':166,250,260,658,678 'time':199,207,227,455,747,895 'time-bas':746 'timelin':467 'timestamp':193,202,204 'token':241,583 'tool':375 'topic-agent-skills' 'topic-agentic-ai' 'topic-ai-agents' 'topic-automation' 'topic-claude-code' 'topic-clawdbot' 'topic-codex' 'topic-cursor' 'topic-developer-tools' 'topic-gemini-cli' 'topic-github-copilot' 'topic-llm-agents' 'total':232 'trigger':76,78,97,791,803,808,822,838 'truncat':63,95,820,961 'type':386,478 'unavail':92,788,817,867 'unclear':133 'unless':1008 'unrel':555 'url':291,483 'use':58,220,641,668 'user':65,86,98,112,125,134,280,356,362,485,845,864,872,923,1009,1018 'valu':479 'vari':711 'via':882 'vs':715 'wait':843 'whichev':1005 'without':69,122,1032 'work':6,20,34,48,68,110,128,142,308,466 'workflow':145 'workspac':559,695 'workspace-level':694 'write':510,926 'x':627 'xarg':438 'y':520","prices":[{"id":"852355b0-7c36-4301-a0e4-8c5fb9ca5273","listingId":"7f3eec38-68d4-4472-a7be-aa8c58b55cef","amountUsd":"0","unit":"free","nativeCurrency":null,"nativeAmount":null,"chain":null,"payTo":null,"paymentMethod":"skill-free","isPrimary":true,"details":{"org":"jdrhyne","category":"agent-skills","install_from":"skills.sh"},"createdAt":"2026-04-18T22:04:54.513Z"}],"sources":[{"listingId":"7f3eec38-68d4-4472-a7be-aa8c58b55cef","source":"github","sourceId":"jdrhyne/agent-skills/context-recovery","sourceUrl":"https://github.com/jdrhyne/agent-skills/tree/main/skills/context-recovery","isPrimary":false,"firstSeenAt":"2026-04-18T22:04:54.513Z","lastSeenAt":"2026-04-22T06:54:18.127Z"}],"details":{"listingId":"7f3eec38-68d4-4472-a7be-aa8c58b55cef","quickStartSnippet":null,"exampleRequest":null,"exampleResponse":null,"schema":null,"openapiUrl":null,"agentsTxtUrl":null,"citations":[],"useCases":[],"bestFor":[],"notFor":[],"kindDetails":{"org":"jdrhyne","slug":"context-recovery","github":{"repo":"jdrhyne/agent-skills","stars":230,"topics":["agent-skills","agentic-ai","ai-agents","automation","claude-code","clawdbot","codex","cursor","developer-tools","gemini-cli","github-copilot","llm-agents","mcp","openclaw","prompt-engineering","prompts"],"license":null,"html_url":"https://github.com/jdrhyne/agent-skills","pushed_at":"2026-03-27T14:29:53Z","description":"A collection of AI agent skills for Clawdbot, Claude Code, Codex","skill_md_sha":"a76432dd21b9fc93a45b51c71f0ae45587478bad","skill_md_path":"skills/context-recovery/SKILL.md","default_branch":"main","skill_tree_url":"https://github.com/jdrhyne/agent-skills/tree/main/skills/context-recovery"},"layout":"multi","source":"github","category":"agent-skills","frontmatter":{"name":"context-recovery","description":"Automatically recover working context after session compaction or when continuation is implied but context is missing. Works across Discord, Slack, Telegram, Signal, and other supported channels."},"skills_sh_url":"https://skills.sh/jdrhyne/agent-skills/context-recovery"},"updatedAt":"2026-04-22T06:54:18.127Z"}}