Skip to content

fix: update the templates used by init to use correct claude code syntax and IO#238

Closed
jimweller wants to merge 2 commits intoruvnet:mainfrom
jimweller:fix/init-settings-syntax-for-hooks
Closed

fix: update the templates used by init to use correct claude code syntax and IO#238
jimweller wants to merge 2 commits intoruvnet:mainfrom
jimweller:fix/init-settings-syntax-for-hooks

Conversation

@jimweller
Copy link
Copy Markdown

@jimweller jimweller commented Jul 13, 2025

The claude code hook json format seems to have changed very recently. Hook commands get a json payload from stdin. In order to populate the npx claude-flow... commands we need to extract the fields that we need from the payload.

https://docs.anthropic.com/en/docs/claude-code/hooks

The old init command was generating syntax that claude code v1.0.51 did not accept and doctor said

└ hooks
├ postCommandHook: Expected array, but received object
├ postEditHook: Expected array, but received object
├ preCommandHook: Expected array, but received object
├ preEditHook: Expected array, but received object
└ sessionEndHook: Expected array, but received object

@jimweller jimweller marked this pull request as draft July 13, 2025 23:04
@ruvnet
Copy link
Copy Markdown
Owner

ruvnet commented Jul 13, 2025

I'll take a look later. Thanks for doing this. Feel free to join our WhatsApp group to discuss:

https://chat.whatsapp.com/H4ybOphfzMDLHXv6fXs1xd

@jimweller
Copy link
Copy Markdown
Author

Is seems like some mcp settings are mixed into the .claude/settings.json at the top level. I'm removing them. I'm not sure where they go yet.

  "features": {
    "autoTopologySelection": true,
    "parallelExecution": true,
    "neuralTraining": true,
    "bottleneckAnalysis": true,
    "smartAutoSpawning": true,
    "selfHealingWorkflows": true,
    "crossSessionMemory": true,
    "githubIntegration": true
  },
  "performance": {
    "maxAgents": 10,
    "defaultTopology": "hierarchical",
    "executionStrategy": "parallel",
    "tokenOptimization": true,
    "cacheEnabled": true,
    "telemetryLevel": "detailed"
  }

@jimweller
Copy link
Copy Markdown
Author

jimweller commented Jul 14, 2025

Similar issue in that mcpServers is not a directive for settings.json. It can get confusing fast because of the -s <SCOPE> switch. I think we want project where it creates a .mcp.json in the root of the folder.

Buuuut it seems like --dangerously-skip-permissions skips over .mcp.json file. If you run claude without that switch, it prompts to trust the file. After which it updates .claude/settings.local.json with

  "enabledMcpjsonServers": [
    "claude-flow"
  ],

So I think we need init to handle .mcp.json file and enabledMcpjsonServers in .claude/settings.local.json.

Hold my beer!

PS You can easily get conflicts where claude has stored an mcp server in your user+project settings in ~/.claude.json. So that should be cleaned before experimenting with this stuff.

@jimweller
Copy link
Copy Markdown
Author

ruv-swarm always fails. I can start it on the command line fine. Is it necessary for claude-flow?

…laude/settings.local.json such that the mcp servers are trusted even with --dangerously-skip-permissions
@jimweller jimweller changed the title fix: update the templates created by init to use correct claude code hooks syntax and IO fix: update the templates used by init to use correct claude code syntax and IO Jul 14, 2025
@jimweller
Copy link
Copy Markdown
Author

Hooks are working now at least. I see records in hive.db:memory_entries. Not sure if this is the PR to do it. I'll wait to talk to some people before taking it out of draft.

So we need to dial this stuff in:

  • .mcp.json - to include the claude-code (and maybe ruv-swarm?) mcp servers
  • .claude/settings.json - fix hooks, remove mcpServers, remove junk entries that are for something else
  • .claude/settings.local.json - use enabledMcpjsonServers to trust the mcp servers from .mcp.json
