context-restore
Bir skill ya da command çağrısına, dosyası session onu yükledikten sonra diskte değiştiyse dosyanın güncel metnini veren ve diskte değişen bir rules dosyasını modele veren bir Claude Code Mod'u.
Ne yapar
Claude Code 2.1.280 üzerinde ölçüldü:
- Engine her skill ve command'ı bir kere yükler ve dosyası diskte değişse de her çağrıda o kopyayı verir. Yazılan bir
/nameeski metni gönderir, bir Skill tool çağrısıSkill /<name> is already loaded above; instructions unchanged.cevabını verir. - Compaction'ın kestiği bir skill yeniden çağrıldığında, yazılarak ya da Skill tool ile, engine onu kendisi bütün olarak yeniden gönderir. Mod bu durumda bir şey yapmaz.
- İki prompt arasında değişen bir rules dosyası bir compaction'a kadar modele ulaşmaz.
Bu yüzden mod iki şey yapar:
- Bir skill ya da command'ın her çağrısında (
/nameyazılarak, Skill tool ile çağrılarak ya da bir subagent'a önceden yüklenerek) metnin geldiği dosyayı okur. Bir skill dizinini ilk satırında adlandırır (Base directory for this skill: <dizin>), yani dosyası<dizin>/SKILL.mdolur. Bir command'ın dosyası aranır:<plugin>:<ad>için plugin'incommands/<ad>.mddosyası, değilse projenin ya da sizincommands/<ad>.mddosyanız. Built-in bir command'ın dosyası yoktur.- Placeholder taşımayan bir dosya engine'in metniyle karşılaştırılır. Farklıysa engine'in kopyasının yerine dosyanın metni konur ve engine'in arkasına eklediği argümanlar (
ARGUMENTS: ...) kalır. Engine o zaman yeni metni gönderir, bir Skill tool çağrısında da. - Placeholder taşıyan bir dosya (
$ARGUMENTS,$1,${...},!`...`) karşılaştırılamaz, çünkü engine onları doldurmuştur. Dosya session başladıktan sonra yazıldıysa engine'in doldurulmuş metni kalır ve dosyanın güncel metni onun ardından gelir, yukarıdaki talimatların yerine geçtiğini ve yukarıdaki argümanların hâlâ geçerli olduğunu söyleyen bir not ile. - Yeniden çağrılmayan bir skill ya da command yeniden gönderilmez.
- Placeholder taşımayan bir dosya engine'in metniyle karşılaştırılır. Farklıysa engine'in kopyasının yerine dosyanın metni konur ve engine'in arkasına eklediği argümanlar (
instructionsattachment'ının taşıdığı her rules dosyasını kaydeder (her biriContents of <yol> (ile başlar ve yalnız içinde/rules/geçen yol sayılır). Gönderdiğiniz her prompt'ta, session onu okuduktan sonra yazılmış bir rules dosyası o prompt ile modele yalnız modelin okuduğu bir not olarak gider: dosya ve öncekinin yerine geçen güncel metni. Her değişiklik bir kere gönderilir.
Her olay için sidebar stream'inde, sidebar kapalıyken transcript'te tek satır okursunuz:
context-restore: changed on disk, the call got the current text: commit
context-restore: changed on disk, the new text went to the model: context7.md
/context-restore ayarı, kaç rules dosyasının izlendiğini ve son olayı yazar.
Komut
/context-restore ayar, izlenenler ve son olay
/context-restore on | off varsayılan on
Kurulum
claude plugin marketplace add KilimcininKorOglu/claude-code-mods
claude plugin install context-restore@kilimcininkoroglu-mods
Function hook'lar early access. Flag olmadan hiçbir şey yüklenmez. Flag'i kalıcı yapmak için ~/.claude/settings.json dosyasına ekleyin:
{ "env": { "CLAUDE_CODE_ENABLE_FUNCTION_HOOKS": "1" } }
Kurulumdan sonra
- Claude Code'u yeniden başlatın.
- Olay satırları için sidebar mod'unu kurun. O olmadan mod satırları transcript'e yazar.
Nereye uzanır
Claude Code 2.1.280 üzerinde claude plugin validate ile doğrulandı:
❯ ./register.ts hooks: session.start, command.run{command=context-restore}, skill.prompt, prompt.attachment{type=instructions}, prompt.submit
❯ ./register.ts calls: $.clock.now, $.command.register, $.env.get, $.fs.exists (via commandFileOf, mtimeOf, pluginDirs), $.fs.read (via changedRules, pluginDirs, readBody), $.fs.stat (via mtimeOf), $.sidebar.set (via toPerson), $.store.get, $.store.set (via setEnabled), $.ui.log
❯ ./register.ts env reads: CLAUDE_CONFIG_DIR, HOME
Reach L1, dosya okur.
1. Okur: session'ın çağırdığı her skill ve command'ın dosyasını ve son yazılma zamanını; session'ın okuduğu rules dosyalarını ve son yazılma zamanlarını; bir plugin'in command dosyasını bulmak için host'un installed_plugins.json dosyasını
2. Çalıştırır: hiçbir şey
3. Gönderir: modele, dosyası değişmiş çağrılan bir skill ya da command'ın güncel metnini, ve diskte değişen okunmuş bir rules dosyasının metnini
4. Saklar: $.store içinde on/off ayarını; rules kayıtları bellekte yaşar ve session ile biter
5. Düşman girdi: gönderilen her metin session'ın kendisinin kullandığı bir dosyadır; düşman metin taşıyan bir skill ya da rules dosyası modele engine üzerinden de ulaşır
Sınırlar
- Placeholder taşıyan bir dosya, son yazılma zamanı session'ın başlangıcıyla karşılaştırılarak değişmiş sayılır.
/reload-pluginssonrası mod reload anından sayar, yani ondan önce yapılan bir değişiklik görülmez. - Placeholder taşıyan bir dosyanın güncel metni engine'in metninden sonra, placeholder'ları doldurulmadan gelir.
- Dosyası mod'un baktığı iki yerde de olmayan bir command (
--plugin-dirile yüklenen bir plugin, iç içe bir command adı) engine'in metnini korur. - Değişen bir rules dosyası modele yazıldığı anda değil, sonraki prompt ile gider. Değişiklik ile sonraki prompt arasına bir compaction girerse dosyayı engine de gönderir.
- CLAUDE.md izlenmez.
Geliştirme
make install # eslint, typescript-eslint, typescript
make lint # complexity limiti 10, üstünde build'i düşürür
make typecheck # /plugin-types ile üretilen .claude/types/ gerekir
make validate
make test # claude plugin test
context-restore
A Claude Code Mod that hands a skill or command call the current text of its file when the file changed on disk after the session loaded it, and hands the model a rules file that changed on disk.
What it does
Measured on Claude Code 2.1.280:
- The engine loads each skill and command once, and hands that copy at every call, also after its file changed on disk. A typed
/namesends the old text, and a Skill tool call answersSkill /<name> is already loaded above; instructions unchanged. - A skill that compaction cut is sent whole again by the engine itself when it is called again, typed or through the Skill tool. The mod does nothing for that case.
- A rules file that changes between two prompts does not reach the model until a compaction.
So the mod does two things:
- At each call of a skill or command (typed as
/name, called through the Skill tool, or preloaded into a subagent), it reads the file the text came from. A skill names its directory in its first line (Base directory for this skill: <dir>), so its file is<dir>/SKILL.md. A command's file is looked up: a plugin'scommands/<name>.mdfor<plugin>:<name>, else the project's or your owncommands/<name>.md. A built-in command has no file.- A file with no placeholder is compared with the engine's text. When they differ, the file's text takes the place of the engine's copy, and the arguments the engine added after it (
ARGUMENTS: ...) stay. The engine then sends the new text, also on a Skill tool call. - A file with placeholders (
$ARGUMENTS,$1,${...},!`...`) cannot be compared, because the engine filled them in. When the file was written after the session started, the engine's filled text stays and the file's current text follows it, with a note that it replaces the instructions above and that the arguments above still apply. - A skill or command that is not called again is not sent again.
- A file with no placeholder is compared with the engine's text. When they differ, the file's text takes the place of the engine's copy, and the arguments the engine added after it (
- It records every rules file the
instructionsattachment carries (each starts withContents of <path> (, and only a path with/rules/in it counts). At each prompt you send, a rules file written since the session read it reaches the model with that prompt, as a note only the model reads: the file, and its current text, which replaces the earlier one. Each change is sent once.
You read one line per event in the sidebar stream, or in the transcript while the sidebar is closed:
context-restore: changed on disk, the call got the current text: commit
context-restore: changed on disk, the new text went to the model: context7.md
/context-restore prints the setting, how many rules files are watched, and the last event.
Command
/context-restore the setting, what is watched, and the last event
/context-restore on | off on by default
Install
claude plugin marketplace add KilimcininKorOglu/claude-code-mods
claude plugin install context-restore@kilimcininkoroglu-mods
Function hooks are early access. Nothing loads without the flag. To keep it on, add this to ~/.claude/settings.json:
{ "env": { "CLAUDE_CODE_ENABLE_FUNCTION_HOOKS": "1" } }
After installing
- Restart Claude Code.
- Install the sidebar mod for the event lines. Without it the mod writes them to the transcript.
What it can reach
Validated with claude plugin validate on Claude Code 2.1.280:
❯ ./register.ts hooks: session.start, command.run{command=context-restore}, skill.prompt, prompt.attachment{type=instructions}, prompt.submit
❯ ./register.ts calls: $.clock.now, $.command.register, $.env.get, $.fs.exists (via commandFileOf, mtimeOf, pluginDirs), $.fs.read (via changedRules, pluginDirs, readBody), $.fs.stat (via mtimeOf), $.sidebar.set (via toPerson), $.store.get, $.store.set (via setEnabled), $.ui.log
❯ ./register.ts env reads: CLAUDE_CONFIG_DIR, HOME
Reach L1, it reads files.
1. Reads: the file of each skill and command the session calls, and its last write time; the rules files the session read, and their last write time; the host's installed_plugins.json, to find a plugin's command file
2. Runs: nothing
3. Sends: to the model, the current text of a called skill or command whose file changed, and the text of a read rules file that changed on disk
4. Persists: in $.store, the on/off setting; the rules records live in memory and end with the session
5. Hostile input: every text sent is a file the session itself uses; a skill or rules file that holds hostile text reaches the model through the engine as well
Limits
- A file with placeholders counts as changed by its last write time against the session's start. After
/reload-pluginsthe mod counts from the reload, so a change made before it is not seen. - A file with placeholders gets its current text after the engine's text, with the placeholders not filled in.
- A command whose file is in neither place the mod looks (a
--plugin-dirplugin, a nested command name) keeps the engine's text. - A changed rules file reaches the model with the next prompt, not at the moment it is written. When a compaction comes between the change and the next prompt, the engine sends the file too.
- CLAUDE.md is not watched.
Development
make install # eslint, typescript-eslint, typescript
make lint # complexity limit 10, fails the build above it
make typecheck # needs .claude/types/ from /plugin-types
make validate
make test # claude plugin test