Skip to content

(context): listing header always says "Context found in cdk.json:" regardless of where the context is #1814

Description

@go-to-k

Describe the bug

Running cdk context with no options lists the merged context values, with the header:

Context found in cdk.json:

However, this header is printed even when cdk.json contains no context key at all and every listed value comes from cdk.context.json (and/or ~/.cdk.json). The listing merges the context from all of these files, but the header always names cdk.json.

Implementation: packages/aws-cdk/lib/commands/context.ts prints ioHelper.defaults.info('Context found in %s:', chalk.blue(PROJECT_CONFIG)), where PROJECT_CONFIG is the fixed string 'cdk.json'. There is no per-source information in the listing.

Display-only issue; no functional impact.

Regression Issue

  • Select this option if this issue appears to be a regression.

Last Known Working CDK Version

No response

Expected Behavior

The header should reflect where the listed context actually comes from, e.g.:

Context found in cdk.context.json:

or, when several files contribute:

Context found in cdk.json, cdk.context.json:

Current Behavior

The header always says Context found in cdk.json:, even when cdk.json has no context.

Reproduction Steps

  1. In a CDK project, make sure cdk.json has no context key.
  2. Create cdk.context.json with any value, e.g. { "foo": "bar" }.
  3. Run cdk context.

The listing shows foo under the header Context found in cdk.json:, although the value is in cdk.context.json.

Possible Solution

The CLI's Configuration already knows which files contributed context. Expose the list of context files that currently contain values, and have the context command render the header from that list (falling back to a generic header when no file source is known).

I will submit a PR for this.

Additional Information/Context

No response

CDK CLI Version

2.1135.0

Framework Version

2.261.0

Node.js Version

24.19.0

OS

macOS 15

Language

TypeScript

Language Version

No response

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions