claude-agent 0.2.25

Rust SDK for building AI agents with Anthropic's Claude - Direct API, no CLI dependency
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
use std::collections::HashMap;
use std::path::{Path, PathBuf};

use serde::{Deserialize, Serialize};

use super::PluginError;
use super::manifest::PluginDescriptor;
use super::namespace;
use crate::common::SourceType;
use crate::config::HookConfig;
use crate::hooks::{HookEvent, HookRule};
use crate::mcp::McpServerConfig;
use crate::skills::{SkillIndex, SkillIndexLoader};
use crate::subagents::{SubagentIndex, SubagentIndexLoader};

const PLUGIN_ROOT_VAR: &str = "${CLAUDE_PLUGIN_ROOT}";

fn resolve_plugin_root(value: &str, root: &Path) -> String {
    value.replace(PLUGIN_ROOT_VAR, &root.display().to_string())
}

fn resolve_hook_config(config: HookConfig, root: &Path) -> HookConfig {
    match config {
        HookConfig::Command(cmd) => HookConfig::Command(resolve_plugin_root(&cmd, root)),
        HookConfig::Full {
            command,
            timeout_secs,
            matcher,
        } => HookConfig::Full {
            command: resolve_plugin_root(&command, root),
            timeout_secs,
            matcher,
        },
    }
}

fn resolve_mcp_config(config: McpServerConfig, root: &Path) -> McpServerConfig {
    match config {
        McpServerConfig::Stdio {
            command,
            args,
            env,
            cwd,
        } => McpServerConfig::Stdio {
            command: resolve_plugin_root(&command, root),
            args: args
                .into_iter()
                .map(|a| resolve_plugin_root(&a, root))
                .collect(),
            env: env
                .into_iter()
                .map(|(k, v)| (k, resolve_plugin_root(&v, root)))
                .collect(),
            cwd: cwd.map(|c| resolve_plugin_root(&c, root)),
        },
        other => other,
    }
}

/// Outer wrapper for hooks.json — supports both nested and flat formats.
#[derive(Debug, Deserialize)]
#[serde(untagged)]
enum PluginHooksFile {
    /// Nested format: `{"hooks": {"PreToolUse": [{"matcher": "...", "hooks": [...]}]}}`
    Nested {
        hooks: HashMap<String, Vec<HookRule>>,
    },
    /// Flat format: `{"PreToolUse": ["echo pre"]}`
    Flat(HashMap<String, Vec<HookConfig>>),
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PluginHookEntry {
    pub plugin: String,
    pub event: HookEvent,
    pub config: HookConfig,
    pub plugin_root: PathBuf,
}

#[derive(Debug, Default)]
pub struct PluginResources {
    pub skills: Vec<SkillIndex>,
    pub subagents: Vec<SubagentIndex>,
    pub hooks: Vec<PluginHookEntry>,
    pub mcp_servers: HashMap<String, McpServerConfig>,
}

pub struct PluginLoader;

impl PluginLoader {
    pub async fn load(plugin: &PluginDescriptor) -> Result<PluginResources, PluginError> {
        let plugin_name = plugin.name();
        let mut resources = PluginResources::default();

        Self::load_skills(plugin, plugin_name, &mut resources).await?;
        Self::load_commands(plugin, plugin_name, &mut resources).await?;
        Self::load_subagents(plugin, plugin_name, &mut resources).await?;
        Self::load_hooks(plugin, plugin_name, &mut resources).await?;
        Self::load_mcp(plugin, plugin_name, &mut resources).await?;

        Ok(resources)
    }

    async fn load_skills(
        plugin: &PluginDescriptor,
        plugin_name: &str,
        resources: &mut PluginResources,
    ) -> Result<(), PluginError> {
        let skills_dir = plugin.skills_dir();
        if !skills_dir.exists() {
            return Ok(());
        }

        let loader = SkillIndexLoader::new();
        let skills =
            loader
                .scan_directory(&skills_dir)
                .await
                .map_err(|e| PluginError::ResourceLoad {
                    plugin: plugin_name.to_string(),
                    message: format!("Skills: {e}"),
                })?;

        let plugin_root = plugin.root_dir();
        for mut skill in skills {
            skill.name = namespace::namespaced(plugin_name, &skill.name);
            skill.source_type = SourceType::Plugin;
            Self::collect_resource_hooks(
                &skill.hooks,
                plugin_name,
                plugin_root,
                &mut resources.hooks,
            );
            resources.skills.push(skill);
        }

        Ok(())
    }