[start with a clean folder]
node ~/Projects/personal/claude-flow/src/cli/simple-cli.js init --force
node ~/Projects/personal/claude-flow/src/cli/simple-cli.js hive-mind init --force
[change settings.json file to @alpha version]
node ~/Projects/personal/claude-flow/src/cli/simple-cli.js hive-mind spawn "make a calculator webpage" --queenType strategic --workerTypes researcher,coder,analyst,tester --maxWorkers 5 --monitor --claude

@ryanleecode
Copy link
Copy Markdown

@jimweller does this fix all the agents just pemrnantly being idle?

@jimweller
Copy link
Copy Markdown
Author

jimweller commented Jul 14, 2025

I'm not 100% certain. You can check out the branch and try the sequence from my last comment with your use case.

As I spelunk the code, the flow is not super clear or consistent. It seems like "hive-mind wizard" is the happy path. And claude will try to achieve the goal even if claude-flow isn't working. So it can be really hard to tell.

But before this change "hive-mind spawn" didn't seem to do anything.

There's still other coherence problems like the hooks using "notification" vs "notify" or camel case vs kebab case cli switches.

I'm mostly here to follow along, learn, and help where I can.

Copy link
Copy Markdown
Owner

ruvnet commented Jul 14, 2025

Thank you for this PR! The hook format updates are definitely needed for Claude Code v1.0.51+ compatibility.

✅ What works well:

  • Correct array-based hook format matching the new Claude Code requirements
  • Proper JSON extraction using jq from stdin payloads
  • Good use of matcher patterns for different tool types
  • Covers all hook lifecycles (PreToolUse, PostToolUse, Stop)

⚠️ Concerns:

1. Missing MCP Server Configuration

The PR removes the entire mcpServers section, which would prevent Claude Flow from functioning as an MCP server:

"mcpServers": {
  "claude-flow": {
    "command": "npx",
    "args": ["claude-flow", "mcp", "start"],
    ...
  }
}

This configuration is essential for Claude Flow's core functionality.

2. Dependency on jq

The new commands require jq to be installed. Consider:

  • Adding fallback behavior if jq is not available
  • Documenting this requirement clearly
  • Or using shell built-ins for simple JSON parsing

3. Lost Configuration Sections

The features and performance sections contain important settings that shouldn't be removed.

🔧 Suggestions:

  1. Keep both old and new sections for backward compatibility, or add version detection
  2. Add error handling for JSON parsing failures:
    FILE_PATH=$(jq -r '.tool_input.file_path' 2>/dev/null || echo "")
  3. Restore the MCP server configuration - it's critical for Claude Flow
  4. Test with different Claude Code versions to ensure compatibility

Would you be willing to update the PR to preserve the MCP server configuration while keeping your excellent hook format updates?

@darman84
Copy link
Copy Markdown

I'm not 100% certain. You can check out the branch and try the sequence from my last comment with your use case.

As I spelunk the code, the flow is not super clear or consistent. It seems like "hive-mind wizard" is the happy path. And claude will try to achieve the goal even if claude-flow isn't working. So it can be really hard to tell.

But before this change "hive-mind spawn" didn't seem to do anything.

There's still other coherence problems like the hooks using "notification" vs "notify" or camel case vs kebab case cli switches.

I'm mostly here to follow along, learn, and help where I can.

For me it doesn't seem to work at all when i try to use the wizard for some reason, claude code just doesn't seem to be getting prompted correctly for me.
This works for me:
claude-flow hive-mind spawn "TEXT" --claude
The issue with this though is that typing out my entire prompt in the quotation block can be annoying, so I've resorted to using a text transformer tool like picotoolkit to compress my prompt to one line. But sometimes this doesn't work either if i paste an error with characters that it doesn't like.

@jimweller
Copy link
Copy Markdown
Author

jimweller commented Jul 14, 2025

Thank you for this PR! The hook format updates are definitely needed for Claude Code v1.0.51+ compatibility.

1. Missing MCP Server Configuration

2. Dependency on jq

3. Lost Configuration Sections

1 mcpServers don't go in settings.json anymore. It's not part of the schema. Claude code throws an error. It belongs in .mcp.json wth appropriate permissions in settings.local.json.

https://docs.anthropic.com/en/docs/claude-code/settings#available-settings

