Use Context Engine with Claude Code

Use Context Engine with Claude Code to bring context distilled from your organization's data into coding sessions. By retrieving relevant Knowledge Indicators (KIs) from an AI index instead of repeatedly discovering and interpreting source data, Claude Code can complete tasks faster and use fewer model tokens.

The Context Engine skill teaches Claude Code when and how to retrieve context. Claude Code runs the locally installed Elastic CLI, which calls the Context Engine APIs. This integration does not require an MCP server.

For guidance that applies to every agent integration, refer to Configure agents to use an AI index. For the list, describe, and query flow, refer to Retrieve context from an AI index.

You need:

  • An Elastic Stack 9.6 deployment with an Enterprise license, or an Elastic Cloud Serverless project.
  • Claude Code installed.
  • Node.js 22.12.0 or later to install the Elastic CLI.
  • The contextEngine:enabled advanced setting turned on in the Kibana space you want to query.
  • An AI index that contains at least one Knowledge Indicator (KI).
  • The Context Engine Read privilege in that space.
  • The Elasticsearch read and view_index_metadata privileges for the AI index's backing indices.
  • Permission to create an API key with those Kibana and Elasticsearch privileges.

Install Elastic CLI 0.7.0 or later globally so Claude Code can run it from its shell environment:

npm install -g @elastic/cli@latest
elastic --version
		

The Elastic CLI is in technical preview. The Context Engine command group is available in version 0.7.0 and later.

Run the following command in the same environment as Claude Code:

elastic kb context-engine --help
		

The command output should include operations for listing, describing, and querying AI indices. If the command group is unavailable, update the Elastic CLI before continuing.

Create the API key that the Elastic CLI will use:

Create an API key with the required privileges:

  1. In Kibana, open Stack Management → API Keys, then select Create API key.

  2. Leave Control security privileges off and define a role with the following privileges:

    • Index privileges: read and view_index_metadata on ai-index-*.
    • Kibana privileges: Context Engine at Read in the space you want to query.
  3. Create the API key and copy its encoded value.

Add a named context with the Kibana URL and API key for the deployment:

elastic config context add context-engine \
  --kb-url https://my-deployment.kb.us-east-1.aws.elastic.cloud \
  --kb-api-key <api-key>
		

The Elastic CLI stores the API key in the operating system's credential store when one is available. Set the new context as the default, then verify that the CLI can connect:

elastic config current-context set context-engine
elastic status
		

To target a non-default Kibana space, include /s/<space-id> in the Kibana URL.

The kibana-context-engine skill supplies the retrieval procedure and the Elastic CLI commands that Claude Code needs. The skill is included in the elastic-kibana plugin in the Elastic agent skills repository.

Add the repository as a Claude Code marketplace, then install the elastic-kibana plugin. For more information about marketplaces and plugins, refer to Install and manage plugins in the Claude Code documentation.

claude plugin marketplace add https://github.com/elastic/agent-skills
claude plugin install elastic-kibana@elastic-agent-skills
		

If the plugin is already installed, update it to the latest version:

claude plugin update elastic-kibana
		

After installing or updating the plugin, start a new Claude Code session. Run /skills and confirm that kibana-context-engine is available.

Ask a question covered by one of your AI indices. Tell Claude Code to use Context Engine if you want to exercise the integration explicitly. For example:

Use Context Engine to explain <subject covered by your AI index>. Tell me which AI index and Knowledge Indicators you used.
		

Claude Code should load the skill and run these operations in order:

  1. List the available AI indices and select one whose description matches the question.
  2. Describe that AI index to obtain its ES|QL target, fields, KI types, tags, and example queries.
  3. Query the AI index for relevant KIs and use the results to answer the question.

For the underlying retrieval sequence, refer to Retrieve context from an AI index.

Review the commands Claude Code ran and confirm that it:

  • Used elastic kb context-engine commands rather than querying the backing index directly.
  • Listed the available AI indices before selecting one, unless the prompt already identified the AI index.
  • Described the selected AI index before constructing the ES|QL query.
  • Queried the target and fields returned by the describe operation.
  • Used KIs from the expected AI index to answer the question.

The commands should correspond to the following operations:

Operation Elastic CLI command
List AI indices elastic kb context-engine get-context-engine-ai-index
Describe an AI index elastic kb context-engine get-context-engine-ai-index-aiindexid-describe --ai-index-id '<id>'
Query AI indices elastic kb context-engine post-context-engine-ai-index-query --query '<esql>'

Use the following table to resolve common setup and retrieval problems:

Symptom Resolution
Claude Code does not load kibana-context-engine. Confirm that the elastic-kibana plugin is installed and up to date, then start a new session and run /skills.
elastic is not found. Install the CLI globally and confirm that its executable is on the PATH available to Claude Code.
elastic kb context-engine is not a recognized command. Update the Elastic CLI to version 0.7.0 or later.

For additional API-level failures, refer to Troubleshoot retrieval.

  • The Elastic plugin for Claude installs public Elastic agent skills and connects Claude to the Elastic Docs MCP server. It does not connect Claude to your deployment data.
  • The Elastic Cloud Serverless connector for Claude connects Claude on the web or desktop to the Elastic Agent Builder MCP server for a Elastic Cloud Serverless project. This is a separate access path from the local skill and Elastic CLI described on this page.