    /// Load `commands/` directory (simple markdown files treated as skills).
    async fn load_commands(
        plugin: &PluginDescriptor,
        plugin_name: &str,
        resources: &mut PluginResources,
    ) -> Result<(), PluginError> {
        let commands_dir = plugin.commands_dir();
        if !commands_dir.exists() {
            return Ok(());
        }

        let loader = SkillIndexLoader::new();
        let mut entries =
            tokio::fs::read_dir(&commands_dir)
                .await
                .map_err(|e| PluginError::ResourceLoad {
                    plugin: plugin_name.to_string(),
                    message: format!("Commands dir: {e}"),
                })?;

        while let Some(entry) =
            entries
                .next_entry()
                .await
                .map_err(|e| PluginError::ResourceLoad {
                    plugin: plugin_name.to_string(),
                    message: format!("Commands entry: {e}"),
                })?
        {
            let path = entry.path();
            if !path.is_file() {
                continue;
            }
            let ext = path.extension().and_then(|e| e.to_str());
            if ext != Some("md") {
                continue;
            }

            let skill = match loader.load_file(&path).await {
                Ok(s) => s,
                Err(_) => continue,
            };

            let namespaced = namespace::namespaced(plugin_name, &skill.name);
            // Only add if not already loaded from skills/ (skills take precedence)
            if !resources.skills.iter().any(|s| s.name == namespaced) {
                let mut skill = skill;
                skill.name = namespaced;
                skill.source_type = SourceType::Plugin;
                resources.skills.push(skill);
            }
        }

        Ok(())
    }

    async fn load_subagents(
        plugin: &PluginDescriptor,
        plugin_name: &str,
        resources: &mut PluginResources,
    ) -> Result<(), PluginError> {
        let agents_dir = plugin.agents_dir();
        if !agents_dir.exists() {
            return Ok(());
        }

        let loader = SubagentIndexLoader::new();
        let subagents =
            loader
                .scan_directory(&agents_dir)
                .await
                .map_err(|e| PluginError::ResourceLoad {
                    plugin: plugin_name.to_string(),
                    message: format!("Agents: {e}"),
                })?;

        let plugin_root = plugin.root_dir();
        for mut subagent in subagents {
            subagent.name = namespace::namespaced(plugin_name, &subagent.name);
            subagent.source_type = SourceType::Plugin;
            Self::collect_resource_hooks(
                &subagent.hooks,
                plugin_name,
                plugin_root,
                &mut resources.hooks,
            );
            resources.subagents.push(subagent);
        }

        Ok(())
    }

    fn collect_resource_hooks(
        hooks: &Option<HashMap<String, Vec<HookRule>>>,
        plugin_name: &str,
        plugin_root: &Path,
        out: &mut Vec<PluginHookEntry>,
    ) {
        let Some(hooks_map) = hooks else { return };
        for (event_name, rules) in hooks_map {
            let Some(event) = HookEvent::from_pascal_case(event_name) else {
                continue;
            };
            for rule in rules {
                let matcher = rule.matcher.as_deref();
                for action in &rule.hooks {
                    if let Some(config) = action
                        .to_hook_config(matcher)
                        .map(|c| resolve_hook_config(c, plugin_root))
                    {
                        out.push(PluginHookEntry {
                            plugin: plugin_name.to_string(),
                            event,
                            config,
                            plugin_root: plugin_root.to_path_buf(),
                        });
                    }
                }
            }
        }
    }

    async fn load_hooks(
        plugin: &PluginDescriptor,
        plugin_name: &str,
        resources: &mut PluginResources,
    ) -> Result<(), PluginError> {
        let hooks_path = plugin.hooks_config_path();
        if !hooks_path.exists() {
            return Ok(());
        }

        let content = tokio::fs::read_to_string(&hooks_path).await?;
        let hooks_file: PluginHooksFile =
            serde_json::from_str(&content).map_err(|e| PluginError::InvalidManifest {
                path: hooks_path,
                reason: format!("hooks config: {e}"),
            })?;

        let plugin_root = plugin.root_dir();

        match hooks_file {
            PluginHooksFile::Nested { hooks } => {
                Self::collect_resource_hooks(
                    &Some(hooks),
                    plugin_name,
                    plugin_root,
                    &mut resources.hooks,
                );
            }
            PluginHooksFile::Flat(hooks_map) => {
                for (event_name, configs) in hooks_map {
                    let Some(event) = HookEvent::from_pascal_case(&event_name) else {
                        continue;
                    };
                    for mut config in configs {
                        config = resolve_hook_config(config, plugin_root);
                        resources.hooks.push(PluginHookEntry {
                            plugin: plugin_name.to_string(),
                            event,
                            config,
                            plugin_root: plugin_root.to_path_buf(),
                        });
                    }
                }
            }
        }

        Ok(())
    }

    async fn load_mcp(
        plugin: &PluginDescriptor,
        plugin_name: &str,
        resources: &mut PluginResources,
    ) -> Result<(), PluginError> {
        let mcp_path = plugin.mcp_config_path();
        if !mcp_path.exists() {
            return Ok(());
        }

        let content = tokio::fs::read_to_string(&mcp_path).await?;

        #[derive(Deserialize)]
        struct McpConfig {
            #[serde(rename = "mcpServers", default)]
            mcp_servers: HashMap<String, McpServerConfig>,
        }

        let config: McpConfig =
            serde_json::from_str(&content).map_err(|e| PluginError::InvalidManifest {
                path: mcp_path,
                reason: format!("MCP config: {e}"),
            })?;

        let plugin_root = plugin.root_dir();
        for (name, server_config) in config.mcp_servers {
            let namespaced_name = namespace::namespaced(plugin_name, &name);
            let resolved = resolve_mcp_config(server_config, plugin_root);
            resources.mcp_servers.insert(namespaced_name, resolved);
        }

        Ok(())
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use std::path::PathBuf;
    use tempfile::tempdir;

    use crate::plugins::manifest::PluginManifest;

    fn make_descriptor(root: PathBuf, name: &str) -> PluginDescriptor {
        PluginDescriptor::new(
            PluginManifest {
                name: name.into(),
                description: "test".into(),
                version: "1.0.0".into(),
                author: None,
                homepage: None,
                repository: None,
                license: None,
                keywords: Vec::new(),
            },
            root,
        )
    }

    #[tokio::test]
    async fn test_load_skills() {
        let dir = tempdir().unwrap();
        let skills_dir = dir.path().join("skills");
        std::fs::create_dir_all(&skills_dir).unwrap();
        std::fs::write(
            skills_dir.join("commit.skill.md"),
            "---\nname: commit\ndescription: Git commit\n---\nContent",
        )
        .unwrap();

        let descriptor = make_descriptor(dir.path().to_path_buf(), "my-plugin");
        let resources = PluginLoader::load(&descriptor).await.unwrap();

        assert_eq!(resources.skills.len(), 1);
        assert_eq!(resources.skills[0].name, "my-plugin:commit");
        assert_eq!(resources.skills[0].source_type, SourceType::Plugin);
    }

    #[tokio::test]
    async fn test_load_subagents() {
        let dir = tempdir().unwrap();
        let agents_dir = dir.path().join("agents");
        std::fs::create_dir_all(&agents_dir).unwrap();
        std::fs::write(
            agents_dir.join("reviewer.md"),
            "---\nname: reviewer\ndescription: Code reviewer\n---\nPrompt",
        )
        .unwrap();

        let descriptor = make_descriptor(dir.path().to_path_buf(), "my-plugin");
        let resources = PluginLoader::load(&descriptor).await.unwrap();

        assert_eq!(resources.subagents.len(), 1);
        assert_eq!(resources.subagents[0].name, "my-plugin:reviewer");
        assert_eq!(resources.subagents[0].source_type, SourceType::Plugin);
    }

    #[tokio::test]
    async fn test_load_hooks() {
        let dir = tempdir().unwrap();
        let hooks_dir = dir.path().join("hooks");
        std::fs::create_dir_all(&hooks_dir).unwrap();
        std::fs::write(
            hooks_dir.join("hooks.json"),
            r#"{"PreToolUse": ["echo pre"], "SessionStart": ["echo start"]}"#,
        )
        .unwrap();

        let descriptor = make_descriptor(dir.path().to_path_buf(), "my-plugin");
        let resources = PluginLoader::load(&descriptor).await.unwrap();

        assert_eq!(resources.hooks.len(), 2);
        assert!(
            resources
                .hooks
                .iter()
                .any(|h| h.event == HookEvent::PreToolUse)
        );
        assert!(
            resources
                .hooks
                .iter()
                .any(|h| h.event == HookEvent::SessionStart)
        );
    }

    #[tokio::test]
    async fn test_load_mcp() {
        let dir = tempdir().unwrap();
        std::fs::write(
            dir.path().join(".mcp.json"),
            r#"{"mcpServers":{"context7":{"type":"stdio","command":"npx","args":["@context7/mcp"]}}}"#,
        )
        .unwrap();

        let descriptor = make_descriptor(dir.path().to_path_buf(), "my-plugin");
        let resources = PluginLoader::load(&descriptor).await.unwrap();

        assert_eq!(resources.mcp_servers.len(), 1);
        assert!(resources.mcp_servers.contains_key("my-plugin:context7"));
    }

    #[tokio::test]
    async fn test_load_empty_plugin() {
        let dir = tempdir().unwrap();
        let descriptor = make_descriptor(dir.path().to_path_buf(), "empty");
        let resources = PluginLoader::load(&descriptor).await.unwrap();

        assert!(resources.skills.is_empty());
        assert!(resources.subagents.is_empty());
        assert!(resources.hooks.is_empty());
        assert!(resources.mcp_servers.is_empty());
    }

    #[tokio::test]
    async fn test_namespace_applied_to_all_resources() {
        let dir = tempdir().unwrap();

        // Create skills
        let skills_dir = dir.path().join("skills");
        std::fs::create_dir_all(&skills_dir).unwrap();
        std::fs::write(
            skills_dir.join("build.skill.md"),
            "---\nname: build\ndescription: Build project\n---\nBuild it",
        )
        .unwrap();

        // Create MCP
        std::fs::write(
            dir.path().join(".mcp.json"),
            r#"{"mcpServers":{"server1":{"type":"stdio","command":"cmd"}}}"#,
        )
        .unwrap();

        let descriptor = make_descriptor(dir.path().to_path_buf(), "acme");
        let resources = PluginLoader::load(&descriptor).await.unwrap();

        assert_eq!(resources.skills[0].name, "acme:build");
        assert!(resources.mcp_servers.contains_key("acme:server1"));
    }

    #[tokio::test]
    async fn test_load_hooks_official_format() {
        let dir = tempdir().unwrap();
        let hooks_dir = dir.path().join("hooks");
        std::fs::create_dir_all(&hooks_dir).unwrap();
        std::fs::write(
            hooks_dir.join("hooks.json"),
            r#"{
                "hooks": {
                    "PostToolUse": [
                        {
                            "matcher": "Write|Edit",
                            "hooks": [
                                {"type": "command", "command": "scripts/format.sh"}
                            ]
                        }
                    ],
                    "PreToolUse": [
                        {
                            "hooks": [
                                {"type": "command", "command": "scripts/check.sh", "timeout": 10}
                            ]
                        }
                    ]
                }
            }"#,
        )
        .unwrap();

        let descriptor = make_descriptor(dir.path().to_path_buf(), "my-plugin");
        let resources = PluginLoader::load(&descriptor).await.unwrap();

        assert_eq!(resources.hooks.len(), 2);

        let post = resources
            .hooks
            .iter()
            .find(|h| h.event == HookEvent::PostToolUse)
            .unwrap();
        match &post.config {
            HookConfig::Full {
                command, matcher, ..
            } => {
                assert_eq!(command, "scripts/format.sh");
                assert_eq!(matcher.as_deref(), Some("Write|Edit"));
            }
            _ => panic!("Expected Full config"),
        }

        let pre = resources
            .hooks
            .iter()
            .find(|h| h.event == HookEvent::PreToolUse)
            .unwrap();
        match &pre.config {
            HookConfig::Full {
                command,
                timeout_secs,
                ..
            } => {
                assert_eq!(command, "scripts/check.sh");
                assert_eq!(*timeout_secs, Some(10));
            }
            _ => panic!("Expected Full config with timeout"),
        }
    }