❯ claude mcp add -s project echoMcp -- echo "Hi there"
Added stdio MCP server echoMcp with command: echo Hi there to project config
❯ cat .mcp.json
{
  "mcpServers": {
    "echoMcp": {
      "type": "stdio",
      "command": "echo",
      "args": [
        "Hi there"
      ],
      "env": {}
    }
  }
}

2 I would handle that with documentation since I would expect any developer using this tool to have jq installed.

3 I'm not sure exactly where those settings go. I think they are subordinate to claude-flow. They are definitely no claude-code top level configurations that would belong on the settings.json file.

I'll keep working on it as time permits and look forward to chatting about it in whatsapp.

Copy link
Copy Markdown
Owner

ruvnet commented Jul 14, 2025

Hi @jimweller! 👋

Thank you so much for this PR! You identified the exact same hooks format issue we were working on - great minds think alike!

I really appreciate you digging into the Claude Code documentation and figuring out the JSON stdin approach with jq. Your implementation is actually more aligned with how Claude Code officially documents the hooks should work.

Good news and timing

We just merged a similar fix a few minutes ago (commit 9f2d77f) that addresses the same compatibility issues. Our approach uses template variables instead of JSON parsing, which avoids the jq dependency, and we also included a migration script to help existing users update their settings.

What I love about your PR

The enabledMcpjsonServers addition to settings.local.json is brilliant! This ensures MCP servers are trusted even with --dangerously-skip-permissions. We'll definitely incorporate this in a follow-up commit - thank you for catching that!

Coming soon

We're working on several related improvements:

  • Better MCP server trust configuration (inspired by your PR!)
  • Enhanced hooks documentation
  • Optional stdin JSON parsing support for users who prefer that approach
  • Improved version detection to handle future Claude Code updates gracefully

Next steps

Since we've already merged the core fix, I'll close this PR, but please know that your contribution helped validate our approach and provided valuable insights. The MCP trust configuration you added will definitely make it into the next release!

Feel free to test out the latest alpha version with the migration script:

npm install -g claude-flow@alpha
npx claude-flow@alpha migrate-hooks

Thanks again for your contribution and for helping make Claude Flow better! 🚀

@ruvnet
Copy link
Copy Markdown
Owner

ruvnet commented Jul 14, 2025

closing. thanks for your help on this..
ruv.

not a bot.

@ruvnet ruvnet closed this Jul 14, 2025
@jimweller
Copy link
Copy Markdown
Author

jimweller commented Jul 14, 2025

There's one more fix in this PR you should explore. Everything after this line does not belong in settings.json.

https://github.com/ruvnet/claude-flow/blob/e3cdf15780c207e5b43aa28e1b0b69609c294707/src/cli/simple-commands/init/templates/settings.json#L68

You also need to check the createEnhancedSettingsJsonFallback in.
https://github.com/ruvnet/claude-flow/blob/e3cdf15780c207e5b43aa28e1b0b69609c294707/src/cli/simple-commands/init/templates/enhanced-templates.js#L1226

Cheers

@pksorensen
Copy link
Copy Markdown

ruv-swarm always fails. I can start it on the command line fine. Is it necessary for claude-flow?

i see the same thing for my setups.

One thing thats also interesting to understand better (might be my own understanding) is that its unclear if mcp servers are installed to the claude home settings and not project settings and if this might be earlier version of claude flow that has installed the mcp servers globally.

Note that i am running in devdontainers but i use a shared claude home directory across those.

@jimweller
Copy link
Copy Markdown
Author

ruv-swarm always fails. I can start it on the command line fine. Is it necessary for claude-flow?

i see the same thing for my setups.

One thing thats also interesting to understand better (might be my own understanding) is that its unclear if mcp servers are installed to the claude home settings and not project settings and if this might be earlier version of claude flow that has installed the mcp servers globally.

Note that i am running in devdontainers but i use a shared claude home directory across those.

I'm running in devcontainers too. And I'm cognizant of keeping ~/.claude.json and ~/.claude SUPER clean. I'm trying to keep all the claude-code and claude-flow tools isolated to the project folder I'm working in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants