{"id":"6d502c22-b6fe-40ee-b60f-4c53c1111cbc","shortId":"ZqxVSD","kind":"skill","title":"agent-memory","tagline":"Teach cross-session memory patterns using MEMORY.md — what to save, how to organize it, how to maintain it over time, and how to structure topic files as memory grows. Works in any Claude Code project with no external dependencies. Trigger words: remember this, save for later, ac","description":"# agent-memory — Cross-Session Memory Patterns for Claude Code\n\nClaude Code has no memory between sessions by default. Every conversation starts blank. But a project's knowledge accumulates — commands discovered, patterns debugged, preferences revealed, mistakes made and corrected. Without persistence, that knowledge is lost every time the window closes.\n\nThis skill establishes a simple, durable memory pattern using a single file: `MEMORY.md`.\n\n---\n\n## The Core Pattern\n\nOne file. Written by the agent. Read at session start.\n\n```\n.claude/\n  MEMORY.md          # The agent's persistent knowledge base\n  identity/          # Optional: separate identity files (see agent-identity skill)\n  memory/            # Optional: topic files as memory grows\n    debugging.md\n    deployment.md\n    user-preferences.md\n```\n\n---\n\n## Setting Up MEMORY.md\n\nCreate `.claude/MEMORY.md` with this structure:\n\n```markdown\n# [Project/Agent] Memory\n\n> This file persists across sessions. Write here when you learn something\n> worth remembering. Remove entries that become outdated. Keep it useful,\n> not comprehensive.\n\n## Project Patterns\n\n[Commands, scripts, conventions specific to this project]\n\n## Tools & Scripts\n\n[Purpose-built scripts and how to invoke them]\n\n## Lessons Learned\n\n[Mistakes made and corrections. Dated entries.]\n\n## User Preferences\n\n[Communication style, workflow preferences, discovered through interaction]\n\n## Open Questions\n\n[Unresolved things to investigate — remove when resolved]\n```\n\nThen add this to your `CLAUDE.md`:\n\n```markdown\n## Memory\n\nAt the start of every session, read `.claude/MEMORY.md` before doing any work.\nAfter context compaction, re-read it immediately.\n\nWhen you learn something worth keeping, write it to MEMORY.md before the session ends.\n```\n\n---\n\n## What to Write vs. What to Skip\n\nThe most common mistake: writing everything, making the file so long it stops being read carefully.\n\n**Write to MEMORY.md:**\n\n- Project-specific commands, especially non-obvious ones\n  - \"Run `npm run build:prod` not `npm run build` — the latter overwrites staging\"\n- Scripts you built and their locations\n  - \".claude/scripts/check-email.py — reads Gmail unread, takes --limit flag\"\n- Mistakes made once that shouldn't happen again\n  - \"2025-03-12: Pushed to main while on detached HEAD. Always verify branch before committing.\"\n- User preferences discovered through interaction, not assumed\n  - \"Prefers Telegram summaries over file links\"\n- Patterns that took time to figure out\n  - \"Prisma requires explicit `include` for relations — no auto-eager-loading\"\n\n**Do not write to MEMORY.md:**\n\n- Session-specific context (\"currently working on auth PR\")\n- Information available in the codebase or docs\n- Reminders for things you'll do this session (use a TODO comment)\n- Generic programming knowledge any agent would have\n- Things that will be outdated next week\n\nThe test: *Would a fresh session six months from now benefit from this?* If no, skip it.\n\n---\n\n## Organizing Growing Memory\n\nMEMORY.md works well up to ~150-200 lines. Beyond that, introduce topic files:\n\n```bash\nmkdir -p .claude/memory\n```\n\nMove detailed sections to topic files and keep MEMORY.md as an index:\n\n```markdown\n# Memory Index\n\n## Quick Reference\n\n- Build: `npm run build:prod`\n- Deploy: `.claude/scripts/deploy.sh --env production`\n- DB migrate: `npm run db:migrate` (always after schema changes)\n\n## Topic Files\n\n- Debugging patterns: `.claude/memory/debugging.md`\n- Deployment notes: `.claude/memory/deployment.md`\n- User preferences: `.claude/memory/user-preferences.md`\n- API integrations: `.claude/memory/apis.md`\n\n## Recent Lessons\n\n[Last 3-5 lessons only — older ones move to topic files]\n```\n\nReference topic files in `CLAUDE.md`:\n\n```markdown\n## Memory\n\nRead at session start:\n- `.claude/MEMORY.md` — always\n- `.claude/memory/debugging.md` — when debugging\n- `.claude/memory/deployment.md` — when deploying\n```\n\n---\n\n## Writing Memory During a Session\n\nDon't wait until the session ends. Write memory entries when you learn something:\n\n```bash\n# Append an entry immediately\ncat >> .claude/MEMORY.md << 'EOF'\n\n## New Discovery (2025-03-20)\n\n- The Redis connection string requires `?family=6` for IPv6 — without it,\n  connections timeout silently on this server.\nEOF\n```\n\nWhen adding a dated lesson:\n\n```bash\nDATE=$(date +%Y-%m-%d)\ncat >> .claude/MEMORY.md << EOF\n\n## Lesson (${DATE})\n\n- [What happened, what was wrong, what the correct approach is]\nEOF\n```\n\n---\n\n## Maintaining Memory Over Time\n\nMemory files need occasional pruning — entries go stale, contexts change, projects evolve.\n\n**Review MEMORY.md when:**\n- Starting a major new phase of the project\n- A remembered pattern stops being true\n- The file grows past 200 lines\n\n**What to prune:**\n- Lessons from debugging a problem that's now fixed and closed\n- Preferences that were superseded\n- Scripts that no longer exist\n- Anything prefixed \"TODO\" that was resolved\n\n**What to archive, not delete:**\n- Significant debugging investigations (move to `.claude/memory/archive/`)\n- Historical context that might matter for understanding decisions\n\n---\n\n## Memory vs. Documentation\n\nMEMORY.md is not documentation. It's the agent's personal notebook.\n\n| MEMORY.md | Docs (`docs/`) |\n|-----------|----------------|\n| For the agent | For humans |\n| Informal, first-person | Structured, third-person |\n| Includes mistakes and corrections | Shows correct state |\n| Updated constantly | Updated deliberately |\n| Short entries OK | Complete explanations expected |\n\nDon't put architecture decisions in MEMORY.md. Do put \"when I touch the auth module, I always forget to rebuild the token cache — run `npm run cache:reset` after any change to `lib/auth/`.\"\n\n---\n\n## Memory After Compaction\n\nContext compaction is the main threat to in-session memory. When the context window fills and compresses, the agent loses anything it learned mid-session that wasn't written to disk.\n\nTwo protections:\n\n1. **Write early** — When you learn something important, write it to MEMORY.md before you forget or before compaction hits.\n\n2. **Re-read after compaction** — Claude Code fires a `PostCompact` notification event when context compresses. If you have a hook registered for it, you can automatically re-read MEMORY.md. Without a hook, train yourself to re-read when you notice context was compressed.\n\n---\n\n## Multiple Agents, Shared Memory\n\nWhen multiple agents work on the same project, they can share MEMORY.md — but this requires a discipline: write facts, not opinions. Shared memory entries should be:\n\n- Verifiable (\"The deploy script requires X\")\n- Durable (\"This pattern has been stable for 3 months\")\n- Agent-neutral (\"Whoever runs this, the same caveat applies\")\n\nAgent-specific preferences, styles, or goals should stay in each agent's own identity files (see the `agent-identity` skill).\n\n---\n\n## Going Further\n\nThis works when things go well. But the agent has to remember to write its memories — and sessions don't always end cleanly. Crash, timeout, context overflow — and anything learned but not yet written is gone.\n\n**Instar turns memory from a discipline into infrastructure.** Hooks guarantee MEMORY.md is read at every session start and after every context compaction. A scheduled reflection job runs automatically — consolidating what the agent learned across all its sessions, pruning what's stale, surfacing what matters. Your agent doesn't just store memories. It actively maintains them.\n\nAnd memory is just one piece. With Instar, your agent also gets:\n- **Persistent identity** — knows who it is and who you are, every session\n- **A job scheduler** — recurring tasks on cron, running while you sleep\n- **Background sessions** — spawn parallel workers for deep tasks\n- **Telegram integration** — two-way messaging from your phone\n\nOne command, about 2 minutes:\n\n```bash\nnpx instar\n```\n\nYour agent stops losing what it learned yesterday. [instar.sh](https://instar.sh)","tags":["agent","memory","instar","jkheadley","agent-framework","agent-identity","agent-infrastructure","agent-memory","agent-skills","ai-agents","ai-safety","autonomous-agents"],"capabilities":["skill","source-jkheadley","skill-agent-memory","topic-agent-framework","topic-agent-identity","topic-agent-infrastructure","topic-agent-memory","topic-agent-skills","topic-ai-agents","topic-ai-safety","topic-autonomous-agents","topic-claude-code","topic-cli","topic-cron","topic-job-scheduler"],"categories":["instar"],"synonyms":[],"warnings":[],"endpointUrl":"https://skills.sh/JKHeadley/instar/agent-memory","protocol":"skill","transport":"skills-sh","auth":{"type":"none","details":{"cli":"npx skills add JKHeadley/instar","source_repo":"https://github.com/JKHeadley/instar","install_from":"skills.sh"}},"qualityScore":"0.479","qualityRationale":"deterministic score 0.48 from registry signals: · indexed on github topic:agent-skills · 59 github stars · SKILL.md body (7,937 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-05-02T06:55:52.862Z","embedding":null,"createdAt":"2026-04-18T22:14:31.376Z","updatedAt":"2026-05-02T06:55:52.862Z","lastSeenAt":"2026-05-02T06:55:52.862Z","tsv":"'-03':349,590 '-12':350 '-20':591 '-200':467 '-5':532 '1':842 '150':466 '2':861,1132 '200':674 '2025':348,589 '3':531,950 '6':598 'ac':51 'accumul':81 'across':171,1055 'activ':1074 'ad':611 'add':238 'agent':2,53,124,132,144,431,734,743,826,908,913,953,963,973,981,994,1053,1067,1086,1138 'agent-ident':143,980 'agent-memori':1,52 'agent-neutr':952 'agent-specif':962 'also':1087 'alway':358,510,553,787,1006 'anyth':699,828,1014 'api':525 'append':580 'appli':961 'approach':634 'architectur':774 'archiv':707 'assum':369 'auth':406,784 'auto':391 'auto-eager-load':390 'automat':887,1049 'avail':409 'background':1112 'base':136 'bash':474,579,615,1134 'becom':184 'benefit':451 'beyond':469 'blank':75 'branch':360 'build':317,322,495,498 'built':204,329 'cach':793,797 'care':301 'cat':584,621 'caveat':960 'chang':513,650,801 'claud':37,61,63,129,867 'claude.md':242,545 'claude/memory':477 'claude/memory.md':161,252,552,585,622 'claude/memory/apis.md':527 'claude/memory/archive':715 'claude/memory/debugging.md':518,554 'claude/memory/deployment.md':521,557 'claude/memory/user-preferences.md':524 'claude/scripts/check-email.py':333 'claude/scripts/deploy.sh':501 'clean':1008 'close':102,689 'code':38,62,64,868 'codebas':412 'command':82,193,308,1130 'comment':426 'commit':362 'common':288 'communic':221 'compact':259,806,808,859,866,1043 'complet':768 'comprehens':190 'compress':824,876,906 'connect':594,603 'consolid':1050 'constant':762 'context':258,402,649,717,807,820,875,904,1011,1042 'convent':195 'convers':73 'core':117 'correct':91,216,633,757,759 'crash':1009 'creat':160 'cron':1107 'cross':6,56 'cross-sess':5,55 'current':403 'd':620 'date':217,613,616,617,625 'db':504,508 'debug':85,516,556,681,711 'debugging.md':154 'decis':723,775 'deep':1118 'default':71 'delet':709 'deliber':764 'depend':43 'deploy':500,519,559,939 'deployment.md':155 'detach':356 'detail':479 'disciplin':927,1027 'discov':83,225,365 'discoveri':588 'disk':839 'doc':414,739,740 'document':726,730 'doesn':1068 'durabl':108,943 'eager':392 'earli':844 'end':278,571,1007 'entri':182,218,574,582,646,766,934 'env':502 'eof':586,609,623,636 'especi':309 'establish':105 'event':873 'everi':72,98,249,1036,1041,1099 'everyth':291 'evolv':652 'exist':698 'expect':770 'explan':769 'explicit':385 'extern':42 'fact':929 'famili':597 'figur':381 'file':30,114,120,141,150,169,294,374,473,483,515,540,543,642,671,977 'fill':822 'fire':869 'first':748 'first-person':747 'fix':687 'flag':339 'forget':788,856 'fresh':445 'generic':427 'get':1088 'gmail':335 'go':647,984,990 'goal':968 'gone':1021 'grow':33,153,459,672 'guarante':1031 'happen':346,627 'head':357 'histor':716 'hit':860 'hook':881,894,1030 'human':745 'ident':137,140,145,976,982,1090 'immedi':264,583 'import':849 'in-sess':814 'includ':386,754 'index':489,492 'inform':408,746 'infrastructur':1029 'instar':1022,1084,1136 'instar.sh':1145,1146 'integr':526,1121 'interact':227,367 'introduc':471 'investig':233,712 'invok':209 'ipv6':600 'job':1047,1102 'keep':186,270,485 'know':1091 'knowledg':80,95,135,429 'last':530 'later':50 'latter':324 'learn':177,212,267,577,830,847,1015,1054,1143 'lesson':211,529,533,614,624,679 'lib/auth':803 'limit':338 'line':468,675 'link':375 'll':419 'load':393 'locat':332 'long':296 'longer':697 'lose':827,1140 'lost':97 'm':619 'made':89,214,341 'main':353,811 'maintain':21,637,1075 'major':658 'make':292 'markdown':165,243,490,546 'matter':720,1065 'memori':3,8,32,54,58,67,109,147,152,167,244,460,491,547,561,573,638,641,724,804,817,910,933,1001,1024,1072,1078 'memory.md':11,115,130,159,274,304,398,461,486,654,727,738,777,853,891,922,1032 'messag':1125 'mid':832 'mid-sess':831 'might':719 'migrat':505,509 'minut':1133 'mistak':88,213,289,340,755 'mkdir':475 'modul':785 'month':448,951 'move':478,537,713 'multipl':907,912 'need':643 'neutral':954 'new':587,659 'next':439 'non':311 'non-obvi':310 'note':520 'notebook':737 'notic':903 'notif':872 'npm':315,320,496,506,795 'npx':1135 'obvious':312 'occasion':644 'ok':767 'older':535 'one':119,313,536,1081,1129 'open':228 'opinion':931 'option':138,148 'organ':17,458 'outdat':185,438 'overflow':1012 'overwrit':325 'p':476 'parallel':1115 'past':673 'pattern':9,59,84,110,118,192,376,517,666,945 'persist':93,134,170,1089 'person':736,749,753 'phase':660 'phone':1128 'piec':1082 'postcompact':871 'pr':407 'prefer':86,220,224,364,370,523,690,965 'prefix':700 'prisma':383 'problem':683 'prod':318,499 'product':503 'program':428 'project':39,78,191,199,306,651,663,918 'project-specif':305 'project/agent':166 'protect':841 'prune':645,678,1059 'purpos':203 'purpose-built':202 'push':351 'put':773,779 'question':229 'quick':493 're':261,863,889,899 're-read':260,862,888,898 'read':125,251,262,300,334,548,864,890,900,1034 'rebuild':790 'recent':528 'recur':1104 'redi':593 'refer':494,541 'reflect':1046 'regist':882 'relat':388 'rememb':46,180,665,997 'remind':415 'remov':181,234 'requir':384,596,925,941 'reset':798 'resolv':236,704 'reveal':87 'review':653 'run':314,316,321,497,507,794,796,956,1048,1108 'save':14,48 'schedul':1045,1103 'schema':512 'script':194,201,205,327,694,940 'section':480 'see':142,978 'separ':139 'server':608 'session':7,57,69,127,172,250,277,400,422,446,550,564,570,816,833,1003,1037,1058,1100,1113 'session-specif':399 'set':157 'share':909,921,932 'short':765 'shouldn':344 'show':758 'signific':710 'silent':605 'simpl':107 'singl':113 'six':447 'skill':104,146,983 'skill-agent-memory' 'skip':285,456 'sleep':1111 'someth':178,268,578,848 'source-jkheadley' 'spawn':1114 'specif':196,307,401,964 'stabl':948 'stage':326 'stale':648,1062 'start':74,128,247,551,656,1038 'state':760 'stay':970 'stop':298,667,1139 'store':1071 'string':595 'structur':28,164,750 'style':222,966 'summari':372 'supersed':693 'surfac':1063 'take':337 'task':1105,1119 'teach':4 'telegram':371,1120 'test':442 'thing':231,417,434,989 'third':752 'third-person':751 'threat':812 'time':24,99,379,640 'timeout':604,1010 'todo':425,701 'token':792 'took':378 'tool':200 'topic':29,149,472,482,514,539,542 'topic-agent-framework' 'topic-agent-identity' 'topic-agent-infrastructure' 'topic-agent-memory' 'topic-agent-skills' 'topic-ai-agents' 'topic-ai-safety' 'topic-autonomous-agents' 'topic-claude-code' 'topic-cli' 'topic-cron' 'topic-job-scheduler' 'touch':782 'train':895 'trigger':44 'true':669 'turn':1023 'two':840,1123 'two-way':1122 'understand':722 'unread':336 'unresolv':230 'updat':761,763 'use':10,111,188,423 'user':219,363,522 'user-preferences.md':156 'verifi':359,937 'vs':282,725 'wait':567 'wasn':835 'way':1124 'week':440 'well':463,991 'whoever':955 'window':101,821 'without':92,601,892 'word':45 'work':34,256,404,462,914,987 'worker':1116 'workflow':223 'worth':179,269 'would':432,443 'write':173,271,281,290,302,396,560,572,843,850,928,999 'written':121,837,1019 'wrong':630 'x':942 'y':618 'yesterday':1144 'yet':1018","prices":[{"id":"e01b16b8-9bc8-4165-a4f6-7721ce56f9c0","listingId":"6d502c22-b6fe-40ee-b60f-4c53c1111cbc","amountUsd":"0","unit":"free","nativeCurrency":null,"nativeAmount":null,"chain":null,"payTo":null,"paymentMethod":"skill-free","isPrimary":true,"details":{"org":"JKHeadley","category":"instar","install_from":"skills.sh"},"createdAt":"2026-04-18T22:14:31.376Z"}],"sources":[{"listingId":"6d502c22-b6fe-40ee-b60f-4c53c1111cbc","source":"github","sourceId":"JKHeadley/instar/agent-memory","sourceUrl":"https://github.com/JKHeadley/instar/tree/main/skills/agent-memory","isPrimary":false,"firstSeenAt":"2026-04-18T22:14:31.376Z","lastSeenAt":"2026-05-02T06:55:52.862Z"}],"details":{"listingId":"6d502c22-b6fe-40ee-b60f-4c53c1111cbc","quickStartSnippet":null,"exampleRequest":null,"exampleResponse":null,"schema":null,"openapiUrl":null,"agentsTxtUrl":null,"citations":[],"useCases":[],"bestFor":[],"notFor":[],"kindDetails":{"org":"JKHeadley","slug":"agent-memory","github":{"repo":"JKHeadley/instar","stars":59,"topics":["agent-framework","agent-identity","agent-infrastructure","agent-memory","agent-skills","ai-agents","ai-safety","autonomous-agents","claude-code","cli","cron","job-scheduler","llm","mcp","npm-package","open-source","persistency","telegram-bot","typescript","whatsapp"],"license":"mit","html_url":"https://github.com/JKHeadley/instar","pushed_at":"2026-05-02T05:23:59Z","description":"Persistent Claude Code agents with scheduling, sessions, memory, and Telegram.","skill_md_sha":"a986a57f7aa1a41b590be418328374abcc2db1aa","skill_md_path":"skills/agent-memory/SKILL.md","default_branch":"main","skill_tree_url":"https://github.com/JKHeadley/instar/tree/main/skills/agent-memory"},"layout":"multi","source":"github","category":"instar","frontmatter":{"name":"agent-memory","license":"MIT","description":"Teach cross-session memory patterns using MEMORY.md — what to save, how to organize it, how to maintain it over time, and how to structure topic files as memory grows. Works in any Claude Code project with no external dependencies. Trigger words: remember this, save for later, across sessions, persistent memory, don't forget, note this, keep this, write this down."},"skills_sh_url":"https://skills.sh/JKHeadley/instar/agent-memory"},"updatedAt":"2026-05-02T06:55:52.862Z"}}