    #[tokio::test]
    async fn test_load_commands() {
        let dir = tempdir().unwrap();
        let commands_dir = dir.path().join("commands");
        std::fs::create_dir_all(&commands_dir).unwrap();
        std::fs::write(
            commands_dir.join("hello.md"),
            "---\nname: hello\ndescription: Greet user\n---\nHello!",
        )
        .unwrap();

        let descriptor = make_descriptor(dir.path().to_path_buf(), "my-plugin");
        let resources = PluginLoader::load(&descriptor).await.unwrap();

        assert_eq!(resources.skills.len(), 1);
        assert_eq!(resources.skills[0].name, "my-plugin:hello");
        assert_eq!(resources.skills[0].source_type, SourceType::Plugin);
    }

    #[tokio::test]
    async fn test_skills_take_precedence_over_commands() {
        let dir = tempdir().unwrap();

        // Create skill with name "deploy"
        let skills_dir = dir.path().join("skills");
        std::fs::create_dir_all(&skills_dir).unwrap();
        std::fs::write(
            skills_dir.join("deploy.skill.md"),
            "---\nname: deploy\ndescription: Deploy (skill)\n---\nSkill content",
        )
        .unwrap();

        // Create command with same name "deploy"
        let commands_dir = dir.path().join("commands");
        std::fs::create_dir_all(&commands_dir).unwrap();
        std::fs::write(
            commands_dir.join("deploy.md"),
            "---\nname: deploy\ndescription: Deploy (command)\n---\nCommand content",
        )
        .unwrap();

        let descriptor = make_descriptor(dir.path().to_path_buf(), "my-plugin");
        let resources = PluginLoader::load(&descriptor).await.unwrap();

        // Only one skill should exist — skills/ takes precedence
        assert_eq!(resources.skills.len(), 1);
        assert_eq!(resources.skills[0].name, "my-plugin:deploy");
        assert_eq!(resources.skills[0].description, "Deploy (skill)");
    }

    #[test]
    fn test_resolve_plugin_root() {
        let root = std::path::Path::new("/plugins/my-plugin");
        assert_eq!(
            super::resolve_plugin_root("${CLAUDE_PLUGIN_ROOT}/scripts/check.sh", root),
            "/plugins/my-plugin/scripts/check.sh"
        );
        assert_eq!(super::resolve_plugin_root("echo hello", root), "echo hello");
        assert_eq!(
            super::resolve_plugin_root("${CLAUDE_PLUGIN_ROOT}/a ${CLAUDE_PLUGIN_ROOT}/b", root),
            "/plugins/my-plugin/a /plugins/my-plugin/b"
        );
    }

    #[tokio::test]
    async fn test_hooks_plugin_root_substitution() {
        let dir = tempdir().unwrap();
        let hooks_dir = dir.path().join("hooks");
        std::fs::create_dir_all(&hooks_dir).unwrap();
        std::fs::write(
            hooks_dir.join("hooks.json"),
            r#"{"PreToolUse": ["${CLAUDE_PLUGIN_ROOT}/scripts/check.sh"]}"#,
        )
        .unwrap();

        let descriptor = make_descriptor(dir.path().to_path_buf(), "my-plugin");
        let resources = PluginLoader::load(&descriptor).await.unwrap();

        assert_eq!(resources.hooks.len(), 1);
        let expected_cmd = format!("{}/scripts/check.sh", dir.path().display());
        match &resources.hooks[0].config {
            HookConfig::Command(cmd) => assert_eq!(cmd, &expected_cmd),
            _ => panic!("Expected Command config"),
        }
        assert_eq!(resources.hooks[0].plugin_root, dir.path());
    }

    #[tokio::test]
    async fn test_mcp_plugin_root_substitution() {
        let dir = tempdir().unwrap();
        std::fs::write(
            dir.path().join(".mcp.json"),
            r#"{"mcpServers":{"srv":{"type":"stdio","command":"${CLAUDE_PLUGIN_ROOT}/bin/server","args":["--config","${CLAUDE_PLUGIN_ROOT}/config.json"],"env":{"DB_PATH":"${CLAUDE_PLUGIN_ROOT}/data"}}}}"#,
        )
        .unwrap();

        let descriptor = make_descriptor(dir.path().to_path_buf(), "my-plugin");
        let resources = PluginLoader::load(&descriptor).await.unwrap();

        let config = resources.mcp_servers.get("my-plugin:srv").unwrap();
        match config {
            McpServerConfig::Stdio {
                command, args, env, ..
            } => {
                let root = dir.path().display().to_string();
                assert_eq!(command, &format!("{root}/bin/server"));
                assert_eq!(args[1], format!("{root}/config.json"));
                assert_eq!(env.get("DB_PATH").unwrap(), &format!("{root}/data"));
            }
            _ => panic!("Expected Stdio config"),
        }
    }

    #[tokio::test]
    async fn test_hooks_official_format_plugin_root_substitution() {
        let dir = tempdir().unwrap();
        let hooks_dir = dir.path().join("hooks");
        std::fs::create_dir_all(&hooks_dir).unwrap();
        std::fs::write(
            hooks_dir.join("hooks.json"),
            r#"{
                "hooks": {
                    "PostToolUse": [{
                        "matcher": "Write",
                        "hooks": [{"type": "command", "command": "${CLAUDE_PLUGIN_ROOT}/fmt.sh"}]
                    }]
                }
            }"#,
        )
        .unwrap();

        let descriptor = make_descriptor(dir.path().to_path_buf(), "my-plugin");
        let resources = PluginLoader::load(&descriptor).await.unwrap();

        assert_eq!(resources.hooks.len(), 1);
        match &resources.hooks[0].config {
            HookConfig::Full { command, .. } => {
                assert_eq!(command, &format!("{}/fmt.sh", dir.path().display()));
            }
            _ => panic!("Expected Full config"),
        }
    }
}